Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (checkValidation())
            {
                if (isEdit)
                {
                    int            editPunishmentCount  = 0;
                    PunishmentRule updatePunishmentRule = (from p in mbmsEntities.PunishmentRules where p.PunishmentRuleID == punishmentRuleID select p).FirstOrDefault();
                    if (txtPunishmentCode.Text != updatePunishmentRule.PunishmentCode)
                    {
                        editPunishmentCount = (from p in mbmsEntities.PunishmentRules where p.PunishmentCode == txtPunishmentCode.Text && p.Active == true select p).ToList().Count;
                    }

                    if (editPunishmentCount > 0)
                    {
                        tooltip.SetToolTip(txtPunishmentCode, "Error");
                        tooltip.Show("Punishment Rule Code is already exist!", txtPunishmentCode);
                        return;
                    }

                    updatePunishmentRule.PunishmentCode = txtPunishmentCode.Text;
                    updatePunishmentRule.ExceedMonth    = Convert.ToInt32(txtExceedMonth.Text);
                    updatePunishmentRule.Amount         = Convert.ToDecimal(txtAmount.Text);
                    updatePunishmentRule.UpdatedUserID  = UserID;
                    updatePunishmentRule.UpdatedDate    = DateTime.Now;
                    punishmentRuleController.UpdatePurnishmentRule(updatePunishmentRule);
                    MessageBox.Show("Successfully updated Punishment Rule!", "Update");
                    isEdit       = false;
                    btnSave.Text = "Save";
                    Clear();
                    FormRefresh();
                }
                else
                {
                    PunishmentRule punishmentRule      = new PunishmentRule();
                    int            punishmentRuleCount = 0;
                    punishmentRuleCount = (from p in mbmsEntities.PunishmentRules where p.PunishmentCode == txtPunishmentCode.Text && p.Active == true select p).ToList().Count;

                    if (punishmentRuleCount > 0)
                    {
                        tooltip.SetToolTip(txtPunishmentCode, "Error");
                        tooltip.Show("Punishment Rule Code is already exist!", txtPunishmentCode);
                        return;
                    }
                    punishmentRule.PunishmentRuleID = Guid.NewGuid().ToString();
                    punishmentRule.PunishmentCode   = txtPunishmentCode.Text;
                    punishmentRule.ExceedMonth      = Convert.ToInt32(txtExceedMonth.Text);
                    punishmentRule.Amount           = Convert.ToDecimal(txtAmount.Text);
                    punishmentRule.Active           = true;
                    punishmentRule.CreatedUserID    = UserID;
                    punishmentRule.CreatedDate      = DateTime.Now;
                    punishmentRuleController.Save(punishmentRule);
                    MessageBox.Show("Successfully registered Punishment Rule! Please check it in 'Punishment Rule List'.", "Save Success");
                    Clear();
                    FormRefresh();
                }
            }
        }
Ejemplo n.º 2
0
        public void DeletePrunishmentRule(PunishmentRule r)
        {
            PunishmentRule punishmentRule = mBMSEntities.PunishmentRules.Where(x => x.PunishmentRuleID == r.PunishmentRuleID).SingleOrDefault();

            punishmentRule.Active        = r.Active;
            punishmentRule.DeletedDate   = DateTime.Now;
            punishmentRule.DeletedUserID = r.DeletedUserID;
            mBMSEntities.SaveChanges();
        }
Ejemplo n.º 3
0
 private void dgvPunishmentRuleList_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
 {
     foreach (DataGridViewRow row in dgvPunishmentRuleList.Rows)
     {
         PunishmentRule punishmentRule = (PunishmentRule)row.DataBoundItem;
         row.Cells[0].Value = punishmentRule.PunishmentRuleID;
         row.Cells[1].Value = punishmentRule.PunishmentCode;
         row.Cells[2].Value = punishmentRule.ExceedMonth;
         row.Cells[3].Value = punishmentRule.Amount;
     }
 }
Ejemplo n.º 4
0
        public void UpdatePurnishmentRule(PunishmentRule r)
        {
            PunishmentRule punishmentRule = mBMSEntities.PunishmentRules.Where(x => x.PunishmentRuleID == r.PunishmentRuleID).SingleOrDefault();

            punishmentRule.PunishmentCode = r.PunishmentCode;
            punishmentRule.ExceedMonth    = r.ExceedMonth;
            punishmentRule.Amount         = r.Amount;
            punishmentRule.UpdatedUserID  = r.UpdatedUserID;
            punishmentRule.UpdatedDate    = DateTime.Now;
            mBMSEntities.PunishmentRules.AddOrUpdate(punishmentRule); //requires using System.Data.Entity.Migrations;
            mBMSEntities.SaveChanges();
        }
Ejemplo n.º 5
0
 private void dgvPunishmentRuleList_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0)
     {
         if (e.ColumnIndex == 5)
         {
             //DeleteForPunishmentRule
             if (!CheckingRoleManagementFeature("PunishmentEditOrDelete"))
             {
                 MessageBox.Show("Access Denied for this function.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
             DialogResult result = MessageBox.Show(this, "Are you sure you want to delete?", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
             if (result.Equals(DialogResult.OK))
             {
                 DataGridViewRow row = dgvPunishmentRuleList.Rows[e.RowIndex];
                 punishmentRuleID = Convert.ToString(row.Cells[0].Value);
                 dgvPunishmentRuleList.DataSource = "";
                 PunishmentRule punishmentRule = (from p in mbmsEntities.PunishmentRules where p.PunishmentRuleID == punishmentRuleID select p).FirstOrDefault();
                 punishmentRule.Active        = false;
                 punishmentRule.DeletedUserID = UserID;
                 punishmentRule.DeletedDate   = DateTime.Now;
                 punishmentRuleController.DeletePrunishmentRule(punishmentRule);
                 dgvPunishmentRuleList.DataSource = (from p in mbmsEntities.PunishmentRules where p.Active == true orderby p.PunishmentCode descending select p).ToList();
                 MessageBox.Show(this, "Successfully Deleted!", "Delete Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 Clear();
                 FormRefresh();
             }
         }
         else if (e.ColumnIndex == 4)
         {
             //EditPunishmentRule
             if (!CheckingRoleManagementFeature("PunishmentEditOrDelete"))
             {
                 MessageBox.Show("Access Denied for this function.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
             DataGridViewRow row = dgvPunishmentRuleList.Rows[e.RowIndex];
             punishmentRuleID       = Convert.ToString(row.Cells[0].Value);
             txtPunishmentCode.Text = Convert.ToString(row.Cells[1].Value);
             txtExceedMonth.Text    = Convert.ToString(row.Cells[2].Value);
             txtAmount.Text         = Convert.ToString(row.Cells[3].Value);
             isEdit            = true;
             this.btnSave.Text = "Update";
         }
     }
 }
Ejemplo n.º 6
0
 public void Save(PunishmentRule r)
 {
     mBMSEntities.PunishmentRules.Add(r);
     mBMSEntities.SaveChanges();
 }