Exemple #1
0
 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 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();
                }
            }
        }