Exemple #1
0
        private void btnSaveDonation_Click(object sender, RoutedEventArgs e)
        {
            if (txtName.Text == "" || txtAmount.Text == "")
            {
                MessageBox.Show("Please enter Name and Amount.");
                return;
            }
            if (txtEmail.Text != "")
            {
                if (!Regex.IsMatch(txtEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
                {
                    MessageBox.Show("Please enter correct Email");
                    return;
                }
            }
            if (txtPhone.Text != "")
            {
                if (!Regex.IsMatch(txtPhone.Text, @"[^0-9]+"))
                {
                    MessageBox.Show("Please enter correct phone number");
                    return;
                }
            }

            /*
             * if (cbByType.SelectedItem != null)
             * {
             *  if ((cbByType.SelectedItem as ComboBoxItem).Content.ToString() != "By Cash")
             *  {
             *      MessageBox.Show("Please Enter Neft/ DD / Check Number");
             *      return;
             *  }
             * }
             */

            db = new SQLiteDatabase();
            Donation dobj = new Donation();

            dobj.ReceiptNo  = txtSLNo.Text;//
            dobj.Ddate      = TxtDate.Text;
            dobj.Name       = txtName.Text;
            dobj.Gender     = (bool)rbfeMale.IsChecked ? "Female" : "Male";
            dobj.Email      = txtEmail.Text;
            dobj.Phone      = txtPhone.Text;
            dobj.Place      = txtPlace.Text;
            dobj.FundType   = cbFundType.Text;
            dobj.Amount     = Convert.ToDecimal((!string.IsNullOrWhiteSpace(txtAmount.Text) ? txtAmount.Text : "0"));
            dobj.BTNo       = txtBNo.Text;
            dobj.Address    = txtAddress.Text;
            dobj.Comment    = txtComment.Text;
            dobj.AmountType = cbByType.Text;
            dobj.Place      = txtPlace.Text;
            if (IsDonationEdit)
            {
                dobj.Modified   = DateTime.Now.ToSqlLiteDatetime();
                dobj.ModifiedBy = LoginUser.UName;
                dobj.Created    = Convert.ToDateTime(SelectedItem.Created).ToSqlLiteDatetime();
                dobj.CreatedBy  = SelectedItem.CreatedBy;
                Dictionary <string, string> dic1 = GetTypePropertyValues <Donation>(dobj);
                string s = db.Update("Donations", dic1, " ReceiptNo =" + Convert.ToString(dobj.ReceiptNo) + "");
                db.ExecuteNonQuery(s);
            }
            else
            {
                dobj.Created   = DateTime.Now.ToSqlLiteDatetime();
                dobj.CreatedBy = LoginUser.UName;
                Dictionary <string, string> dic1 = GetTypePropertyValues <Donation>(dobj);
                string s = db.Insert("Donations", dic1);
                db.ExecuteNonQuery(s);
                NextNumber = "";
            }

            splAddDonation.Visibility = Visibility.Collapsed;
            splDonations.Visibility   = Visibility.Visible;
            LoadData();
            IsDonationEdit = false;
            FillDoantionForm(new Donation());
            SelectedItem = null;
        }