using POSDemo.DB;
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 POSDemo.Screens.customers
{
public partial class fcustomers : Form
{
POSTutEntities db = new POSTutEntities();
string imagePath = "";
int i;
Customer cust;
public fcustomers()
{
InitializeComponent();
dataGridView1.DataSource =
db.Customers.ToList();
}
void Clear()
{
txtName.Text =
txtAddress.Text
= txtNotes.Text
= txtPhone.Text
= txtCompany.Text
= txtEmail.Text = "";
isActive.Checked = false;
pictureBox1.ImageLocation = "";
}
private void fcustomers_Load(object sender, EventArgs e)
{
}
====================== save==============================
private void button1_Click(object sender, EventArgs e)
{
Customer c = new Customer();
c.Name = txtName.Text;
c.Address = txtAddress.Text;
c.Notes = txtNotes.Text;
c.Phone = txtPhone.Text;
c.Company = txtCompany.Text;
c.Email = txtEmail.Text;
c.IsActive = isActive.Checked;
db.Customers.Add(c);
db.SaveChanges();
if (imagePath != "")
{
// string destPath =
Environment.CurrentDirectory + "\\images\\products\\" + p.Id +
".jpg";
string destPath = "images\\Customers\\" + c.id + ".jpg";
File.Copy(imagePath, destPath, true);
c.Image = destPath;
db.SaveChanges();
}
dataGridView1.DataSource =
db.Customers.ToList();
MessageBox.Show("Submitted Successfully");
Clear();
}
====================== pictureBox1 ==============================
private void pictureBox1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
imagePath = dialog.FileName;
pictureBox1.ImageLocation =
dialog.FileName;
}
}
================================= Search
========================
private void button5_Click(object sender, EventArgs e)
{
if (textName.Text == "")
dataGridView1.DataSource =
db.Customers.Where(x => x.Phone == textPhone.Text).ToList();
else
dataGridView1.DataSource =
db.Customers.Where(x => x.Phone == textPhone.Text || x.Name.Contains(textName.Text)).ToList();
}
================================= Refresh
========================
private void button6_Click(object sender, EventArgs e)
{
dataGridView1.DataSource =
db.Customers.ToList();
}
========================= dataGridView1=========================================
private void
dataGridView1_SelectionChanged(object sender, EventArgs e)
{
try
{
i = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
cust =
db.Customers.SingleOrDefault(x => x.id == i);
txtName.Text=cust.Name;
txtAddress.Text=cust.Address;
txtNotes.Text=cust.Notes;
txtPhone.Text=cust.Phone;
txtCompany.Text=cust.Company;
txtEmail.Text=cust.Email;
isActive.Checked=(bool)cust.IsActive;
pictureBox1.ImageLocation =
cust.Image;
}
catch
{
}
}
========================================
============================ Update=============================
private void button2_Click(object sender, EventArgs e)
{
cust.Name = txtName.Text;
cust.Address = txtAddress.Text;
cust.Notes = txtNotes.Text;
cust.Phone = txtPhone.Text;
cust.Company = txtCompany.Text;
cust.Email = txtEmail.Text;
cust.IsActive = isActive.Checked;
// cust.Image= pictureBox1.ImageLocation ;
if (imagePath != "")
{
// string destPath =
Environment.CurrentDirectory + "\\images\\products\\" + p.Id +
".jpg";
string destPath = "images\\Customers\\" + i + ".jpg";
File.Copy(imagePath, destPath, true);
cust.Image = destPath;
}
db.SaveChanges();
dataGridView1.DataSource =
db.Customers.ToList();
MessageBox.Show("Submitted Successfully");
}
=========================================
clear
private void button4_Click(object sender, EventArgs e)
{
Clear();
}
=================================== delete
private void button3_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are You Sure to Delete this
Record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
//Product x = db.Customers.Find(i);
//db.Products.Remove(x);
// db.Products.Attach(cust);
//======= Or
db.Customers.Remove(cust);
db.SaveChanges();
dataGridView1.DataSource =
db.Customers.ToList();
Clear();
MessageBox.Show("Deleted
Successfully");
}
}
==================================================== close
private void button7_Click(object sender, EventArgs e)
{
Close();
}
private void label12_Click(object sender, EventArgs e)
{
Close();
}
}
}
مسلسل | اسم الملف | لينك |
---|---|---|
1 | تعلم لغة c sharp من البداية الى الاحتراف مهندس بديع موسى راجى | https://www.youtube.com/playlist?list=PLMmy9Ec9B98xzr_x2vafMGx9_gCIkZhM6 |
2 | كورس Object-oriented programming C Sharp مهندس بديع موسى راجى | https://www.youtube.com/playlist?list=PLMmy9Ec9B98yRqBvoBB2Wi3mNro5DDdOL |
3 | Database Analysis and design Full course - ERD schema مهندس بديع موسى راجى | https://www.youtube.com/playlist?list=PLMmy9Ec9B98zl-h_NvnQAs8BW8QRMIw-P |
4 | تعلم باحتراف MS SQL server 2019 مهندس بديع موسى راجى | https://www.youtube.com/playlist?list=PLMmy9Ec9B98zuTzQXSZYomkE-RLntASLB |
5 | كورس Windows Desktop Applications in c sharp مهندس بديع موسى راجى | https://www.youtube.com/playlist?list=PLMmy9Ec9B98yVy2t1hE3t4t1zKAxAvpkW |
6 | مهنس بديع موسى راجى dbase in c sharp سى شارب و قواعد البيانات ِADO.NET مهندس بديع موسى راجى | https://www.youtube.com/playlist?list=PLMmy9Ec9B98y_tlKzFvxJXLY_2VHlzdz6 |
7 | مهنس بديع موسى راجى dbase in c sharp سى شارب و قواعد البيانات ِ LINQ.NET مهندس بديع موسى راجى | https://www.youtube.com/playlist?list=PLMmy9Ec9B98yLGrgsN5WdmMQGzzyU4E_Y |
8 | Entity Framework and C Sharp كورس مهندس بديع موسى راجى | https://www.youtube.com/playlist?list=PLMmy9Ec9B98wyhsQuDejKvsfdVtVf_Uef |
451 | 0451 Entity Framework مقدمة | https://youtu.be/BsgTy4Wiypk |
452 | 0452 Entity Framework CRUD Operations part1 واجهة البرنامج | https://youtu.be/aO2dC-cdXFA |
453 | 0453 Entity Framework CRUD Operations part 2 تكوين المودل | https://youtu.be/DLRKSAOT0q8 |
454 | 0454 Entity Framework CRUD Operations Model browser part 3 | https://youtu.be/MTvwgVLUh_k |
455 | 0455 Entity Framework CRUD Operations part 4 | https://youtu.be/b5c0wAjs3gk |
456 | 0456 Entity Framework CRUD Operations part 5 | https://youtu.be/Ss5SpsxNP8I |
500 | مشروع المبيعات سوبر ماركت وصيدليات سى شارب و Entity Framework | https://youtu.be/yJhA4BxLzIw |
501 | 001 Login form design مشروع المبيعات سوبر ماركت وصيدليات سى شارب | https://youtu.be/s1bCZBkhwIk |
502 | 002 Save user form and dbase model مشروع المبيعات سوبر ماركت وصيدليات سى شارب | https://youtu.be/rbbmmBnzWY0 |
503 | 003 Save user form save image in dbase مشروع المبيعات سوبر ماركت وصيدليات سى شارب | https://youtu.be/5e75lEG4Pu8 |
504 | 004 مشروع المبيعات سوبر ماركت وصيدليات سى شارب entity framework | https://youtu.be/iNk1OgWKwe4 |
505 | 005 مشروع المبيعات سوبر ماركت وصيدليات سى شارب entity framework DBase Model | https://youtu.be/39Y7KBWgsMU |
506 | 006 customer crud operations مشروع المبيعات سوبر ماركت وصيدليات سى شارب Entity Framework | https://youtu.be/cjEx0ZV_GHk |
21 | 21 |