示例#1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtName.Text) || string.IsNullOrWhiteSpace(txtType.Text) || string.IsNullOrWhiteSpace(cmbUnit.Text))
            {
                ClsCommon.ShowErrorToolTip(txtName, "Please Enter The ProductionMaterial Name");
            }
            else
            {
                var model = new ProductionMaterialModel
                {
                    ProductionMaterialId = _productionMaterialId,
                    MaterialName         = txtName.Text,
                    MaterialType         = txtType.Text,
                    Description          = txtDesc.Text,
                    UnitOfMeasurementId  = (int)cmbUnit.SelectedValue
                };

                if (_isNewMode)
                {
                    _productionMaterialId = _productionMaterialService.Save(model).ProductionMaterialId;
                    if (_productionMaterialId <= 0)
                    {
                        return;
                    }
                    MessageBox.Show(@"Data Saved Successfully", @"Save", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    var frm = (FrmProductionMaterial)_frmForm;
                    frm.grdData.Rows.Add(_productionMaterialId, model.MaterialName, model.UnitOfMeasurementId, cmbUnit.Text, model.MaterialType, model.Description);
                    frm.grdData.Rows[frm.grdData.Rows.Count - 1].IsSelected = true;
                    txtName.Focus();
                    txtName.Text = "";
                    Notify();
                }
                else
                {
                    var success = _productionMaterialService.Update(model).ProductionMaterialId;
                    if (success <= 0)
                    {
                        return;
                    }
                    MessageBox.Show(@"Data Updated Successfully", @"Update", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    var frm = (FrmProductionMaterial)_frmForm;
                    frm.grdData.CurrentRow.Cells["MaterialName"].Value        = model.MaterialName;
                    frm.grdData.CurrentRow.Cells["MaterialType"].Value        = model.MaterialType;
                    frm.grdData.CurrentRow.Cells["UnitOfMeasurementId"].Value = model.UnitOfMeasurementId;
                    frm.grdData.CurrentRow.Cells["UnitName"].Value            = cmbUnit.Text;
                    frm.grdData.CurrentRow.Cells["Description"].Value         = model.Description;
                    Close();
                    Notify();
                }
            }
        }