-1-
-2-
====================
قائمة الملفات
===================
كورس Windows Desktop Applications in c sharp مهندس بديع موسى راجى
https://www.youtube.com/playlist?list=PLMmy9Ec9B98yVy2t1hE3t4t1zKAxAvpkW
==========
قائمة الملفات
===================
تعلم لغة c sharp من البداية الى الاحتراف مهندس بديع موسى راجى
https://www.youtube.com/playlist?list=PLMmy9Ec9B98xzr_x2vafMGx9_gCIkZhM6
======================
قائمة الملفات
===============
كورس Object-oriented programming C Sharp مهندس بديع موسى راجى
https://www.youtube.com/playlist?list=PLMmy9Ec9B98yRqBvoBB2Wi3mNro5DDdOL
=======================
قائمة الملفات
===============
Database Analysis and design Full course - ERD schema مهندس بديع موسى راجى
https://www.youtube.com/playlist?list=PLMmy9Ec9B98zl-h_NvnQAs8BW8QRMIw-P
======================
قائمة الملفات
===============
تعلم باحتراف MS SQL server 2019 مهندس بديع موسى راجى
https://www.youtube.com/playlist?list=PLMmy9Ec9B98zuTzQXSZYomkE-RLntASLB
=================
الموقع
https://course-7.blogspot.com/
====================
الكود
==============
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace wfa0009
{
public partial class Form1 : Form
{
OpenFileDialog opic = new OpenFileDialog();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "" || textBox4.Text.Trim() == "")
{
MessageBox.Show("try input data again");
return;
}
//======== check id
StreamReader sridtest = new StreamReader("mydata2.txt");
string stch = sridtest.ReadToEnd();
sridtest.Close();
if (stch.Contains(textBox1.Text + ";"))
{
MessageBox.Show("this id is taken try another");
textBox1.Focus();
textBox1.SelectAll();
}
else
{
//=== write to file
StreamWriter sw2 = new StreamWriter("mydata2.txt", true, Encoding.Unicode); //==append
string ifstr = textBox1.Text + ";"
+ textBox2.Text + ";"
+ textBox3.Text + ";"
+ textBox4.Text;
sw2.WriteLine(ifstr);
sw2.Close();
//== chech directory
if (!Directory.Exists("img"))
Directory.CreateDirectory("img");
//=== save pic to folder img with name id of person
if(File.Exists(opic.FileName))
pictureBox1.Image.Save("img/" + textBox1.Text + ".jpg");
MessageBox.Show("Person is added");
// to empty form
cleartextbox();
}
}
private void Form1_Load(object sender, EventArgs e)
{
// this.Icon = Icon.ExtractAssociatedIcon("wfa0009.exe"); //not dynamic
this.Icon = Icon.ExtractAssociatedIcon(AppDomain.CurrentDomain.FriendlyName); // dynamic
}
void cleartextbox()
{
pictureBox1.Image = new PictureBox().Image; //clear pic
foreach (Control cont in this.Controls)
{
if (cont is TextBox)
{
cont.Text = "";
}
}
textBox1.Focus();
}
private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
Form FR = new Form(); //create
FR.StartPosition = FormStartPosition.CenterParent;
FR.Font = this.Font;
FR.Icon = this.Icon;
FR.Size = this.Size;
FR.Text = "all records";
TextBox tb = new TextBox();
tb.Multiline = true;
tb.ScrollBars = ScrollBars.Both;
tb.Dock = DockStyle.Fill; // full screen
FR.Controls.Add(tb);
try
{
StreamReader sr = new StreamReader("mydata2.txt");
string rAlllines = sr.ReadToEnd();
sr.Close();
tb.Text = rAlllines;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
FR.ShowDialog();
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() != "")
{
StreamReader sr = new StreamReader("mydata2.txt");
string line = "";
bool found = false;
do
{
line = sr.ReadLine();
if (line != null)
{
string[] lwords = line.Split(';');
if (lwords[0] == textBox1.Text.Trim())
{
textBox2.Text = lwords[1];
textBox3.Text = lwords[2];
textBox4.Text = lwords[3];
string picpath = "img/" + lwords[0] + ".jpg";
if (File.Exists(picpath))
{
pictureBox1.Image = Image.FromFile(picpath);
}
if (File.Exists(picpath))
{
MessageBox.Show("found data and pic");
}
else
{
pictureBox1.Image = new PictureBox().Image; //clear pic
MessageBox.Show("found data only without pic");
}
found = true;
break;
}
}
} while (line != null);
sr.Close();
if (!found)
{
MessageBox.Show("not found");
}
}
else
{
MessageBox.Show("plz enter Id");
textBox1.Focus();
}
}
private void button5_Click(object sender, EventArgs e)
{
// to empty form
cleartextbox();
}
private void button6_Click(object sender, EventArgs e)
{
//OpenFileDialog opic = new OpenFileDialog();
opic.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
opic.Filter = "Images|*.jpg;*.png;*.gif;*.bmp";
if (opic.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(opic.FileName);
}
}
private void button7_Click(object sender, EventArgs e)
{
Form FR = new Form(); //create
FR.StartPosition = FormStartPosition.CenterParent;
FR.Font = this.Font;
FR.Icon = this.Icon;
FR.Size = this.Size;
FR.Text = "all records with photos";
FR.AutoScroll = true;
int mytop = 40;
try
{
StreamReader sr = new StreamReader("mydata2.txt");
string rline;
do
{
rline = sr.ReadLine();
if (rline != null)
{
TextBox txt = new TextBox();
PictureBox pic = new PictureBox();
txt.Width = 500;
txt.Top = mytop;
pic.Top = mytop;
pic.Left = 605;
pic.Size = new Size(125, 125);
pic.SizeMode = PictureBoxSizeMode.StretchImage;
mytop += 155;
txt.Text = rline;
string pathpic = "img/" + rline.Split(';')[0] + ".jpg";
pic.BorderStyle = BorderStyle.FixedSingle; // if pic not found
if (File.Exists(pathpic))
pic.Image = Image.FromFile(pathpic);
// add control to form
FR.Controls.Add(txt);
FR.Controls.Add(pic);
}
} while (rline != null) ;
sr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
FR.ShowDialog();
}
}
}
-3-
-4-