Beispiel #1
0
 private void DeleteChungTu()
 {
     try
     {
         if (this.Business == null)
         {
             this.Business = GetBussiness();
         }
         ConnectionUtil.Instance.BeginTransaction();
         //OnDeleteChungTu();
         Business.DeleteChungTu();
         ConnectionUtil.Instance.CommitTransaction();
         MessageBox.Show("Đã xóa thành công.");
         this.Close();
         Reload();
     }
     catch (Exception)
     {
         ConnectionUtil.Instance.RollbackTransaction();
         throw;
     }
 }
Beispiel #2
0
        protected virtual void SaveChungTu()
        {
            List <DMChungTuNhapInfo> li = tblChungTuDataProvider.Search(txtSoPhieu.Text.Trim());

            if (li.Count > 0 && OID == 0)
            {
                txtSoPhieu.Focus();
                throw new ManagedException("Số phiếu đã tồn tại trong hệ thống. Xin hãy kiểm tra lại!");
            }
            if (this.Business == null)
            {
                this.Business = GetBussiness();
            }

            try
            {
                ConnectionUtil.Instance.BeginTransaction();
                SaveChungTuInstance();
                Business.SaveChungTu();
                AfterSaveChungTuInstance();
                ConnectionUtil.Instance.CommitTransaction();
            }
            catch (Exception)
            {
                ConnectionUtil.Instance.RollbackTransaction();
                throw;
            }
            Reload();
            //ConnectionUtil.Instance.DoSerializableWorkInTransaction(
            //    delegate
            //    {
            //        SaveChungTuInstance();
            //        Business.SaveChungTu();
            //        AfterSaveChungTuInstance();
            //    });
        }
        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;
            }
        }
        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            if (bteKhoThucHien.Tag == null)
            {
                MessageBox.Show("Bạn chưa chọn kho thực hiện!");
                return;
            }

            if (bteLyDoTraHang.Tag == null)
            {
                MessageBox.Show("Bạn chưa chọn lý do trả hàng!");
                return;
            }

            try
            {
                XuatLinhKienMoi();
                NhapLinhKienLoi();

                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();

                        frmProgress.Instance.MaxValue = 17;

                        ChungTuBusinessBase businessCloned = xuatDoiLinhKienLoiBusiness.Clone();

                        frmProgress.Instance.Value += 1;

                        (businessCloned as XuatDoiLinhKienLoiBusiness).ChungTu.NgayLap =
                            CommonProvider.Instance.GetSysDate();

                        frmProgress.Instance.Value += 1;

                        (businessCloned as XuatDoiLinhKienLoiBusiness).ChungTu.NgayXuatHang =
                            CommonProvider.Instance.GetSysDate();

                        frmProgress.Instance.Value += 1;

                        businessCloned.SaveChungTu();

                        frmProgress.Instance.Value += 1;

                        //cập nhật lại mã linh kiện mới vào phiếu xuất linh kiện.
                        DoiLinhKienLoiDataProvider.Instance.
                        UpdatePhieuXuatLinhKien(linhKienMoi.IdChiTiet,
                                                linhKienLoi.IdChiTiet,
                                                (businessCloned as XuatDoiLinhKienLoiBusiness).
                                                ChungTu.SoChungTuGoc);

                        frmProgress.Instance.Value += 1;

                        businessCloned = nhapDoiLinhKienLoiBusiness.Clone();

                        frmProgress.Instance.Value += 1;

                        (businessCloned as NhapDoiLinhKienLoiBusiness).ChungTu.NgayLap =
                            CommonProvider.Instance.GetSysDate();

                        frmProgress.Instance.Value += 1;

                        (businessCloned as NhapDoiLinhKienLoiBusiness).ChungTu.NgayXuatHang =
                            CommonProvider.Instance.GetSysDate();

                        frmProgress.Instance.Value += 1;

                        businessCloned.SaveChungTu();

                        frmProgress.Instance.Value += 1;

                        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(), "Đổi mã linh kiện");
                        }
                    }
                });

                //ConnectionUtil.Instance.DoSerializableWorkInTransaction(
                //    delegate
                //        {
                //            frmProgress.Instance.MaxValue = 17;

                //            ChungTuBusinessBase businessCloned = xuatDoiLinhKienLoiBusiness.Clone();

                //            frmProgress.Instance.Value += 1;

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

                //            frmProgress.Instance.Value += 1;

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

                //            frmProgress.Instance.Value += 1;

                //            businessCloned.SaveChungTu();

                //            frmProgress.Instance.Value += 1;

                //            //cập nhật lại mã linh kiện mới vào phiếu xuất linh kiện.
                //            DoiLinhKienLoiDataProvider.Instance.
                //                UpdatePhieuXuatLinhKien(linhKienMoi.IdChiTiet,
                //                                        linhKienLoi.IdChiTiet,
                //                                        (businessCloned as XuatDoiLinhKienLoiBusiness).
                //                                            ChungTu.SoChungTuGoc);

                //            frmProgress.Instance.Value += 1;

                //            businessCloned = nhapDoiLinhKienLoiBusiness.Clone();

                //            frmProgress.Instance.Value += 1;

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

                //            frmProgress.Instance.Value += 1;

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

                //            frmProgress.Instance.Value += 1;

                //            businessCloned.SaveChungTu();

                //            frmProgress.Instance.Value += 1;
                //        });

                this.Close();
            }
            catch (Exception ex)
            {
#if DEBUG
                MessageBox.Show(ex.ToString());
#else
                MessageBox.Show(ex.Message);
#endif
                EventLogProvider.Instance.WriteOfflineLog(ex.ToString(), this.Name);
            }
        }
