Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ep.Clear();
            int er = 0;

            if (txtName.Text == "")
            {
                er++;
                ep.SetError(txtName, "Required");
            }
            if (txtContact.Text == "")
            {
                er++;
                ep.SetError(txtContact, "Required");
            }
            if (txtDescription.Text == "")
            {
                er++;
                ep.SetError(txtDescription, "Required");
            }
            if (txtAddress.Text == "")
            {
                er++;
                ep.SetError(txtAddress, "Required");
            }
            if (txtContactPerson.Text == "")
            {
                er++;
                ep.SetError(txtContactPerson, "Required");
            }
            if (txtContactPerson.Text == "")
            {
                er++;
                ep.SetError(txtContactPerson, "Required");
            }

            if (txtPassword.Text == "")
            {
                er++;
                ep.SetError(txtPassword, "Required");
            }

            if (cmbHead.SelectedValue == null || cmbHead.SelectedValue.ToString() == "")
            {
                er++;
                ep.SetError(cmbHead, "Required");
            }
            if (cmbEmployee.SelectedValue == null || cmbEmployee.SelectedValue.ToString() == "")
            {
                er++;
                ep.SetError(cmbEmployee, "Required");
            }

            if (er > 0)
            {
                return;
            }

            DAL.Ledger ledger = new DAL.Ledger();
            ledger.Id            = Id;
            ledger.Name          = txtName.Text;
            ledger.Contact       = txtContact.Text;
            ledger.ContactPerson = txtContactPerson.Text;
            ledger.Address       = txtAddress.Text;
            ledger.Description   = txtDescription.Text;
            ledger.Email         = txtEmail.Text;
            ledger.EmployeeId    = Convert.ToInt32(cmbEmployee.SelectedValue);
            ledger.Password      = txtPassword.Text;
            ledger.HeadId        = Convert.ToInt32(cmbHead.SelectedValue);
            ledger.CreateDate    = dtpDate.Value;

            if (ledger.Update())
            {
                MessageBox.Show(@"Data Updated");
            }
            else
            {
                MessageBox.Show(ledger.Error);
            }
        }
Пример #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            int error = 0;

            errorProvider.Clear();

            if (textBoxName.Text == "")
            {
                error++;
                errorProvider.SetError(textBoxName, "Required");
            }

            if (textBoxContact.Text == "")
            {
                error++;
                errorProvider.SetError(textBoxContact, "Required");
            }

            if (textBoxEmail.Text == "")
            {
                error++;
                errorProvider.SetError(textBoxEmail, "Required");
            }

            if (textBoxPassword.Text == "")
            {
                error++;
                errorProvider.SetError(textBoxPassword, "Required");
            }

            if (comboBoxGander.Text == "")
            {
                error++;
                errorProvider.SetError(comboBoxGander, "Required");
            }

            if (textBoxAddress.Text == "")
            {
                error++;
                errorProvider.SetError(textBoxAddress, "Required");
            }

            if (comboBoxCity.Text == "")
            {
                error++;
                errorProvider.SetError(comboBoxCity, "Required");
            }

            if (dateTimePickerDateOfBirth.Text == "")
            {
                error++;
                errorProvider.SetError(dateTimePickerDateOfBirth, "Required");
            }

            if (dateTimePickerCreateDate.Text == "")
            {
                error++;
                errorProvider.SetError(dateTimePickerCreateDate, "Required");
            }

            if (comboBoxType.Text == "")
            {
                error++;
                errorProvider.SetError(comboBoxType, "Required");
            }

            //if (pictureBoxLedger.Text  == "")
            //{
            //    error++;
            //    errorProvider.SetError(pictureBoxLedger, "Required");
            //}

            if (error > 0)
            {
                return;
            }


            ledger.Name        = textBoxName.Text;
            ledger.Contact     = textBoxContact.Text;
            ledger.Email       = textBoxEmail.Text;
            ledger.Password    = textBoxPassword.Text;
            ledger.Gander      = comboBoxGander.Text;
            ledger.Address     = textBoxAddress.Text;
            ledger.CityId      = Convert.ToInt32(comboBoxCity.SelectedValue);
            ledger.DateOfBirth = Convert.ToDateTime(dateTimePickerDateOfBirth.Text);
            ledger.CreateDate  = Convert.ToDateTime(dateTimePickerCreateDate.Text);
            ledger.Type        = comboBoxType.Text;
            ledger.Image       = DAL.FileImage.ImageToByte(pictureBoxLedger.Image);

            if (ledger.Update())
            {
                MessageBox.Show("Ledger Updated");
                textBoxName.Text               = "";
                textBoxContact.Text            = "";
                textBoxEmail.Text              = "";
                textBoxPassword.Text           = "";
                comboBoxGander.Text            = "";
                textBoxAddress.Text            = "";
                comboBoxCity.Text              = "";
                dateTimePickerDateOfBirth.Text = "";
                dateTimePickerCreateDate.Text  = "";
                comboBoxType.Text              = "";
                pictureBoxLedger.Text          = "";
                textBoxName.Focus();
            }
            else
            {
                MessageBox.Show(ledger.Error);
            }
        }