Beispiel #1
0
        private void NewCustomerSaveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                customers customer_Insert = new customers
                {
                    companyCode = int.Parse(CompanyCodeTextBox.Text.ToString()),
                    name        = CompanyNameTextBox.Text.ToString(),
                    address     = AddressTextBox.Text.ToString(),
                    texRate     = decimal.Parse(TexRateTextBox.Text.ToString()),
                    country     = CountryTextBox.Text.ToString()
                };
                //to new a new customer.
                db.customers.Add(customer_Insert);
                db.SaveChanges();
                MessageBox.Show("已新增客户:" + CompanyNameTextBox.Text.ToString(), "新增客户成功!", MessageBoxButton.OK, MessageBoxImage.Information);

                CompanyCodeTextBox.Text = "";
                CompanyNameTextBox.Text = "";
                AddressTextBox.Text     = "";
                TexRateTextBox.Text     = "";
                CountryTextBox.Text     = "";
                // set all the textbox to null;
            }
            catch
            {
                MessageBox.Show("数据库写入异常!", "新增客户失败!", MessageBoxButton.OK, MessageBoxImage.Information);
                //if insert db error then info.
            }
        }
Beispiel #2
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            contactPerson addContactPerson = new contactPerson()
            {
                companyCode     = getCompanyCode,
                department      = DepartmentTextBox.Text,
                gender          = GenderTextBox.Text,
                name            = NameTextBox.Text,
                contacnPersonID = int.Parse(ContactPersonIDTextBox.Text)
            };

            //add a new contact person to db.
            db.contactPerson.Add(addContactPerson);
            db.SaveChanges();
            closeDialogEvent();
            //after save in db,use this func to call reload_datagrid func to refresh the data.
            this.Close();
        }
Beispiel #3
0
 public int SaveChanges()
 {
     return(db.SaveChanges());
 }