Beispiel #1
0
 public frm_PhieuDeNghiNhapTieuHao()
 {
     InitializeComponent();
     Common.LoadStyle(this);
     business = new DeNghiNhapTieuHaoBusiness();
 }
Beispiel #2
0
 public frm_PhieuDeNghiNhapTieuHao(ChungTuDeNghiXuatTieuHaoInfornew xuatTieuHaoInfor)
 {
     InitializeComponent();
     Common.LoadStyle(this);
     business = new DeNghiNhapTieuHaoBusiness(xuatTieuHaoInfor);
 }
Beispiel #3
0
        private void SaveAll()
        {
            try
            {
                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!");
                }
                //ConnectionUtil.Instance.BeginTransaction();
                SaveChungTu();
                for (int i = 0; i < opt.selection.Count; i++)
                {
                    DeNghiXuatTieuHaoChiTietInfonew dn = (DeNghiXuatTieuHaoChiTietInfonew)opt.selection[i];
                    business.ListChiTietChungTu.Add(dn);
                }

                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;

                        DeNghiNhapTieuHaoBusiness businessCloned = (DeNghiNhapTieuHaoBusiness)business.Clone();

                        frmProgress.Instance.Value += 1;

                        if (businessCloned.ChungTu.IdChungTu == 0 &&
                            !dteNgay.Enabled)
                        {
                            businessCloned.ChungTu.NgayLap = 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(), "Đề nghị nhập tiêu hao");
                        }
                    }
                });

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

                //            DeNghiNhapTieuHaoBusiness businessCloned = (DeNghiNhapTieuHaoBusiness)business.Clone();

                //            frmProgress.Instance.Value += 1;

                //            if (businessCloned.ChungTu.IdChungTu == 0 &&
                //                !dteNgay.Enabled) businessCloned.ChungTu.NgayLap = CommonProvider.Instance.GetSysDate();

                //            frmProgress.Instance.Value += 1;

                //            businessCloned.SaveChungTu();

                //            frmProgress.Instance.Value += 1;

                //        });
                ////ConnectionUtil.Instance.CommitTransaction();
            }
            catch (Exception)
            {
                //ConnectionUtil.Instance.RollbackTransaction();
                throw;
            }
        }