Пример #1
0
        void LoadLabour()
        {
            UnitService unitService = new();

            unit = unitService.FetchRate(new Model.Unit(null, "KG", ZERO));
            txtLabourRate.Text = unit.Rate.ToString();
        }
 void ClearForm()
 {
     txtUnitName.Clear();
     txtRate.Clear();
     updateUnit        = null;
     btnEdit.Enabled   = false;
     btnDelete.Enabled = false;
     btnAdd.Enabled    = true;
 }
 private void unitGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     btnDelete.Enabled = true;
     btnAdd.Enabled    = false;
     btnEdit.Enabled   = true;
     updateUnit        = new Model.Unit
     {
         Id = Utils.Utility.CellValueByIndex(0, unitGridView)
     };
     txtUnitName.Text = Utils.Utility.CellValueByIndex(1, unitGridView);
     txtRate.Text     = Utils.Utility.CellValueByIndex(2, unitGridView);
 }
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(txtUnitName.Text) && string.IsNullOrWhiteSpace(txtRate.Text))
     {
         MessageBox.Show("Please Enter Details");
         txtUnitName.Focus();
         ClearForm();
     }
     else if (updateUnit != null && !string.IsNullOrEmpty(updateUnit.Id))
     {
         MessageBox.Show("Please Enter New Rate Details");
         updateUnit = null;
         ClearForm();
     }
     else if (!Utils.Utility.IsNumeric(txtRate.Text))
     {
         MessageBox.Show("Enter valid rate");
         ClearForm();
     }
     else
     {
         Model.Unit unit = new Model.Unit(null, txtUnitName.Text, Double.Parse(txtRate.Text));
         if (!RecordExists())
         {
             bool isAdded = unitService.AddUnit(unit);
             if (isAdded)
             {
                 MessageBox.Show("Rate Added !!");
                 ClearForm();
             }
             else
             {
                 MessageBox.Show("Rate adding failed..");
             }
             PopulateUnitGrid();
         }
     }
 }