private Boolean CheckConfickTraLaiNhaCungCap(Entities.TraLaiNCC gitri, Entities.TraLaiNCC sosanh)
 {
     Boolean kiemtra = false;
     try
     {
         Common.Utilities ck = new Common.Utilities();
         int count = 0;
         if (gitri.MaHDTraLaiNCC != sosanh.MaHDTraLaiNCC)
         { kiemtra = false; txtSodonhang.Text = sosanh.MaHDTraLaiNCC; }
         else { kiemtra = true; count = count + 1; }
         if (ck.SoSanhNgay('/', "!=", gitri.Ngaytra.ToString(), sosanh.Ngaytra.ToString()) == true)
         {
             kiemtra = false;
             makNgaydonhang.Text = sosanh.Ngaytra.ToString("dd/MM/yyyy");
             //string ngay = ck.KiemTraDinhDangNgayThangNam("NgayThangNam", sosanh.Ngaytra.ToString(), '/');
             //makNgaydonhang.Text = new Common.Utilities().XuLy(2, ngay);
         }
         else { kiemtra = true; count = count + 1; }
         if (gitri.MaNCC != sosanh.MaNCC)
         { kiemtra = false; txtMakhachhang.Text = sosanh.MaNCC; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.NoHienThoi != sosanh.NoHienThoi)
         { kiemtra = false; txtNohienthoi.Text = sosanh.NoHienThoi.ToString(); }
         else { kiemtra = true; count = count + 1; }
         if (gitri.NguoiNhanHang != sosanh.NguoiNhanHang)
         { kiemtra = false; txtNguoitra.Text = sosanh.NguoiNhanHang; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.HinhThucThanhToan != sosanh.HinhThucThanhToan)
         { kiemtra = false; cbxHinhthucthanhtoan.SelectedItem = sosanh.HinhThucThanhToan; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.MaHoaDonNhap != sosanh.MaHoaDonNhap)
         { kiemtra = false; txtChungtugoc.Text = sosanh.MaHoaDonNhap; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.MaKho != sosanh.MaKho)
         { kiemtra = false; cbxKhoHang.SelectedValue = sosanh.MaKho; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.MaTienTe != sosanh.MaTienTe)
         { kiemtra = false; cbxTiente_Tygia.SelectedValue = sosanh.MaTienTe; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.TienBoiThuong != sosanh.TienBoiThuong)
         { kiemtra = false; txtTongtienthanhtoan.Text = sosanh.TienBoiThuong; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.ThanhToanNgay != sosanh.ThanhToanNgay)
         { kiemtra = false; txtThanhtoanngay.Text = sosanh.ThanhToanNgay; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.ThueGTGT != sosanh.ThueGTGT)
         { kiemtra = false; txtGiatrigiatang.Text = sosanh.ThueGTGT; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.GhiChu != sosanh.GhiChu)
         { kiemtra = false; txtDiengiai.Text = sosanh.GhiChu; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.Deleted != sosanh.Deleted)
         { kiemtra = false; MessageBox.Show("Đơn hàng đã xóa"); }
         else { kiemtra = true; count = count + 1; }
         if (count < 14)
         { kiemtra = false; }
         else
         { kiemtra = true; }
     }
     catch (Exception ex)
     {
         string s = ex.Message.ToString();
         kiemtra = false;
     }
     return kiemtra;
 }
        /// <summary>
        /// xu ly don dat hang
        /// </summary>
        /// <param name="hanhdong"></param>
        private void XuLy_DonDatHang(string hanhdong)
        {
            try
            {
                Entities.DonDatHang don = new Entities.DonDatHang();
                Common.Utilities ck = new Common.Utilities();
                string thoigian_1 = makNgaydonhang.Text;
                string thoigian_2 = makNgaynhapdukien.Text;
                string thoigian_sosanh = DateServer.Date().ToString("dd/MM/yyyy");
                if (ck.SoSanhNgay('/', ">=", thoigian_1, thoigian_sosanh) == true && thoigian_1 != null && thoigian_2 != null && ck.SoSanhNgay('/', ">=", thoigian_2, thoigian_sosanh) == true)
                {
                    kiemtrama(check_loaidathang, txtManhacungcap.Text, txtManhacungcap.Text);
                    bool temp = false;
                    don.NgayDonHang = Utils.StringToDateTime(thoigian_1, out temp);
                    //don.NgayDonHang = DateTime.Parse(new Common.Utilities().KiemTraDinhDangNgayThangNam("ThangNgayNam", thoigian_1, '/'));
                    don.NgayNhapDuKien = Utils.StringToDateTime(thoigian_2, out temp);
                    //don.NgayNhapDuKien = DateTime.Parse(new Common.Utilities().KiemTraDinhDangNgayThangNam("ThangNgayNam", thoigian_2, '/'));
                    don.Hanhdong = hanhdong;
                    don.DonDatHangID = ID;
                    don.MaDonDatHang = "" + txtSodonhang.Text.ToUpper();
                    don.LoaiDonDatHang = check_loaidathang.Checked;
                    if (check_loaidathang.Checked == true)
                    { manhacungcap = txtManhacungcap.Text; }
                    if (check_loaidathang.Checked == false)
                    { manhacungcap = ""; }
                    don.MaNhaCungCap = manhacungcap;
                    don.NoHienThoi = txtNohienthoi.Text;
                    don.TrangThaiDonDatHang = txtTrangthaidonhang.Text.ToString();
                    don.HinhThucThanhToan = cbxHinhthucthanhtoan.SelectedItem.ToString();
                    don.MaKho = cbxMaKho.SelectedValue.ToString().ToUpper();
                    don.MaNhanVien = cbxNhanvien.SelectedValue.ToString().ToUpper();
                    don.MaTienTe = cbxTiente_Tygia.SelectedValue.ToString().ToUpper();
                    don.ThueGTGT = txtGiatrigiatang.Text;
                    don.Phivanchuyen = Double.Parse(0 + txtPhivanchuyen.Text).ToString();
                    don.PhiKhac = Double.Parse(0 + txtPhikhac.Text).ToString();
                    don.GhiChu = "" + txtDiengiai.Text.ToString();
                    don.Deleted = false;

                    don.Manhanvien = Common.Utilities.User.NhanVienID;
                    don.Tendangnhap = Common.Utilities.User.TenDangNhap;

                    if (check_loaidathang.Checked == false)
                    { makhachhang = txtManhacungcap.Text; }
                    if (check_loaidathang.Checked == true)
                    { makhachhang = ""; }
                    don.Makhachhang = makhachhang;
                    if (dgvInsertOrder.RowCount > 0)
                    {
                        if (CheckData(don) == true)
                        {
                            cl = new Server_Client.Client();
                            this.client = cl.Connect(Luu.IP, Luu.Ports);
                            clientstrem = cl.SerializeObj(this.client, "DonDatHang", don);
                            Entities.DonDatHang[] tralai = new Entities.DonDatHang[1];
                            int trave = Convert.ToInt32(cl.DeserializeHepper(clientstrem, tralai));
                            if (trave == 1)
                            {
                                LuuChiTietDonHang();
                            }
                            else
                            {
                                MessageBox.Show("Thất bại");
                            }
                        }
                        else
                        { }
                    }
                    else
                    { MessageBox.Show("Không có hàng hóa trong đơn đặt hàng"); }
                }
                else
                { MessageBox.Show("Kiểm tra ngày"); }
            }
            catch (Exception ex)
            {
                string s = ex.Message.ToString();
                MessageBox.Show("Hãy kiểm tra lại thông tin nhập");
            }
        }
 /// <summary>
 /// kiem tra khi update
 /// </summary>
 /// <param name="gitri"></param>
 /// <param name="sosanh"></param>
 /// <returns></returns>
 private Boolean CheckConfick(Entities.DonDatHang gitri, Entities.DonDatHang sosanh)
 {
     Boolean kiemtra = false;
     try
     {
         Common.Utilities ck = new Common.Utilities();
         int count = 0;
         if (gitri.MaDonDatHang != sosanh.MaDonDatHang)
         { kiemtra = false; txtSodonhang.Text = sosanh.MaDonDatHang; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.LoaiDonDatHang != sosanh.LoaiDonDatHang)
         { kiemtra = false; check_loaidathang.Checked = sosanh.LoaiDonDatHang; }
         else { kiemtra = true; count = count + 1; }
         if (ck.SoSanhNgay('/', "!=", gitri.NgayDonHang.ToString(), sosanh.NgayDonHang.ToString()) == true)
         {
             kiemtra = false;
             makNgaydonhang.Text = sosanh.NgayDonHang.ToString("dd/MM/yyyy");
             //string ngay = ck.KiemTraDinhDangNgayThangNam("NgayThangNam", sosanh.NgayDonHang.ToString(), '/');
             //makNgaydonhang.Text = new Common.Utilities().XuLy(2, ngay);
         }
         else { kiemtra = true; count = count + 1; }
         if (gitri.MaNhaCungCap != sosanh.MaNhaCungCap)
         { kiemtra = false; txtManhacungcap.Text = sosanh.MaNhaCungCap; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.NoHienThoi != sosanh.NoHienThoi)
         { kiemtra = false; txtNohienthoi.Text = sosanh.NoHienThoi.ToString(); }
         else { kiemtra = true; count = count + 1; }
         if (gitri.TrangThaiDonDatHang != sosanh.TrangThaiDonDatHang)
         { kiemtra = false; txtTrangthaidonhang.Text = sosanh.TrangThaiDonDatHang; }
         else { kiemtra = true; count = count + 1; }
         if (ck.SoSanhNgay('/', "!=", gitri.NgayNhapDuKien.ToString(), sosanh.NgayNhapDuKien.ToString()) == true)
         {
             kiemtra = false;
             makNgaynhapdukien.Text = sosanh.NgayNhapDuKien.ToString("dd/MM/yyyy");
             //string ngay = ck.KiemTraDinhDangNgayThangNam("NgayThangNam", sosanh.NgayNhapDuKien.ToString(), '/');
             //makNgaynhapdukien.Text = new Common.Utilities().XuLy(2, ngay);
         }
         else { kiemtra = true; count = count + 1; }
         if (gitri.HinhThucThanhToan != sosanh.HinhThucThanhToan)
         { kiemtra = false; cbxHinhthucthanhtoan.SelectedItem = sosanh.HinhThucThanhToan; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.MaKho != sosanh.MaKho)
         { kiemtra = false; cbxMaKho.SelectedValue = sosanh.MaKho; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.MaNhanVien != sosanh.MaNhanVien)
         { kiemtra = false; cbxNhanvien.SelectedValue = sosanh.MaNhanVien; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.MaTienTe != sosanh.MaTienTe)
         { kiemtra = false; cbxTiente_Tygia.SelectedValue = sosanh.MaTienTe; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.ThueGTGT != sosanh.ThueGTGT)
         { kiemtra = false; txtGiatrigiatang.Text = sosanh.ThueGTGT; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.PhiKhac != sosanh.PhiKhac)
         { kiemtra = false; txtPhikhac.Text = sosanh.PhiKhac; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.Phivanchuyen != sosanh.Phivanchuyen)
         { kiemtra = false; txtPhivanchuyen.Text = sosanh.Phivanchuyen; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.GhiChu != sosanh.GhiChu)
         { kiemtra = false; txtDiengiai.Text = sosanh.GhiChu; }
         else { kiemtra = true; count = count + 1; }
         if (gitri.Deleted != sosanh.Deleted)
         { kiemtra = false; MessageBox.Show("Đơn hàng đã xóa"); }
         else { kiemtra = true; count = count + 1; }
         if (gitri.Makhachhang != sosanh.Makhachhang)
         { kiemtra = false; txtManhacungcap.Text = sosanh.Makhachhang; }
         else { kiemtra = true; count = count + 1; }
         if (count < 17)
         { kiemtra = false; }
         else
         { kiemtra = true; }
     }
     catch (Exception ex)
     {
         string s = ex.Message.ToString();
         kiemtra = false;
     }
     return kiemtra;
 }
        private void XuLy_HoaDonNhap(string hanhdong)
        {
            try
            {
                if (!KiemTraNgayHetHan()) return;

                thanhtoan = new Entities.HoaDonNhap[1];
                Entities.HoaDonNhap don = new Entities.HoaDonNhap();
                Common.Utilities ck = new Common.Utilities();
                string thoigian_1 = makNgaydonhang.Text;
                string thoigian_2 = makHanthanhtoan.Text;
                string thoigian_sosanh = Date.ToString("dd/MM/yyyy");
                if (string.IsNullOrEmpty(thoigian_1) || string.IsNullOrEmpty(thoigian_2))
                {
                    MessageBox.Show("Kiểm tra ngày"); return;
                }
                if (!(ck.SoSanhNgay('/', ">=", thoigian_1, thoigian_sosanh) && ck.SoSanhNgay('/', ">=", thoigian_2, thoigian_sosanh)))
                {
                    MessageBox.Show("Kiểm tra ngày"); return;
                }
                else
                {
                    bool _kq0 = true; bool _kq1 = true;
                    don.NgayNhap = Utils.StringToDateTime(thoigian_1, out _kq0);
                    don.HanThanhToan = Utils.StringToDateTime(thoigian_2, out _kq1);
                    //don.NgayNhap = DateTime.Parse(new Common.Utilities().KiemTraDinhDangNgayThangNam("ThangNgayNam", thoigian_1, '/'));
                    //don.HanThanhToan = DateTime.Parse(new Common.Utilities().KiemTraDinhDangNgayThangNam("ThangNgayNam", thoigian_2, '/'));
                    don.Hanhdong = hanhdong;
                    don.HoaDonNhapID = ID;
                    don.MaHoaDonNhap = txtSodonhang.Text;
                    don.MaNhaCungCap = txtManhacungcap.Text;
                    don.NoHienThoi = txtNohienthoi.Text;
                    don.NguoiGiaoHang = "" + txtnguoigiaohang.Text;
                    don.HinhThucThanhToan = cbxHinhthucthanhtoan.SelectedItem.ToString();
                    string kh = "";
                    try { kh = cbxKhoHang.SelectedValue.ToString(); }
                    catch (Exception ex) { MessageBox.Show("Kiểm tra mã kho"); kh = ""; return; }
                    don.MaKho = kh;
                    string MaDonDatHang = txtMadondathang.Text;
                    if (MaDonDatHang == "<F4 - Tra cứu>" || MaDonDatHang.Length <= 0)
                    {
                        MaDonDatHang = "NULL";
                    }
                    don.MaDonDatHang = MaDonDatHang;
                    string tt = "";
                    try { tt = cbxTienTe_TyGia.SelectedValue.ToString(); }
                    catch (Exception ex) { MessageBox.Show("Kiểm tra mã tiền tệ"); tt = ""; return; }
                    don.MaTienTe = tt;
                    don.ChietKhau = Double.Parse(0 + txtTienCKTM0.Text).ToString();
                    don.ThanhToanNgay = Double.Parse(0 + txtThanhtoanngay.Text.Replace(",", "")).ToString();
                    don.ThueGTGT = Double.Parse(0 + txtGiatrigiatang.Text).ToString();
                    don.TongTien = Double.Parse(0 + txtTongThanhToan.Text).ToString();
                    don.GhiChu = "" + txtDiengiai.Text;
                    don.Deleted = false;
                    don.Manhanvien = Common.Utilities.User.NhanVienID;
                    don.Tendangnhap = Common.Utilities.User.TenDangNhap;
                    don.ThanhToanSauKhiLapPhieu = "0";
                    if (dgvInsertOrder.RowCount > 0)
                    {
                        if (CheckData(don) == true)
                        {
                            cl = new Server_Client.Client();
                            this.client = cl.Connect(Luu.IP, Luu.Ports);
                            clientstrem = cl.SerializeObj(this.client, "HoaDonNhap", don);
                            Entities.HoaDonNhap[] tralai = new Entities.HoaDonNhap[1];
                            int trave = System.Convert.ToInt32(cl.DeserializeHepper(clientstrem, tralai));
                            if (trave == 1)
                            {
                                thanhtoan[0] = don;
                                try
                                {
                                    LuuChiTietDonHang();
                                }
                                catch { }
                                CapNhatTrangThaiDonDatHang("Update", MaDonDatHang, "Đã thành công");
                                frmQuanLyNhapKho.BaoDong = "";
                                DialogResult giatri = MessageBox.Show("Bạn có muốn thêm phiếu nhập tiếp không?", "Thông Báo", System.Windows.Forms.MessageBoxButtons.YesNo);
                                {
                                    if (giatri == DialogResult.No)
                                        frmQuanLyNhapKho.BaoDong = "A";
                                } this.Close();
                            }
                            else
                            {
                                MessageBox.Show("Thất bại");
                            }
                        }
                    }
                    else
                    { MessageBox.Show("Không có hàng hóa trong đơn đặt hàng"); }
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message.ToString();
                MessageBox.Show("Thông tin nhập không đúng");
            }
        }