Esempio n. 1
0
 private void UpdateTrangthai()
 {
     if (SanXuatLenhProvier.GetSoLuongSanXuatLenh(Declare.IdKho, Convert.ToInt32(TransactionType.NHAP_THANH_PHAM_SX),
                                                  txtMaLenh.Text.Trim(), 1) == frm.SoLuongYC)
     {
         SanXuatLenhProvier.UpdateTrangThai(new SanXuatLenhInfo
         {
             MaLenh      = txtMaLenh.Text.Trim(),
             MaThanhPham = txtMaSP.Text.Trim(),
             TrangThai   = Convert.ToInt32(TrangThaiSanXuat.DaSanXuatXong)
         });
     }
 }
        private void Save()
        {
            for (int i = 0; i < liChiTiet.Count; i++)
            {
                if (liChiTiet[i].check == false)
                {
                    throw new ManagedException("Bạn chưa xác nhận đủ mã vạch linh kiện để tách thành phẩm !");
                }
            }
            int SoLuongCT = SanXuatLenhProvier.GetSoLuongChungTu(
                Convert.ToInt32(TransactionType.XUAT_THANH_PHAM),
                txtMaLenh.Text.Trim(), 1, frm.TransactionID);

            if (Convert.ToInt32(txtSoLuongYC.Text) <= SoLuongCT)
            {
                throw new ManagedException("Số lượng yêu cầu đã đủ không thể nhập thêm !");
            }
            if (string.IsNullOrEmpty(dtNgayLap.Text))
            {
                dtNgayLap.Focus();
                throw new ManagedException("Bạn chưa trọn ngày lập !");
            }
            if (Convert.ToDateTime(dtNgayLap.EditValue) < frm.NgayLap)
            {
                dtNgayLap.Focus();
                throw new ManagedException("Ngày nhập thành phẩm không được nhỏ hơn ngày lập của mã lệnh!");
            }
            try
            {
                SaveNhapLinhKien(SaveXuatThanhPham());

                string maLenh        = txtMaVachLK.Text.Trim();
                string maThanhPham   = txtMaSP.Text.Trim();
                int    soLuongYc     = frm.SoLuongYC;
                string transactionId = frm.TransactionID;

                frmProgress.Instance.Caption     = Text;
                frmProgress.Instance.Description = "Đang thực hiện ...";
                frmProgress.Instance.MaxValue    = 100;
                frmProgress.Instance.Value       = 0;

                frmProgress.Instance.DoWork(
                    delegate
                {
                    try
                    {
                        ConnectionUtil.Instance.BeginTransaction();

                        ChungTuBusinessBase businessCloned = XTP.Clone();

                        ((XuatThanhPhamSXBussiness)businessCloned).ChungTu.NgayLap =
                            CommonProvider.Instance.GetSysDate();

                        ((XuatThanhPhamSXBussiness)businessCloned).ChungTu.NgayXuatHang =
                            CommonProvider.Instance.GetSysDate();

                        businessCloned.SaveChungTu();

                        businessCloned = NLK.Clone();

                        ((NhapLinhKienSXBussiness)businessCloned).ChungTu.NgayLap =
                            CommonProvider.Instance.GetSysDate();

                        ((NhapLinhKienSXBussiness)businessCloned).ChungTu.NgayXuatHang =
                            CommonProvider.Instance.GetSysDate();

                        businessCloned.SaveChungTu();

                        KhoNhapNccDataProvider.Instance.UpdateTrangThaiChungTu(new ChungTuXuatNhapNccInfo {
                            IdChungTu = sanXuatNhapTachInfo.IdChungTu, TrangThai = 2
                        });

                        if (SanXuatLenhProvier.GetSoLuongSanXuatLenh(Declare.IdKho, Convert.ToInt32(TransactionType.XUAT_LINK_KIEN_SX), maLenh, 1) != soLuongYc)
                        {
                            SanXuatLenhProvier.UpdateTrangThai(new SanXuatLenhInfo
                            {
                                MaLenh      = maLenh,
                                MaThanhPham = maThanhPham,
                                TrangThai   = Convert.ToInt32(TrangThaiSanXuat.DangSX)
                            });
                        }

                        SoLuongCT = SanXuatLenhProvier.GetSoLuongChungTu(
                            Convert.ToInt32(TransactionType.XUAT_THANH_PHAM), maLenh, 1, transactionId);

                        if (soLuongYc < SoLuongCT)
                        {
                            throw new ManagedException("Số lượng yêu cầu đã đủ không thể nhập thêm!");
                        }

                        ConnectionUtil.Instance.CommitTransaction();

                        frmProgress.Instance.Description = "Đã xong!";

                        frmProgress.Instance.Value = frmProgress.Instance.MaxValue;

                        frmProgress.Instance.IsCompleted = true;
                    }
                    catch (Exception ex)
                    {
                        ConnectionUtil.Instance.RollbackTransaction();

                        MessageBox.Show(ex.Message);

                        frmProgress.Instance.Description = "Giao dịch không thành công!";

                        frmProgress.Instance.Value = frmProgress.Instance.MaxValue;

                        frmProgress.Instance.IsCompleted = true;

                        if (!(ex is ManagedException))
                        {
                            EventLogProvider.Instance.WriteOfflineLog(ex.ToString(), "Tách thành phẩm SX");
                        }
                    }
                });

                //ConnectionUtil.Instance.DoSerializableWorkInTransaction(
                //    delegate
                //        {
                //            ChungTuBusinessBase businessCloned = XTP.Clone();

                //            ((XuatThanhPhamSXBussiness)businessCloned).ChungTu.NgayLap =
                //                CommonProvider.Instance.GetSysDate();

                //            ((XuatThanhPhamSXBussiness)businessCloned).ChungTu.NgayXuatHang =
                //                CommonProvider.Instance.GetSysDate();

                //            businessCloned.SaveChungTu();

                //            businessCloned = NLK.Clone();

                //            ((NhapLinhKienSXBussiness) businessCloned).ChungTu.NgayLap =
                //                CommonProvider.Instance.GetSysDate();

                //            ((NhapLinhKienSXBussiness)businessCloned).ChungTu.NgayXuatHang =
                //                CommonProvider.Instance.GetSysDate();

                //            businessCloned.SaveChungTu();

                //            KhoNhapNccDataProvider.Instance.UpdateTrangThaiChungTu(new ChungTuXuatNhapNccInfo { IdChungTu = sanXuatNhapTachInfo.IdChungTu, TrangThai = 2 });

                //            if (SanXuatLenhProvier.GetSoLuongSanXuatLenh(Declare.IdKho, Convert.ToInt32(TransactionType.XUAT_LINK_KIEN_SX), maLenh, 1) != soLuongYc)
                //            {
                //                SanXuatLenhProvier.UpdateTrangThai(new SanXuatLenhInfo
                //                {
                //                    MaLenh = maLenh,
                //                    MaThanhPham = maThanhPham,
                //                    TrangThai = Convert.ToInt32(TrangThaiSanXuat.DangSX)
                //                });
                //            }

                //            SoLuongCT = SanXuatLenhProvier.GetSoLuongChungTu(
                //                Convert.ToInt32(TransactionType.XUAT_THANH_PHAM), maLenh, 1, transactionId);

                //            if (soLuongYc < SoLuongCT)
                //            {
                //                throw new ManagedException("Số lượng yêu cầu đã đủ không thể nhập thêm!");
                //            }
                //        });

                Clear();
                frm.Reload();
                //clsUtils.MsgThongBao("Tách thành công 1 thành phẩm !");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
 private void Save()
 {
     if (txtMaVachTP.Text == "")
     {
         throw new ManagedException("Mã vạch cho thành phẩm không được để trống !");
     }
     for (int i = 0; i < lisx.Count; i++)
     {
         if (lisx[i].SoLuongDaQuet < lisx[i].SoLuongTrenTPham)
         {
             throw new ManagedException("Linh kiện " + lisx[i].TenLinhKien + " chưa nhập đủ số lượng mã vạch !");
         }
     }
     if (check == 0)
     {
         int SoLuongCT = SanXuatLenhProvier.GetSoLuongDNSanXuatLenh(
             Convert.ToInt32(TransactionType.NHAP_THANH_PHAM_SX), txtMaLenh.Text.Trim(), Declare.MaTrungTam);
         if (Convert.ToInt32(txtSoLuongYC.Text) <= SoLuongCT)
         {
             throw new ManagedException("Số lượng yêu cầu đã đủ, bạn không thể nhập thêm");
         }
     }
     if (check == 0 && isXuatLoi == false)
     {
         if (TblHangHoaChiTietDataProvider.IsUsedForAnotherProduct(txtMaVachTP.Text.Trim(), frm.idThanhPham))
         {
             throw new ManagedException("Mã vạch đã sử dụng cho 1 sản phẩm khác. Xin hãy kiểm tra lại !");
         }
         if (NhapThanhPhamSanXuatDataProvider.Instance.CheckMaVachNTP(frm.idThanhPham, txtMaVachTP.Text.Trim()) > 0)
         {
             throw new ManagedException("Mã vạch đã sử dụng cho 1 sản phẩm khác. Xin hãy kiểm tra lại !");
         }
         if (NhapThanhPhamSanXuatDataProvider.Instance.CheckMaVach(frm.idThanhPham, txtMaVachTP.Text.Trim()) > 0)
         {
             throw new ManagedException("Mã vạch đã sử dụng cho 1 sản phẩm khác. Xin hãy kiểm tra lại !");
         }
     }
     for (int i = 0; i < lisx.Count; i++)
     {
         if (lisx[i].SoLuongDaQuet < lisx[i].SoLuongTrenTPham)
         {
             throw new ManagedException("Bạn chưa nhập đủ số lượng mã vạch cho linh kiện " + lisx[i].MaLinhKien + " !");
         }
     }
     if (string.IsNullOrEmpty(dtNgayLap.Text))
     {
         dtNgayLap.Focus();
         throw new ManagedException("Bạn chưa chọn ngày lập !");
     }
     if (Convert.ToDateTime(dtNgayLap.EditValue) < frm.NgayLap)
     {
         dtNgayLap.Focus();
         throw new ManagedException("Ngày xuất linh kiện không được nhỏ hơn ngày lập của mã lệnh !");
     }
     try
     {
         ConnectionUtil.Instance.BeginTransaction();
         if (check == 0)
         {
             SaveXuatLinhKien(SaveNhapThanhPham());
             SLCT++;
         }
         else
         {
             XLKBussiness.SaveChungTu();
         }
         txtSoLuongCT.Text = SLCT.ToString();
         UpdateSoLuongDaXuat();
         if (SanXuatLenhProvier.GetSoLuongSanXuatLenh(Declare.IdKho, Convert.ToInt32(TransactionType.NHAP_THANH_PHAM_SX), txtMaLenh.Text.Trim(), 0) > 0)
         {
             SanXuatLenhProvier.UpdateTrangThai(new SanXuatLenhInfo {
                 MaLenh = txtMaLenh.Text.Trim(), MaThanhPham = txtMaThanhPham.Text.Trim(), TrangThai = Convert.ToInt32(TrangThaiSanXuat.DangSX)
             });
         }
         if (check == 0)
         {
             int SoLuongCT = SanXuatLenhProvier.GetSoLuongDNSanXuatLenh(
                 Convert.ToInt32(TransactionType.NHAP_THANH_PHAM_SX), txtMaLenh.Text.Trim(), Declare.MaTrungTam);
             if (Convert.ToInt32(txtSoLuongYC.Text) < SoLuongCT)
             {
                 throw new ManagedException("Số lượng yêu cầu đã đủ,bạn không thể nhập thêm");
             }
         }
         ConnectionUtil.Instance.CommitTransaction();
         clsUtils.MsgThongBao("Xuất thành công !");
         if (clsUtils.MsgXoa("Bạn có muốn in phiếu bảo hành cho bộ linh kiện không ?") == System.Windows.Forms.DialogResult.Yes)
         {
             List <ChungTuNhapNccChiTietHangHoaInfo> lst = new List <ChungTuNhapNccChiTietHangHoaInfo>();
             lst.AddRange(liMaVach);
             frmChonBaoCao frm1 = new frmChonBaoCao(true);
             frm1.ShowDialog();
             if (frm1.DialogResult == DialogResult.OK)
             {
                 if (frm1.Value == 1)
                 {
                     DMSanPhamInfo sp = DmSanPhamProvider.Instance.GetSanPhamByMa(txtMaThanhPham.Text.Trim());
                     foreach (ChungTuNhapNccChiTietHangHoaInfo pt in lst)
                     {
                         pt.ThoiHanBH = sp.BaoHanhHang;
                     }
                     rptInPhieuBHSX rpt = new rptInPhieuBHSX(txtTenThanhPham.Text.Trim(), txtMaLenh.Text.Trim(), txtMaVachTP.Text.Trim());
                     rpt.DataSource = lst;
                     rpt.ShowPreview();
                 }
                 else
                 {
                     rptInPhieuBHSX rpt = new rptInPhieuBHSX(txtTenThanhPham.Text.Trim(), txtMaLenh.Text.Trim(), txtMaVachTP.Text.Trim());
                     rpt.DataSource = lst;
                     rpt.ShowPreview();
                 }
             }
         }
         Clear();
         frm.LoadDuLieu();
     }
     catch (Exception ex)
     {
         ConnectionUtil.Instance.RollbackTransaction();
         throw ex;
     }
 }