コード例 #1
0
        private void btnSaveBorrowers_Click(object sender, EventArgs e)
        {
            var record = new Borrowers
            {
                FirstName = txtFirstNameBorrowers.Text,
                LastName  = txtLastNameBorrowers.Text,
                Phone     = txtPhoneBorrowers.Text,
                Email     = txtEmailBorrowers.Text
            };

            if (txtIDBorrowers.Text.Equals(""))
            {
                Borrowers.Insert(record);
            }
            else
            {
                record.Id = Convert.ToInt64(txtIDBorrowers.Text);
                Borrowers.Update(record);
            }
            BorrowersGrid();
        }
コード例 #2
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (this.ValidateInputs(txtFirstName.Text, txtLastname.Text, txtMiddlename.Text, txtAddress.Text, txtContacts.Text, txtBday.Text,
                                    txtOccupation.Text, txtMonthlySalary.Text))
            {
                this.Message("Warning! Please Fill Up All Fields.", "Input Validation", true);
                return;
            }

            if (ValidateAlpha(txtFirstName.Text) || ValidateAlpha(txtLastname.Text) || ValidateAlpha(txtOccupation.Text) ||
                ValidateNumeric(txtContacts.Text) || ValidateNumeric(txtMonthlySalary.Text))
            {
                this.Message("Warning! Invalid Characters are Detected. Please use letters and spaces only.", "Input Validation", true);
                return;
            }

            if (bdayValidation)
            {
                this.Message("Warning! Please input correct birthday.", "Input Validation", true);
                return;
            }

            string[]      dob      = txtBday.Text.Split('/');
            DateTime      birthday = new DateTime(int.Parse(dob[2]), int.Parse(dob[0]), int.Parse(dob[1]));
            BorrowerModel b        = new BorrowerModel()
            {
                Id            = id,
                FirstName     = txtFirstName.Text.ToUpper(),
                LastName      = txtLastname.Text.ToUpper(),
                MiddleName    = txtMiddlename.Text.ToUpper(),
                Address       = txtAddress.Text.ToUpper(),
                ContactNumber = txtContacts.Text,
                Birthday      = birthday,
                Occupation    = txtOccupation.Text.ToUpper(),
                MonthlySalary = Convert.ToDecimal(txtMonthlySalary.Text),
                Gender        = optMale.Checked == true ? "MALE" : "FEMALE",
                CivilStatus   = cboCivilStatus.SelectedItem.ToString(),
            };

            if (operation == "update")
            {
                b.Image = _image;
                if (await borrower.Update(b))
                {
                    if (b.Image.Contains("default") && b.Image != _image)
                    {
                        img.CopyImage(_image, b.Image);
                    }
                    this.Message(borrower.msg, "Borrower", false);
                    this.Hide();
                    using (frmViewBorrowers frm = new frmViewBorrowers())
                    {
                        frm.ShowDialog();
                    }
                }
                else
                {
                    this.Message(borrower.msg, "Borrower", true);
                }
            }
            else
            {
                b.Image = _image == "default.png" ? "images/" + _image : "images/" + img.RenameImage(_image);
                if (await borrower.Add(b))
                {
                    if (_image != "default.png")
                    {
                        MessageBox.Show(_image);
                        img.CopyImage(_image, b.Image);
                    }
                    this.Message(borrower.msg, "Borrower", false);
                    this.Hide();
                    using (frmViewBorrowers frm = new frmViewBorrowers())
                    {
                        frm.ShowDialog();
                    }
                }
                else
                {
                    this.Message(borrower.msg, "Borrower", true);
                }
            }
        }