private void OKBtn_Click(object sender, EventArgs e) { if (FIOtextBox.Text != "" && LogintextBox.Text != "" && PsswdtextBox.Text != "") { DataSet1 newDataSet1 = new DataSet1(); DataSet1TableAdapters.workerTableAdapter workerTA = new DataSet1TableAdapters.workerTableAdapter(); workerTA.Fill(newDataSet1.worker); if (EditFlag == false) { workerTA.Insert(LogintextBox.Text, PsswdtextBox.Text, comboBox1.Text, FIOtextBox.Text, BornDTP.Value.Date); } else { workerTA.UpdateQuery(LogintextBox.Text, PsswdtextBox.Text, comboBox1.Text, FIOtextBox.Text, Convert.ToString(BornDTP.Value.Date), Login, Password, tipe, FIO, Convert.ToString(BornDate)); } SuccessFlag = true; WorkerAddForm.ActiveForm.Close(); } else { MessageBox.Show("Заполнены не все поля!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); FIOtextBox.Focus(); } }
private void WorkerAddForm_Shown(object sender, EventArgs e) { FIOtextBox.Text = ""; FIOtextBox.Focus(); SuccessFlag = false; OKBtn.Top = WorkerAddForm.ActiveForm.Height - OKBtn.Height * 3; CancelBtn.Top = WorkerAddForm.ActiveForm.Height - CancelBtn.Height * 3; OKBtn.Left = WorkerAddForm.ActiveForm.Width / 2 - OKBtn.Width - OKBtn.Width / 2; CancelBtn.Left = WorkerAddForm.ActiveForm.Width / 2 + CancelBtn.Width / 2; WorkerAddForm.ActiveForm.Text = FormHeader; FIOtextBox.Text = FIO; LogintextBox.Text = Login; PsswdtextBox.Text = Password; comboBox1.Text = tipe; BornDTP.Value = BornDate; FIOtextBox.Focus(); SuccessFlag = false; }
private void SaveButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(FIOtextBox.Text)) { MessageBox.Show("Enter contact name!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FIOtextBox.Focus(); FIOtextBox.BackColor = COLOR_ERROR; return; } if (string.IsNullOrEmpty(MAINPHONEtextBox.Text)) { MessageBox.Show("Enter main phone!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MAINPHONEtextBox.Focus(); MAINPHONEtextBox.BackColor = COLOR_ERROR; return; } string CommandText = string.Empty; switch (ACTION) { case 1: // редактировать CommandText = string.Format("UPDATE callers SET fio='{0}', organization='{1}', department='{2}', position='{3}', mainphone='{4}', cellphone='{5}', workphone='{6}', email='{7}', note='{8}' ", FIOtextBox.Text.Trim(), //0 ORGtextBox.Text.Trim(), //1 DEPtextBox.Text.Trim(), //2 POStextBox.Text.Trim(), //3 MAINPHONEtextBox.Text.Trim(), //4 CELLPHONEtextBox.Text.Trim(), //5 WORKPHONEtextBox.Text.Trim(), //6 EMAILtextBox.Text.Trim(), //7 NOTErichTextBox.Text); //8 if (IMPORTANTcheckBox.Checked) { CommandText += ", important=1 "; } else { CommandText += ", important=0 "; } if (PersonalCheckBox.Checked) { CommandText += string.Format(", personal='{0}' ", AsteriskPhoneAgentForm.ASTERISK_PEER_NUMBER); } else { CommandText += ", personal='ALL' "; } CommandText += string.Format(", callercreator='{0}', datecreate='{1}' WHERE callerid='{2}'", Environment.UserName, //0 DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), //1 CALLER_ID); //2 break; case 2: // добавить CommandText = string.Format("INSERT INTO callers (fio, organization, department, position, mainphone, cellphone, workphone, email, note, important, personal, callercreator, datecreate) " + " VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}' ", FIOtextBox.Text.Trim(), //0 ORGtextBox.Text.Trim(), //1 DEPtextBox.Text.Trim(), //2 POStextBox.Text.Trim(), //3 MAINPHONEtextBox.Text.Trim(), //4 CELLPHONEtextBox.Text.Trim(), //5 WORKPHONEtextBox.Text.Trim(), //6 EMAILtextBox.Text.Trim(), //7 NOTErichTextBox.Text); //8 if (IMPORTANTcheckBox.Checked) { CommandText += ", 1 "; } else { CommandText += ", 0 "; } if (PersonalCheckBox.Checked) { CommandText += string.Format(", '{0}'", AsteriskPhoneAgentForm.ASTERISK_PEER_NUMBER); } else { CommandText += ", 'ALL' "; } CommandText += string.Format(", '{0}', '{1}');", Environment.UserName, //0 DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //1 break; } MySqlConnection myConnection = new MySqlConnection(CONNECTION_STRING); MySqlCommand myCommand = new MySqlCommand(CommandText, myConnection); try { myConnection.Open(); //Устанавливаем соединение с базой данных. MySqlDataReader MyDataReader; MyDataReader = myCommand.ExecuteReader(); MyDataReader.Close(); CommandText = string.Format("UPDATE callerschange SET chdatetime='{0}';", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); MySqlCommand myCommand1 = new MySqlCommand(CommandText, myConnection); MyDataReader = myCommand1.ExecuteReader(); MyDataReader.Close(); this.Close(); } catch (Exception exConnecting) { MessageBox.Show(exConnecting.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { myConnection.Close(); } AsteriskPhoneAgentForm.ADD_OR_EDIT_RESULT = true; }