예제 #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         int    isApprored = TextUtils.ToInt(grvDetail.GetFocusedRowCellValue(colIsApproved));
         int    actionType = TextUtils.ToInt(grvDetail.GetFocusedRowCellValue(colActionType));
         string ActionType = TextUtils.ToString(grvDetail.GetFocusedRowCellValue(colActionTypes));
         int    id         = TextUtils.ToInt(grvDetail.GetFocusedRowCellValue(colWorkingID));
         //      int ProductWorkingID = TextUtils.ToInt(grvDetail.GetFocusedRowCellValue());
         if (id == 0)
         {
             return;
         }
         if ((actionType == 2 || actionType == 3) && isApprored == 1)
         {
             MessageBox.Show("Mục kiểm tra đang chờ duyệt", "Không được xóa", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return;
         }
         ProductWorkingModel model = (ProductWorkingModel)ProductWorkingBO.Instance.FindByPK(id);
         if (MessageBox.Show("Bạn có chắc muốn xóa mục cần kiểm tra [" + grvDetail.GetFocusedRowCellValue(colWorkingName).ToString() + "] không?",
                             TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
         {
             return;
         }
         // Chờ duyệt và Thêm thì xóa trực tiếp không ghi vào Lịch sử hành động
         if (TextUtils.ToInt(grvDetail.GetFocusedRowCellValue(colIsApproved)) == 1 && TextUtils.ToInt(grvDetail.GetFocusedRowCellValue(colActionType)) == 1)
         {
             ProductWorkingAuditBO.Instance.DeleteByAttribute("ProductWorkingID", id);
             ProductWorkingBO.Instance.Delete(id);
             grvDetail.DeleteSelectedRows();
         }
         else
         {
             // MessageBox.Show("Hành động này cần được duyệt", "Xác nhận", MessageBoxButtons.OK, MessageBoxIcon.Information);
             if (model.ID > 0)
             {
                 model.IsApproved = 1;
                 model.ActionType = 3;
                 ProductWorkingBO.Instance.Update(model);
                 string          reason = "";
                 frmReasonChange frm    = new frmReasonChange();
                 if (frm.ShowDialog() == DialogResult.OK)
                 {
                     reason = frm.Reason;
                 }
                 ProductWorkingAudit.ProductID        = ProductID;
                 ProductWorkingAudit.ProductWorkingID = model.ID;
                 ProductWorkingAudit.ProductStepCode  = model.ProductStepCode;
                 ProductWorkingAudit.MaxValue         = model.MaxValue;
                 ProductWorkingAudit.MinValue         = model.MinValue;
                 ProductWorkingAudit.WorkingName      = model.WorkingName;
                 ProductWorkingAudit.PeriodValue      = model.PeriodValue;
                 ProductWorkingAudit.SortOrder        = model.SortOrder;
                 ProductWorkingAudit.Unit             = model.Unit;
                 ProductWorkingAudit.ValueType        = model.ValueType;
                 ProductWorkingAudit.ProductStepID    = model.ProductStepID;
                 ProductWorkingAudit.CheckValueType   = model.CheckValueType;
                 ProductWorkingAudit.CreatedBy        = Global.AppFullName;
                 ProductWorkingAudit.CreatedDate      = DateTime.Now;
                 ProductWorkingAudit.UpdatedBy        = Global.AppFullName;
                 ProductWorkingAudit.UpdatedDate      = DateTime.Now;
                 ProductWorkingAudit.IsApproved       = 1;
                 ProductWorkingAudit.ActionType       = 3;
                 ProductWorkingAudit.ReasonChange     = reason;
                 ProductWorkingAuditBO.Instance.Insert(ProductWorkingAudit);
             }
         }
         loadWorking();
         //    ProductWorkingBO.Instance.Delete(id);
         //   grvDetail.DeleteSelectedRows();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #2
0
        /// <summary>
        /// Cất dữ liệu
        /// </summary>
        /// <returns></returns>
        bool saveData()
        {
            if (!ValidateForm())
            {
                return(false);
            }
            string reason = "";
            string sql    = $"SELECT ReasonChange from ProductWorkingAudit " +
                            $"WHERE ProductWorkingID='{ProductWorking.ID}' ";

            reason = TextUtils.ToString(LibIE.ExcuteScalar(sql));
            frmReasonChange frm = new frmReasonChange();

            frm.Reason = reason;
            if (frm.ShowDialog() == DialogResult.OK)
            {
                reason = frm.Reason;
                if (ProductWorking.ID > 0)
                {
                    ProductWorking.ActionType = 2;
                    ProductWorking.IsApproved = 1;
                    //MessageBox.Show("Chờ duyệt", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ProductWorkingBO.Instance.Update(ProductWorking);
                }
                if (Global.UserID != 0)
                {
                    ProductWorking.CreatedBy = Global.AppFullName;
                    ProductWorking.UpdatedBy = Global.AppFullName;
                }
                ProductWorking.ProductID       = ProductID;
                ProductWorking.ProductStepID   = TextUtils.ToInt(cboStep.EditValue);
                ProductWorking.WorkingName     = txtName.Text.Trim();
                ProductWorking.SortOrder       = (int)txtSortOrder.Value;
                ProductWorking.IsHidden        = chkIsShow.Checked;
                ProductWorking.Unit            = txtUnit.Text.Trim();
                ProductWorking.ValueType       = cboValueType.SelectedIndex;// kiểu kiểm tra
                ProductWorking.ValueTypeName   = cboValueType.SelectedIndex == 0 ? "Check mark" : "Giá trị\n数値";
                ProductWorking.MaxValue        = TextUtils.ToDecimal(txtMax.Value);
                ProductWorking.MinValue        = TextUtils.ToDecimal(txtMin.Value);
                ProductWorking.CheckValueType  = cboCheckValueType.SelectedIndex;
                ProductWorking.ProductStepCode = cboStep.Text;
                ProductWorking.IsApproved      = 1;
                if (ProductWorking.ValueType == 0)//checkmark
                {
                    ProductWorking.PeriodValue = txtPeriodValue.Text.Trim();
                }
                else
                {
                    if (ProductWorking.CheckValueType == 1)//giá trị dạng số
                    {
                        if (ProductWorking.MinValue == ProductWorking.MaxValue)
                        {
                            ProductWorking.PeriodValue = ProductWorking.MaxValue.ToString("n3");
                        }
                        else
                        {
                            ProductWorking.PeriodValue = ProductWorking.MinValue.ToString("n3") + "~" + ProductWorking.MaxValue.ToString("n3");
                        }
                    }
                    else
                    {
                        ProductWorking.PeriodValue = txtPeriodValue.Text.Trim();
                    }
                }

                if (ProductWorking.ID > 0)
                {
                    if (_isApproved == 1 && _actionType == 1)
                    {
                        ProductWorking.ActionType = 1;
                        ProductWorkingBO.Instance.Update(ProductWorking);
                        return(true);
                    }
                }
                else
                {
                    ProductWorking.ActionType = 1;
                    ProductWorking.ID         = (int)ProductWorkingBO.Instance.Insert(ProductWorking);
                }
                processAudit(ProductWorking, reason);
                return(true);
            }
            return(false);
        }