/// <summary> /// 设置数据绑定函数 /// </summary> private void SetBinding() { // "配置"-"数据存储位置" 绑定到 programPath实例 System.Windows.Data.Binding bindProgramPath = new System.Windows.Data.Binding("Path"); bindProgramPath.Source = programPath; bindProgramPath.Mode = BindingMode.OneWay; textBoxDataBasePath.SetBinding(System.Windows.Controls.TextBox.TextProperty, bindProgramPath); // "公司" 绑定到 SettingDatabase // 创建连接到设置信息数据库 string sql = "Data Source=" + Program.ReadProgramPath() + "\\设置信息.gsygeo"; using (SQLiteConnection conn = new SQLiteConnection(sql)) { // 打开连接 conn.Open(); // 绑定单位名称 System.Windows.Data.Binding bindCompanyName = new System.Windows.Data.Binding("Name"); bindCompanyName.Source = company; bindCompanyName.Mode = BindingMode.OneWay; CompanyNameTextBox.SetBinding(System.Windows.Controls.TextBox.TextProperty, bindCompanyName); // 绑定单位资质代码 System.Windows.Data.Binding bindCompanyCode = new System.Windows.Data.Binding("Code"); bindCompanyCode.Source = company; bindCompanyCode.Mode = BindingMode.OneWay; CompanyCodeTextBox.SetBinding(System.Windows.Controls.TextBox.TextProperty, bindCompanyCode); // 绑定人员列表 this.CompanyPeopleListView.ItemsSource = company.People; } }
private void AddCustomersButton_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); //символен низ за връзка към базата данни – взема се от файл с име app.config con.ConnectionString = ConfigurationManager.ConnectionStrings["MassiveDynamic.Properties.Settings.MassiveDynamicConnectionString"].ConnectionString; //символен низ със заявката към базата данни string insertIntoId = "'" + CustomerIdAddTextBox.Text + "'"; string inserIntoCustomerName = "'" + CompanyNameTextBox.Text + "'"; string inserIntoCustomerAddress = "'" + AddressTextBox.Text + "'"; string inserIntoCustomerPhone = "'" + CustomerPhoneTextBox.Text + "'"; //INSERT INTO table_name (column1,column2,column3,...) VALUES(value1, value2, value3,...); Insert into cheatSheet string insertCommand = string.Format("insert into Customers (CustomerID,CompanyName,Address,Phone) values({0},{1},{2},{3});", insertIntoId, inserIntoCustomerName, inserIntoCustomerAddress, inserIntoCustomerPhone); SqlCommand com = new SqlCommand(insertCommand, con); //определяне на типа на командата - в конкретния случай е текст com.CommandType = CommandType.Text; try { //отваряме връзката към базата данни con.Open(); //изпълняваме командата / в този случай нямаме връщан резултат com.ExecuteNonQuery(); //извеждаме съобщение, че всичко е преминало успешно MessageBox.Show("Данните за форма на обучение са добавени успешно!", "Message/Съобщение"); //изчистваме въведената стойност в текстовото поле CustomerIdAddTextBox.Clear(); CompanyNameTextBox.Clear(); AddressTextBox.Clear(); CustomerPhoneTextBox.Clear(); } //ако не е преминало всичко успешно, това означава, че е възникнало изключение catch (Exception exe) { //извеждаме съобщение с възникналото изключение MessageBox.Show(exe.ToString(), "Message/Съобщение:"); } //затваря се връзката към базата данни con.Close(); //затваря се отворената форма this.Close(); }
private bool IsValidated() { try { if (LicenseFileTextBox.Text.Length == 0) { MessageBox.Show(this, "Please enter the License File.", _ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning); LicenseFileTextBox.Focus(); BrowseLicenseFile(); return(false); } if (!File.Exists(LicenseFileTextBox.Text)) { MessageBox.Show(this, "Can not find the License File.", _ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning); LicenseFileTextBox.Focus(); BrowseLicenseFile(); return(false); } if (CompanyNameTextBox.Text.Length == 0) { MessageBox.Show(this, "Please enter Company Name.", _ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning); CompanyNameTextBox.Focus(); return(false); } if (UserNameTextBox.Text.Length == 0) { MessageBox.Show(this, "Please enter User Name.", _ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning); UserNameTextBox.Focus(); return(false); } if (EmailTextBox.Text.Length == 0 || !Regex.IsMatch(EmailTextBox.Text, @"^(([^<>()[\]\\.,;:\s@\""]+" + @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@" + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+" + @"[a-zA-Z]{2,}))$")) { MessageBox.Show(this, "Please enter a valid Email Address.", _ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning); EmailTextBox.Focus(); return(false); } return(true); } catch { throw; } }
private void DisplayCompanyEdit() { CompanyEditPopup.IsOpen = true; CompanySelectionPopup.IsOpen = false; CompanyNameTextBox.Focus(); }
private void EditCompanyNoButton_Click(object sender, RoutedEventArgs e) { CompanyNameTextBox.Clear(); }