private void txtFilter_TextChanged(object sender, EventArgs e) { using (Business.Customers customers = new Business.Customers()) { dgvcustomers.DataSource = customers.Get(w => w.FullName.Contains(txtFilter.Text.Trim()) || w.Address.Contains(txtFilter.Text.Trim()) || w.Email.Contains(txtFilter.Text.Trim())); } }
private void DataBinding() { using (Business.Customers customers = new Business.Customers()) { dgvcustomers.DataSource = customers.Get();// customers.Get(); } }
private void btnDeleteCustomer_Click(object sender, EventArgs e) { if (dgvcustomers.CurrentRow != null) { using (Business.Customers customers = new Business.Customers()) { int customerid = int.Parse(dgvcustomers.CurrentRow.Cells[0].Value.ToString()); customers.DeleteByID(customerid); customers.Save(); } } else { MessageBox.Show("یک خط انتخاب کنید"); } }
private void frm_AddCustomer_Load(object sender, EventArgs e) { if (this.CustomerID != 0) { this.Text = "ویرایش"; btninsertdata.Text = "ویرایش"; using (Business.Customers UOW = new Business.Customers()) { var sel = UOW.Get(w => w.ID == CustomerID).FirstOrDefault(); txtAddress.Text = sel.Address; txtEmail.Text = sel.Email; txtMobile.Text = sel.Mobile; txtName.Text = sel.FullName; pc.ImageLocation = Application.StartupPath + "/Image/" + sel.Image; } } }
private void btninsertdata_Click(object sender, EventArgs e) { if (BaseValidator.IsFormValid(this.components)) { string locationName = string.Empty; if (pc.Image != null) { locationName = Guid.NewGuid().ToString() + Path.GetExtension(pc.ImageLocation); if (!Directory.Exists(Application.StartupPath + "/Images/")) { Directory.CreateDirectory(Application.StartupPath + "/Images/"); } pc.Image.Save(Application.StartupPath + "/Images/" + locationName); } using (Business.Customers UOW = new Business.Customers()) { DataLayer.Customers customer = new DataLayer.Customers() { Address = txtAddress.Text.Trim(), Email = txtEmail.Text.Trim(), FullName = txtName.Text.Trim(), Mobile = txtMobile.Text.Trim(), Image = locationName }; if (CustomerID != 0) { customer.ID = CustomerID; UOW.Update(customer); } else { UOW.Insert(customer); } UOW.Save(); } } }