Example #1
0
        void CreateWarranty()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                var cus = (from c in ctx.KhachHangs where c.SoDienThoai == txtWaPhoneNum.Text select c).FirstOrDefault();
                cus.TenKH    = txtWaCustomer.Text;
                cus.GioiTinh = radWaMale.Checked ? "Nam" : "Nữ";
                cus.NgaySinh = datWaBirth.Value;
                cus.Email    = txtWaEmail.Text;
                cus.DiaChi   = txtWaAdress.Text;

                var lastWaID = (from wa in ctx.SuaChuas orderby wa.MaSC descending select wa.MaSC).FirstOrDefault();

                try
                {
                    if (billID != 0)
                    {
                        ctx.pro_CreateWarrantys(lastWaID + 1, txtWaPhoneName.Text, datWaReceive.Value, Int32.Parse(txtWaCharge.Text),
                                                cbbWaPayMethod.SelectedItem.ToString(), txtWaNotices.Text, cusID, Int32.Parse(txtWaEmpID.Text), billID);
                    }
                    else
                    {
                        ctx.pro_CreateWarrantys(lastWaID + 1, txtWaPhoneName.Text, datWaReceive.Value, Int32.Parse(txtWaCharge.Text),
                                                cbbWaPayMethod.SelectedItem.ToString(), txtWaNotices.Text, cusID, Int32.Parse(txtWaEmpID.Text), null);
                    }

                    MessageBox.Show("Thêm thành công!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Thêm không thành công\n Hãy kiểm tra lại các trường thông tin!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                ctx.SaveChanges();
            }
        }