Exemplo n.º 1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (is_Validate())
            {
                try
                {
                    Benefit _Benefit = new Benefit();
                    if (!string.IsNullOrEmpty(txtName.Text))
                    {
                        _Benefit.Description = Utils.ConvertFirstLetterToUpper(txtName.Text.Trim());
                    }
                    decimal rate;
                    if (!string.IsNullOrEmpty(txtRate.Text) && decimal.TryParse(txtRate.Text, out rate))
                    {
                        _Benefit.Rate = decimal.Parse(txtRate.Text);
                    }
                    _Benefit.IsDeleted = false;

                    if (db.Benefits.Any(c => c.Description == _Benefit.Description && c.IsDeleted == false))
                    {
                        MessageBox.Show("Description Exist!", "SB Payroll", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    if (!db.Benefits.Any(c => c.Description == _Benefit.Description && c.IsDeleted == false))
                    {
                        db.Benefits.AddObject(_Benefit);
                        db.SaveChanges();

                        Benefits f = (Benefits)this.Owner;
                        f.RefreshGrid();
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    Utils.ShowError(ex);
                }
            }
        }