private void Save_Button_Click(object sender, EventArgs e)
        {
            VoucherCover selected = VoucherCover_LookupEdit.GetSelectedDataRow().CastTo <VoucherCover>();

            if (selected == null)
            {
                MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000032);
            }

            List <VoucherCoverDetail> saveData = this.VoucherCoverDetailData
                                                 .Where(o => (o.SEQ ?? 0) > 0 && (o.Status == ModifyMode.Insert || o.Status == ModifyMode.Update)).ToList();

            if (VoucherCoverDetailDeleteData != null && VoucherCoverDetailDeleteData.Count > 0)
            {
                saveData?.InsertRange(0, VoucherCoverDetailDeleteData);
            }

            if (saveData?.Count > 0)
            {
                using (VoucherCoverController controller = new VoucherCoverController())
                {
                    if (controller.SaveVoucherCoverDetail(saveData))
                    {
                        MessageBoxHelper.ShowInfoMessage(BSMessage.BSM000001);
                        VoucherCoverDetailDeleteData = new List <VoucherCoverDetail>();
                        this.LoadGridData();
                    }
                    else
                    {
                        MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000002);
                    }
                }
            }
        }
        private void UpdateVoucherCover()
        {
            VoucherCover selected = VoucherCover_LookupEdit.GetSelectedDataRow().CastTo <VoucherCover>();

            if (selected == null)
            {
                MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000032);
                return;
            }

            var frm = new InputBox()
            {
                Text    = "Sửa tiêu đề",
                Content = selected.VoucherCoverName
            };

            if (frm.ShowDialog() == DialogResult.OK)
            {
                selected.VoucherCoverName = frm.Content;
                selected.Status           = ModifyMode.Update;

                if (SaveVoucherCover(selected))
                {
                    MessageBoxHelper.ShowInfoMessage(BSMessage.BSM000001);
                    InitComboBox();
                }
                else
                {
                    MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000002);
                }
            }
        }
        private void Insert_Button_Click(object sender, EventArgs e)
        {
            VoucherCover selected = VoucherCover_LookupEdit.GetSelectedDataRow().CastTo <VoucherCover>();

            if (selected == null)
            {
                MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000032);
                return;
            }

            VoucherCoverDetail detailSelected = Detail_GridView.GetFocusedRow().CastTo <VoucherCoverDetail>();

            if (detailSelected == null)
            {
                MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000032);
                return;
            }

            int index = VoucherCoverDetailData.FindIndex(o => o.VoucherCoverID == selected.VoucherCoverID && o.SEQ == detailSelected.SEQ);

            if (index < 0)
            {
                index = 0;
            }

            VoucherCoverDetailData.Insert(index, new VoucherCoverDetail
            {
                VoucherCoverID = selected.VoucherCoverID,
                Status         = ModifyMode.Insert
            });

            SetSEQ();
            Detail_GridView.RefreshData();
            Detail_GridView.FocusedRowHandle = index;
        }
 private bool SaveVoucherCover(VoucherCover data)
 {
     using (var controller = new VoucherCoverController())
     {
         return(controller.SaveVoucherCover(data));
     }
 }
        private void AddNewVoucherCover()
        {
            var frm = new InputBox()
            {
                Text = "Thêm mới tiêu đề"
            };

            if (frm.ShowDialog() == DialogResult.OK)
            {
                var data = new VoucherCover
                {
                    Status           = ModifyMode.Insert,
                    VoucherCoverName = frm.Content
                };

                if (SaveVoucherCover(data))
                {
                    MessageBoxHelper.ShowInfoMessage(BSMessage.BSM000001);
                    InitComboBox();
                    VoucherCover_LookupEdit.EditValue = data.VoucherCoverID;
                }
                else
                {
                    MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000002);
                }
            }
        }
        public bool DeleteVoucherCover(VoucherCover data)
        {
            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@VoucherCoverID", data.VoucherCoverID)
            };

            this.Context.ExecuteDataFromProcedure("VoucherCoverDelete", sqlParameters);

            return(true);
        }
        private void Delete_Button_Click(object sender, EventArgs e)
        {
            VoucherCover selected = VoucherCover_LookupEdit.GetSelectedDataRow().CastTo <VoucherCover>();

            if (selected == null)
            {
                MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000032);
                return;
            }

            Detail_GridView.DeleteSelectedRows();
            SetSEQ();
        }
        public bool UpdateVoucherCover(VoucherCover data)
        {
            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@VoucherCoverID", data.VoucherCoverID),
                new SqlParameter("@VoucherCoverName", data.VoucherCoverName),
                new SqlParameter("@CompanyID", CommonInfo.CompanyInfo.CompanyID),
                new SqlParameter("@UpdateUser", UserInfo.UserID)
            };

            this.Context.ExecuteDataFromProcedure("VoucherCoverUpdate", sqlParameters);

            return(true);
        }
 private void SetSEQ()
 {
     if (STTAuto_CheckEdit.Checked)
     {
         int          seq      = 0;
         VoucherCover selected = VoucherCover_LookupEdit.GetSelectedDataRow().CastTo <VoucherCover>();
         for (int i = 0; i < VoucherCoverDetailData.Count; i++)
         {
             if (VoucherCoverDetailData[i].VoucherCoverID == selected.VoucherCoverID)
             {
                 seq++;
                 VoucherCoverDetailData[i].SEQ = seq;
             }
         }
     }
 }
        private void DeleteVoucherCover()
        {
            VoucherCover selected = VoucherCover_LookupEdit.GetSelectedDataRow().CastTo <VoucherCover>();

            selected.Status = ModifyMode.Delete;

            if (SaveVoucherCover(selected))
            {
                MessageBoxHelper.ShowInfoMessage(BSMessage.BSM000001);
                InitComboBox();
            }
            else
            {
                MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000002);
            }
        }
        private List <VoucherCoverDetail> GetSelectedDetailData()
        {
            VoucherCover selected = VoucherCover_LookupEdit.GetSelectedDataRow().CastTo <VoucherCover>();

            if (selected == null || VoucherCoverDetailData == null)
            {
                return(null);
            }

            List <VoucherCoverDetail> result = VoucherCoverDetailData
                                               .Where(o => o.VoucherCoverID == selected.VoucherCoverID).ToList();

            result.ForEach(o => o.VoucherCoverName = selected.VoucherCoverName);

            return(result);
        }
        private void SetFilterDetail()
        {
            this.Detail_GridView.ClearColumnsFilter();
            VoucherCover selected = VoucherCover_LookupEdit.GetSelectedDataRow().CastTo <VoucherCover>();

            if (selected == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(selected.VoucherCoverID))
            {
                //Set new filter
                string filter = string.Empty;
                filter += $"[VoucherCoverID] = '{selected.VoucherCoverID}'";
                this.Detail_GridView.ActiveFilterString = filter;
            }
        }
        private void Add_Button_Click(object sender, EventArgs e)
        {
            VoucherCover selected = VoucherCover_LookupEdit.GetSelectedDataRow().CastTo <VoucherCover>();

            if (selected == null)
            {
                MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000032);
                return;
            }

            VoucherCoverDetailData.Add(new VoucherCoverDetail
            {
                VoucherCoverID = selected.VoucherCoverID,
                Status         = ModifyMode.Insert
            });

            SetSEQ();
            Detail_GridView.RefreshData();
            Detail_GridView.FocusedRowHandle = Detail_GridView.RowCount - 1;
        }
        public bool SaveVoucherCover(VoucherCover data)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = this.VoucherCoverDAO.GetVoucherCoverSEQ();
                    switch (data.Status)
                    {
                    // Add new
                    case ModifyMode.Insert:
                        seq++;
                        data.VoucherCoverID = GenerateID.VoucherCoverID(seq);

                        this.VoucherCoverDAO.InsertVoucherCover(data);
                        break;

                    // Update
                    case ModifyMode.Update:
                        this.VoucherCoverDAO.UpdateVoucherCover(data);
                        break;

                    // Delete
                    case ModifyMode.Delete:
                        this.VoucherCoverDAO.DeleteVoucherCover(data);
                        break;
                    }

                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 15
0
 public bool SaveVoucherCover(VoucherCover data)
 {
     return(this.VoucherCoverLogic.SaveVoucherCover(data));
 }