private void ModifyInfor()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                var maNV  = Int32.Parse(txtID.Text);
                var query = (from q in ctx.NhanViens where q.MaNV == maNV select q).FirstOrDefault();
                var acc   = (from a in ctx.Accounts where a.Username == username select a).FirstOrDefault();

                query.SoDienThoai = txtPhone.Text;
                query.DiaChi      = txtAdress.Text;
                if (txtPass.Text == acc.Password)
                {
                    if (pnlChangePass.Visible)
                    {
                        if (txtNewPass.Text.Length > 5)
                        {
                            if (txtNewPass.Text == txtReNewPass.Text)
                            {
                                acc.Password = txtNewPass.Text;

                                ctx.SaveChanges();
                                txtPass.Text          = "";
                                btnSave.Enabled       = false;
                                pnlChangePass.Visible = false;
                                MessageBox.Show("Thay đổi thông tin thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show("Mật khẩu không khớp!\nVui lòng kiểm tra lại", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Mật khẩu phải có ít nhất 6 kí tự\nVui lòng kiểm tra lại", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        ctx.SaveChanges();
                        txtPass.Text          = "";
                        btnSave.Enabled       = false;
                        pnlChangePass.Visible = false;
                        MessageBox.Show("Thay đổi thông tin thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Mật khẩu không đúng\nVui lòng kiểm tra lại!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Example #2
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();
            }
        }
Example #3
0
        private void CreateBills()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                var cus = (from c in ctx.KhachHangs where c.SoDienThoai == txtSearchCus.Text select c).FirstOrDefault();
                cus.TenKH    = txtCustomer.Text;
                cus.GioiTinh = radMale.Checked ? "Nam" : "Nữ";
                cus.NgaySinh = datBirth.Value;
                cus.Email    = txtEmail.Text;
                cus.DiaChi   = txtAdress.Text;

                var lastBillID = (from bill in ctx.HoaDons orderby bill.MaHD descending select bill.MaHD).FirstOrDefault();
                var newbill    = new HoaDon
                {
                    MaHD        = lastBillID + 1,
                    MaKH        = cus.MaKH,
                    MaNV        = Int32.Parse(txtEmployeeID.Text),
                    NgayMua     = datBuy.Value,
                    HanBH       = datWarranty.Value,
                    PTMuaHang   = cbbBuyMethod.SelectedItem.ToString(),
                    PTThanhToan = cbbPayMethod.SelectedItem.ToString(),
                    Tongtien    = 0
                };
                ctx.HoaDons.Add(newbill);
                ctx.SaveChanges();

                billID = lastBillID + 1;
            }
        }
Example #4
0
        private void Delete()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                DialogResult answer = MessageBox.Show("Bạn chắc chắn muốn xóa khách hàng chứ?", "Cảnh báo!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (answer == DialogResult.Yes)
                {
                    try
                    {
                        var cusID = Convert.ToInt32(txtID.Text);

                        var bill = (from b in ctx.HoaDons where b.MaKH == cusID select b).FirstOrDefault();
                        var warr = (from w in ctx.SuaChuas where w.MaNV == cusID select w).FirstOrDefault();
                        if (bill == null && warr == null)
                        {
                            var cus = (from c in ctx.KhachHangs where c.MaKH == cusID select c).FirstOrDefault();
                            ctx.KhachHangs.Remove(cus);
                            ctx.SaveChanges();

                            MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Không thể xóa khách hàng tồn tại trong hóa đơn", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Bạn chưa chọn khách hàng, hãy chọn khách hàng cần xóa trước khi thực hiện thao tác!", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        private void DeleteWaratary()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                try
                {
                    var          wabillID = Convert.ToInt32(txtWaWaBillID.Text);
                    DialogResult answer   = MessageBox.Show("Bạn chắc chắn muốn xóa hóa đơn chứ?", "Question?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (answer == DialogResult.Yes)
                    {
                        if (wabillID != 0)
                        {
                            var wabill = (from wb in ctx.SuaChuas where wb.MaSC == wabillID select wb).FirstOrDefault();
                            ctx.SuaChuas.Remove(wabill);
                            ctx.SaveChanges();

                            MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Bạn chưa chọn điện thoại, hãy chọn điện thoại cần xóa trước khi thực hiện thao tác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #6
0
        void ChoosePhones()
        {
            var cRow    = dgvPhones.CurrentCell.RowIndex;
            var PhoneID = Int32.Parse(dgvPhones.Rows[cRow].Cells[0].FormattedValue.ToString());

            using (var ctx = new PhoneStoreManageEntities())
            {
                var lastDBillID = (from db in ctx.ChiTietHoadons orderby db.MaCTHD descending select db.MaCTHD).FirstOrDefault();
                var newDeBill   = new ChiTietHoadon
                {
                    MaCTHD = lastDBillID + 1,
                    MaHD   = billID,
                    MaDT   = PhoneID
                };
                ctx.ChiTietHoadons.Add(newDeBill);
                ctx.SaveChanges();

                //var countPhone = (from db in ctx.ChiTietHoadons where db.MaHD == billID && db.MaDT == PhoneID select db).Count();

                var detailBill = (from db in ctx.ChiTietHoadons
                                  where db.MaHD == billID
                                  select new
                {
                    db.DienThoai.MaDT,
                    //db.MaHD,
                    db.DienThoai.MauDienThoai.TenDT,
                    db.DienThoai.Mau,
                    db.DienThoai.Gia
                });                  //.Distinct();
                dgvDetailBillPhones.DataSource         = detailBill.ToList();
                dgvDetailBillPhones.Columns[0].Visible = false;
                dgvDetailBillPhones.Refresh();
                LoadPhones();
            }
        }
Example #7
0
        private void Modify()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                if (addFlag)
                {
                    try
                    {
                        var lastCusID = (from c in ctx.KhachHangs orderby c.MaKH descending select c.MaKH).FirstOrDefault();

                        var newCus = new KhachHang
                        {
                            MaKH        = lastCusID + 1,
                            TenKH       = txtName.Text,
                            NgaySinh    = datBirth.Value,
                            GioiTinh    = radMale.Checked ? "Nam" : "Nữ",
                            SoDienThoai = txtPhone.Text,
                            Email       = txtEmail.Text,
                            DiaChi      = txtAdress.Text
                        };
                        ctx.KhachHangs.Add(newCus);
                        MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("Thông tin nhập chưa đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    try
                    {
                        var cusID = Convert.ToInt32(txtID.Text);
                        var cus   = (from c in ctx.KhachHangs where c.MaKH == cusID select c).FirstOrDefault();

                        cus.TenKH       = txtName.Text;
                        cus.NgaySinh    = datBirth.Value;
                        cus.GioiTinh    = radMale.Checked ? "Nam" : "Nữ";
                        cus.SoDienThoai = txtPhone.Text;
                        cus.Email       = txtEmail.Text;
                        cus.DiaChi      = txtAdress.Text;
                        MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("Bạn chưa chọn khách hàng, hãy chọn khách hàng cần sửa trước khi thực hiện thao tác!", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                ctx.SaveChanges();
            }
        }
Example #8
0
 private void DeleteBill()
 {
     using (var ctx = new PhoneStoreManageEntities())
     {
         DeleteDetailBill();
         var bill = (from b in ctx.HoaDons where b.MaHD == billID select b).FirstOrDefault();
         if (bill != null)
         {
             ctx.HoaDons.Remove(bill);
             ctx.SaveChanges();
             MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
        private void Delete()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                DialogResult answer = MessageBox.Show("Nhân viên, hợp đồng\nBạn chắc chắn chứ?", "Cảnh báo!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (answer == DialogResult.Yes)
                {
                    try
                    {
                        if (username != "Admin")
                        {
                            var empID = Convert.ToInt32(txtID.Text);
                            var bill  = (from b in ctx.HoaDons where b.MaNV == empID select b).FirstOrDefault();
                            var warr  = (from w in ctx.SuaChuas where w.MaNV == empID select w).FirstOrDefault();
                            if (bill == null && warr == null)
                            {
                                var acc = (from ac in ctx.Accounts where ac.MaNV == empID select ac).FirstOrDefault();
                                var emp = (from cu in ctx.NhanViens where cu.MaNV == empID select cu).FirstOrDefault();
                                var con = (from co in ctx.HopDongs where co.MaHopDong == emp.MaHopDong select co).FirstOrDefault();

                                if (acc != null)
                                {
                                    ctx.Accounts.Remove(acc);
                                }
                                ctx.HopDongs.Remove(con);
                                ctx.NhanViens.Remove(emp);
                                ctx.SaveChanges();

                                MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show("Không thể xóa nhân viên tồn tại trong hóa đơn", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Không thể xóa nhân viên quản trị!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Bạn chưa chọn nhân viên, hãy chọn nhân viên cần xóa trước khi thực hiện thao tác!", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #10
0
        private void LoadCustomers()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                var customer = from c in ctx.KhachHangs where c.SoDienThoai == txtSearchCus.Text select c;
                try
                {
                    txtCustomer.Text = (from c in customer select c.TenKH).FirstOrDefault().ToString();
                    datBirth.Value   = (from c in customer select c.NgaySinh).FirstOrDefault().Value;
                    txtEmail.Text    = (from c in customer select c.Email).FirstOrDefault().ToString();
                    txtAdress.Text   = (from c in customer select c.DiaChi).FirstOrDefault().ToString();

                    if ((from c in customer select c.GioiTinh).FirstOrDefault().ToString() == "Nam")
                    {
                        radMale.Checked = true;
                    }
                    else
                    {
                        radFemale.Checked = true;
                    }
                    btnSelect.Enabled = true;
                }
                catch
                {
                    ClearControls();

                    DialogResult answer = MessageBox.Show("Không tìn thấy khách hàng. Bạn có muốn tạo mới không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (answer == DialogResult.Yes)
                    {
                        var lastCusID = (from cus in ctx.KhachHangs orderby cus.MaKH descending select cus.MaKH).FirstOrDefault();
                        var newCus    = new KhachHang {
                            MaKH = lastCusID + 1, SoDienThoai = txtSearchCus.Text
                        };
                        ctx.KhachHangs.Add(newCus);
                        ctx.SaveChanges();
                        btnSelect.Enabled = true;
                    }
                    else
                    {
                        btnSelect.Enabled = false;
                    }
                }
            }
        }
Example #11
0
        void LoadCustomers()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                var customer = from c in ctx.KhachHangs where c.SoDienThoai == txtPhoneNum.Text select c;
                try
                {
                    txtCustomer.Text = (from c in customer select c.TenKH).FirstOrDefault().ToString();
                    datBirth.Value   = (from c in customer select c.NgaySinh).FirstOrDefault().Value;
                    txtEmail.Text    = (from c in customer select c.Email).FirstOrDefault().ToString();
                    txtAdress.Text   = (from c in customer select c.DiaChi).FirstOrDefault().ToString();

                    if ((from c in customer select c.GioiTinh).FirstOrDefault().ToString() == "Nam")
                    {
                        radMale.Checked = true;
                    }
                    else
                    {
                        radFemale.Checked = true;
                    }
                }
                catch
                {
                    txtCustomer.Text  = "";
                    datBirth.Value    = new DateTime(2000, 1, 1);
                    txtEmail.Text     = "";
                    txtAdress.Text    = "";
                    radMale.Checked   = false;
                    radFemale.Checked = false;

                    DialogResult answer = MessageBox.Show("Không tìn thấy khách hàng. Bạn có muốn tạo mới không?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (answer == DialogResult.Yes)
                    {
                        var lastCusID = (from cus in ctx.KhachHangs orderby cus.MaKH descending select cus.MaKH).FirstOrDefault();
                        //var lastID = (from hd in ctx.HoaDons orderby hd.MaHD descending select hd.MaHD).FirstOrDefault();
                        var newCus = new KhachHang {
                            MaKH = lastCusID + 1, SoDienThoai = txtPhoneNum.Text
                        };
                        ctx.KhachHangs.Add(newCus);
                        ctx.SaveChanges();
                    }
                }
            }
        }
Example #12
0
        private void DeleteDetailBill()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                var dbill = from db in ctx.ChiTietHoadons where db.MaHD == billID select db;
                var bill  = (from b in ctx.HoaDons where b.MaHD == billID select b).FirstOrDefault();
                if (bill != null)
                {
                    foreach (var db in dbill)
                    {
                        var phone = (from p in ctx.DienThoais
                                     where p.MaDT == db.MaDT
                                     select p).FirstOrDefault();
                        phone.SoLuong += 1;
                    }
                    ctx.ChiTietHoadons.RemoveRange(dbill);
                    ctx.SaveChanges();

                    dgvDetailBillPhones.DataSource = null;
                    dgvDetailBillPhones.Refresh();
                }
            }
        }
        private void DeleteBill()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                try
                {
                    var          billID = Convert.ToInt32(txtBillID.Text);
                    DialogResult answer = MessageBox.Show("Bạn chắc chắn muốn xóa hóa đơn chứ?", "Question?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (answer == DialogResult.Yes)
                    {
                        var waran = (from wa in ctx.SuaChuas where wa.MaHD == billID select wa).FirstOrDefault();
                        if (waran == null)
                        {
                            var bill   = (from b in ctx.HoaDons where b.MaHD == billID select b).FirstOrDefault();
                            var debill = from db in ctx.ChiTietHoadons where db.MaHD == billID select db;
                            if (debill != null)
                            {
                                ctx.ChiTietHoadons.RemoveRange(debill.ToArray());
                            }
                            ctx.HoaDons.Remove(bill);
                            ctx.SaveChanges();

                            MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Không thể xóa đơn tồn tại trong hóa đơn sửa chữa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Bạn chưa chọn hóa đơn, hãy chọn hóa đơn cần xóa trước khi thực hiện thao tác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #14
0
        private void Modify()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                if (addFlag)                  //add
                {
                    if (radBrandMode.Checked) //brand
                    {
                        try
                        {
                            var lastbrandID = (from b in ctx.HangDienThoais orderby b.MaHDT descending select b.MaHDT).FirstOrDefault();
                            var brand       = new HangDienThoai
                            {
                                MaHDT  = lastbrandID + 1,
                                TenHDT = cbbEditBrand.Text
                            };
                            ctx.HangDienThoais.Add(brand);

                            MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("Thông tin nhập chưa đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else if (radPhoneSampleMode.Checked) //sample phone
                    {
                        try
                        {
                            var brand     = (from b in ctx.HangDienThoais where b.TenHDT == cbbEditBrand.SelectedItem.ToString() select b).FirstOrDefault();
                            var lastID    = (from sp in ctx.MauDienThoais orderby sp.MaMDT descending select sp.MaMDT).FirstOrDefault();
                            var newsPhone = new MauDienThoai
                            {
                                MaMDT = lastID + 1,
                                TenDT = txtPhoneSample.Text,
                                NamSX = datManufacturing.Value,
                                KM    = txtPromotion.Text,
                                MoTa  = txtDescription.Text,
                                MaHDT = brand.MaHDT
                            };
                            ctx.MauDienThoais.Add(newsPhone);

                            MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("Thông tin nhập chưa đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else //phone
                    {
                        try
                        {
                            var lastID   = (from p in ctx.DienThoais orderby p.MaDT descending select p.MaDT).FirstOrDefault();
                            var newPhone = new DienThoai
                            {
                                MaDT    = lastID + 1,
                                MaMDT   = Convert.ToInt32(txtPhoneSampleID.Text),
                                Mau     = cbbColor.Text,
                                GiaNhap = Convert.ToInt32(txtEntryPrice.Text),
                                GiaBan  = Convert.ToInt32(txtSalePrice.Text),
                                SoLuong = Convert.ToInt32(txtNumber.Text)
                            };
                            ctx.DienThoais.Add(newPhone);

                            MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("Thông tin nhập chưa đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else //edit
                {
                    if (radBrandMode.Checked) //brand
                    {
                        try
                        {
                            var brand = (from b in ctx.HangDienThoais where b.TenHDT == nameBrand select b).FirstOrDefault();
                            brand.TenHDT = cbbEditBrand.Text;

                            MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("Bạn chưa chọn hãng, hãy chọn hãng cần sửa trước khi thực hiện thao tác!", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else if (radPhoneSampleMode.Checked) //sample phone
                    {
                        try
                        {
                            var phoneID = Int32.Parse(txtPhoneSampleID.Text);
                            var phone   = (from p in ctx.MauDienThoais where p.MaMDT == phoneID select p).FirstOrDefault();

                            phone.TenDT = txtPhoneSample.Text;
                            phone.NamSX = datManufacturing.Value;
                            phone.KM    = txtPromotion.Text;
                            phone.MoTa  = txtDescription.Text;

                            MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("Bạn chưa chọn mẫu điện thoại, hãy chọn mẫu điện thoại cần sửa trước khi thực hiện thao tác!", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else //phone
                    {
                        try
                        {
                            var phone = (from p in ctx.DienThoais where p.MaMDT == phoneSampleID && p.Mau == cbbColor.SelectedItem.ToString() select p).FirstOrDefault();
                            phone.Mau     = cbbColor.Text;
                            phone.SoLuong = Convert.ToInt32(txtNumber.Text);
                            phone.GiaNhap = Convert.ToInt32(txtEntryPrice.Text);
                            phone.GiaBan  = Convert.ToInt32(txtSalePrice.Text);

                            MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("Bạn chưa chọn điện thoại, hãy chọn điện thoại cần sửa trước khi thực hiện thao tác!", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                ctx.SaveChanges();
            }
        }
Example #15
0
        private void ChoosePhones()
        {
            var cRow    = dgvPhones.CurrentCell.RowIndex;
            var PhoneID = Int32.Parse(dgvPhones.Rows[cRow].Cells[0].FormattedValue.ToString());

            using (var ctx = new PhoneStoreManageEntities())
            {
                var check = (from p in ctx.DienThoais where p.MaDT == PhoneID select p.SoLuong).FirstOrDefault();
                if (check > 0)
                {
                    var lastDBillID = (from db in ctx.ChiTietHoadons orderby db.MaCTHD descending select db.MaCTHD).FirstOrDefault();
                    var newDeBill   = new ChiTietHoadon
                    {
                        MaCTHD = lastDBillID + 1,
                        MaHD   = billID,
                        MaDT   = PhoneID
                    };
                    ctx.ChiTietHoadons.Add(newDeBill);
                    ctx.SaveChanges();

                    LoadPhones();
                    dgvPhones.CurrentCell         = dgvPhones[1, cRow];
                    dgvPhones.Rows[cRow].Selected = true;

                    var detailBill = (from b in ctx.ChiTietHoadons
                                      select new
                    {
                        b.MaHD,
                        b.MaDT,
                        b.DienThoai.MauDienThoai.TenDT,
                        b.DienThoai.Mau,
                        b.DienThoai.GiaBan
                    }).Distinct();

                    var countList = from db in ctx.ChiTietHoadons
                                    join p in ctx.DienThoais on db.MaDT equals p.MaDT
                                    join b in ctx.HoaDons on db.MaHD equals b.MaHD
                                    group db by new { db.MaHD, db.MaDT, db.DienThoai.GiaBan } into dbs
                    orderby dbs.Key.MaHD
                        select new
                    {
                        dbs.Key,
                        Count = dbs.Count(),
                        Total = dbs.Count() * dbs.Key.GiaBan
                    };

                    var query = from bill in detailBill
                                join list in countList on
                                new { bill.MaHD, bill.MaDT } equals
                    new { list.Key.MaHD, list.Key.MaDT }
                    into result
                    from r in result.DefaultIfEmpty()
                    where bill.MaHD == billID
                        select new
                    {
                        bill.TenDT,
                        bill.Mau,
                        bill.GiaBan,
                        r.Count,
                        r.Total
                    };

                    dgvDetailBillPhones.DataSource            = query.ToList();
                    dgvDetailBillPhones.Columns[0].HeaderText = "Điện thoại";
                    dgvDetailBillPhones.Columns[1].HeaderText = "Màu";
                    dgvDetailBillPhones.Columns[2].HeaderText = "Giá";
                    dgvDetailBillPhones.Columns[3].HeaderText = "Số lượng";
                    dgvDetailBillPhones.Columns[4].HeaderText = "Thành tiền";
                    dgvDetailBillPhones.Refresh();

                    lblTotalMoney.Text = (from q in ctx.HoaDons where q.MaHD == billID select q.Tongtien).FirstOrDefault().ToString();
                }
            }
        }
Example #16
0
        private void Delete()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                if (radBrandMode.Checked)
                {
                    DialogResult answer = MessageBox.Show("Tất cả mẫu điện thoại cũng sẽ bị xóa\nBạn muốn xóa hãng điện thoại thật không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (answer == DialogResult.Yes)
                    {
                        if (nameBrand != null)
                        {
                            var dBill = (from db in ctx.ChiTietHoadons where db.DienThoai.MauDienThoai.HangDienThoai.TenHDT == nameBrand select db).FirstOrDefault();
                            if (dBill == null)
                            {
                                var phone = (from p in ctx.DienThoais where p.MauDienThoai.HangDienThoai.TenHDT == nameBrand select p).FirstOrDefault();
                                if (phone == null)
                                {
                                    var brand   = (from b in ctx.HangDienThoais where b.TenHDT == nameBrand select b).FirstOrDefault();
                                    var sphones = (from p in ctx.MauDienThoais where p.MaHDT == brand.MaHDT select p).ToList();

                                    ctx.MauDienThoais.RemoveRange(sphones);
                                    ctx.HangDienThoais.Remove(brand);
                                    ctx.SaveChanges();

                                    cbbEditBrand.Text = "";

                                    MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    MessageBox.Show("Không thể xóa hãng do điện thoại của hãng còn trong hệ thống", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Không thể xóa hãng do điện thoại tồn tại trong hóa đơn", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Bạn chưa chọn hãng, hãy chọn hãng cần xóa trước khi thực hiện thao tác!", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else if (radPhoneSampleMode.Checked)
                {
                    DialogResult answer = MessageBox.Show("Bạn muốn xóa mẫu điện thoại thật không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (answer == DialogResult.Yes)
                    {
                        try
                        {
                            var examphoneID = Convert.ToInt32(txtPhoneSampleID.Text);
                            var dBill       = (from db in ctx.ChiTietHoadons where db.DienThoai.MauDienThoai.MaMDT == examphoneID select db).FirstOrDefault();
                            if (dBill == null)
                            {
                                var phone = (from p in ctx.DienThoais where p.MauDienThoai.MaMDT == examphoneID select p).FirstOrDefault();
                                if (phone == null)
                                {
                                    var examPhone = (from xp in ctx.MauDienThoais where xp.MaMDT == examphoneID select xp).FirstOrDefault();

                                    ctx.MauDienThoais.Remove(examPhone);
                                    ctx.SaveChanges();

                                    MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    MessageBox.Show("Không thể xóa mẫu điện thoại do điện thoại của mẫu còn trong hệ thống", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Không thể xóa mẫu điện thoại do điện thoại của mẫu tồn tại trong hóa đơn", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Bạn chưa chọn mẫu điện thoại, hãy chọn mẫu điện thoại cần xóa trước khi thực hiện thao tác!", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    DialogResult answer = MessageBox.Show("Tất cả mẫu điện thoại cũng sẽ bị xóa\nBạn muốn xóa điện thoại thật không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (answer == DialogResult.Yes)
                    {
                        try
                        {
                            var examphoneID = Convert.ToInt32(txtPhoneSampleID.Text);
                            var color       = cbbColor.SelectedItem.ToString();
                            var dBill       = (from db in ctx.ChiTietHoadons where db.DienThoai.MauDienThoai.MaMDT == examphoneID && db.DienThoai.Mau == color select db).FirstOrDefault();
                            if (dBill == null)
                            {
                                var phones = (from p in ctx.DienThoais where p.MauDienThoai.MaMDT == examphoneID && p.Mau == color select p).FirstOrDefault();
                                if (phones != null)
                                {
                                    ctx.DienThoais.Remove(phones);
                                    ctx.SaveChanges();

                                    LoadcbbColor();

                                    MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Không thể xóa mẫu điện thoại do điện thoại của mẫu tồn tại trong hóa đơn", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Bạn chưa chọn điện thoại, hãy chọn điện thoại cần xóa trước khi thực hiện thao tác!", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }
Example #17
0
        void LoadCustomers()
        {
            dgvWaBills.DataSource     = null;
            dgvWaPhoneBill.DataSource = null;

            using (var ctx = new PhoneStoreManageEntities())
            {
                var customer = from c in ctx.KhachHangs where c.SoDienThoai == txtWaPhoneNum.Text select c;
                try
                {
                    txtWaCustomer.Text = (from c in customer select c.TenKH).FirstOrDefault().ToString();
                    datWaBirth.Value   = (from c in customer select c.NgaySinh).FirstOrDefault().Value;
                    txtWaEmail.Text    = (from c in customer select c.Email).FirstOrDefault().ToString();
                    txtWaAdress.Text   = (from c in customer select c.DiaChi).FirstOrDefault().ToString();

                    if ((from c in customer select c.GioiTinh).FirstOrDefault().ToString() == "Nam")
                    {
                        radWaMale.Checked = true;
                    }
                    else
                    {
                        radWaFemale.Checked = true;
                    }


                    cusID = (from c in customer select c.MaKH).FirstOrDefault();
                    var bill = from b in ctx.HoaDons
                               where b.MaKH == cusID
                               select new
                    {
                        b.MaHD,
                        b.MaKH,
                        b.NhanVien.TenNV,
                        b.NgayMua,
                        b.HanBH,
                        b.Tongtien
                    };
                    dgvWaBills.DataSource            = bill.ToList();
                    dgvWaBills.Columns[0].HeaderText = "Mã HD";
                    dgvWaBills.Columns[1].HeaderText = "Mã KH";
                    dgvWaBills.Columns[2].HeaderText = "Nhân viên";
                    dgvWaBills.Columns[3].HeaderText = "Ngày mua";
                    dgvWaBills.Columns[4].HeaderText = "Hạn bảo hành";
                    dgvWaBills.Columns[5].HeaderText = "Tổng tiền";
                    dgvWaBills.Refresh();
                }
                catch
                {
                    txtWaCustomer.Text  = "";
                    datWaBirth.Value    = new DateTime(2000, 1, 1);
                    txtWaEmail.Text     = "";
                    txtWaAdress.Text    = "";
                    radWaMale.Checked   = false;
                    radWaFemale.Checked = false;

                    DialogResult answer = MessageBox.Show("Không tìn thấy khách hàng. Bạn có muốn tạo mới không?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (answer == DialogResult.Yes)
                    {
                        var lastCusID = (from cus in ctx.KhachHangs orderby cus.MaKH descending select cus.MaKH).FirstOrDefault();
                        var newCus    = new KhachHang {
                            MaKH = lastCusID + 1, SoDienThoai = txtWaPhoneNum.Text
                        };
                        cusID = lastCusID + 1;
                        ctx.KhachHangs.Add(newCus);
                        ctx.SaveChanges();
                    }
                }
            }
        }
        private void Modify()
        {
            using (var ctx = new PhoneStoreManageEntities())
            {
                if (addFlag)
                {
                    try
                    {
                        var lastConID = (from co in ctx.HopDongs orderby co.MaHopDong descending select co.MaHopDong).FirstOrDefault();
                        var lastEmpID = (from cu in ctx.NhanViens orderby cu.MaNV descending select cu.MaNV).FirstOrDefault();

                        var newCon = new HopDong
                        {
                            MaHopDong      = lastConID + 1,
                            TenLoaiHopDong = cbbContract.SelectedItem.ToString(),
                            Ngaybatdau     = datStart.Value,
                            Ngayketthuc    = datEnd.Value
                        };

                        var newEmp = new NhanVien
                        {
                            MaNV        = lastEmpID + 1,
                            TenNV       = txtName.Text,
                            GioiTinh    = radMale.Checked ? "Nam" : "Nữ",
                            NgaySinh    = datBirth.Value,
                            SoDienThoai = txtPhone.Text,
                            Luong       = Convert.ToInt32(txtSalary.Text),
                            Email       = txtEmail.Text,
                            DiaChi      = txtAdress.Text,
                            MaCV        = cbbPosition.SelectedIndex + 1,
                            MaHopDong   = lastConID + 1
                        };

                        var newAcc = new Account
                        {
                            Username = txtUsername.Text,
                            Password = txtPassword.Text,
                            MaNV     = lastEmpID + 1
                        };

                        ctx.HopDongs.Add(newCon);
                        ctx.NhanViens.Add(newEmp);
                        ctx.Accounts.Add(newAcc);
                        MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("Thông tin nhập chưa đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    try
                    {
                        var empID = Convert.ToInt32(txtID.Text);
                        var emp   = (from cu in ctx.NhanViens where cu.MaNV == empID select cu).FirstOrDefault();
                        var con   = (from co in ctx.HopDongs where co.MaHopDong == emp.MaHopDong select co).FirstOrDefault();
                        var acc   = (from ac in ctx.Accounts where ac.MaNV == empID select ac).FirstOrDefault();

                        con.TenLoaiHopDong = cbbContract.SelectedItem.ToString();
                        con.Ngaybatdau     = datStart.Value;
                        con.Ngayketthuc    = datEnd.Value;

                        emp.TenNV       = txtName.Text;
                        emp.GioiTinh    = radMale.Checked ? "Nam" : "Nữ";
                        emp.NgaySinh    = datBirth.Value;
                        emp.SoDienThoai = txtPhone.Text;
                        emp.Luong       = Convert.ToInt32(txtSalary.Text);
                        emp.Email       = txtEmail.Text;
                        emp.DiaChi      = txtAdress.Text;
                        emp.MaCV        = cbbPosition.SelectedIndex + 1;

                        if (acc != null)
                        {
                            acc.Username = txtUsername.Text;
                            acc.Password = txtPassword.Text;
                        }
                        else
                        {
                            var acccheck = (from ac in ctx.Accounts where ac.Username == txtUsername.Text select ac).FirstOrDefault();
                            if (acccheck == null)
                            {
                                var newacc = new Account
                                {
                                    Username = txtUsername.Text,
                                    Password = txtPassword.Text,
                                    MaNV     = empID
                                };
                                ctx.Accounts.Add(newacc);
                            }
                            else
                            {
                                MessageBox.Show("Thao tác không thành công, username bị trùng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }

                        MessageBox.Show("Thao tác thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("Bạn chưa chọn nhân viên, hãy chọn nhân viên cần sửa trước khi thực hiện thao tác!", "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                ctx.SaveChanges();
            }
        }