Beispiel #5
0
        void Control_TextChanged(object sender, EventArgs e)
        {
            try
            {
                frmLookUp_SanPham frm;

                if (ColumnMaSanPham == null)
                {
                    return;
                }
                if (!isKeyPressed || dgvChiTiet.CurrentCell.ColumnIndex != dgvChiTiet.Columns.IndexOf(ColumnMaSanPham) ||
                    ((TextBox)sender).Text == String.Empty || ((TextBox)sender).Text == (string)dgvChiTiet.CurrentCell.Value)
                {
                    return;
                }

                if (this.Business == null)
                {
                    this.Business = GetBussiness();
                }

                if (Business.BusinessType == BusinessType.VIRTUAL_OUT || Business.BusinessType == BusinessType.REAL_OUT)
                {
                    frm = new frmLookUp_SanPham(GetIdKho(), 0, true, Business.BusinessType == BusinessType.VIRTUAL_OUT, String.Format("%{0}%", ((TextBox)sender).Text));
                }
                else
                {
                    frm = new frmLookUp_SanPham(String.Format("%{0}%", ((TextBox)sender).Text));
                }

                dgvChiTiet.CurrentCell.Value = null;

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    isKeyPressed = false;
                    PickUpSanPhamInfo(frm.SelectedItem);
                }
                else
                {
                    ((TextBox)sender).Text = String.Empty;
                }
            }
            catch (ManagedException ex)
            {
#if DEBUG
                MessageBox.Show(ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                MessageBox.Show(ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
            catch (Exception ex)
            {
#if DEBUG
                MessageBox.Show(ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                MessageBox.Show(ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
                EventLogProvider.Instance.WriteLog(ex.ToString()
                                                   + "\nUser: "******"\nKho: " + Declare.IdKho,
                                                   this.Name);
            }
        }
Beispiel #6
0
        protected override void SaveChungTu()
        {
            List <DMChungTuNhapInfo> li = tblChungTuDataProvider.Search(txtSoPhieu.Text.Trim());

            if (li.Count > 0 && OID == 0)
            {
                txtSoPhieu.Focus();
                throw new ManagedException("Số phiếu đã tồn tại trong hệ thống. Xin hãy kiểm tra lại!");
            }
            if (this.Business == null)
            {
                this.Business = GetBussiness();
            }

            SaveChungTuInstance();

            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();

                    frmProgress.Instance.MaxValue      = 10;
                    ChungTuBusinessBase clonedBusiness = Business.Clone();
                    frmProgress.Instance.Value        += 1;
                    clonedBusiness.SaveChungTu();
                    frmProgress.Instance.Value += 1;
                    AfterSaveChungTuInstance();
                    frmProgress.Instance.Value += 1;

                    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(), "Xuất trả NCC");
                    }
                }
            });

            //ConnectionUtil.Instance.DoSerializableWorkInTransaction(
            //    delegate
            //        {
            //            frmProgress.Instance.MaxValue = 10;
            //            ChungTuBusinessBase clonedBusiness = Business.Clone();
            //            frmProgress.Instance.Value += 1;
            //            clonedBusiness.SaveChungTu();
            //            frmProgress.Instance.Value += 1;
            //            AfterSaveChungTuInstance();
            //            frmProgress.Instance.Value += 1;
            //        });
            Reload();
        }