private void btnAddNew_Click(object sender, EventArgs e) { try { using (var frm = new frmClient() { Text = "הוסף מנוי" }) { frm.btnAction.Text = "הוסף"; frm.CardSnExists = sn => { var clientID = Dal.GetClientIdByCardSn(sn); return clientID != 0; }; frm.RemoveCardSnFromPrevious = sn => Dal.DeleteCardSn(sn); if (frm.ShowDialog() == DialogResult.Cancel) return; var client = Customers.NewRow(); client["FirstName"] = frm.firstNameTextBox.Text; client["LastName"] = frm.lastNameTextBox.Text; client["IdentificationNumber"] = frm.identificationNumberTextBox.Text; client["Address"] = frm.addressTextBox.Text; client["Email"] = frm.emailTextBox.Text; client["BirthDate"] = frm.birthDateDateTimePicker.Value; client["Active"] = 1; client["CreationTimeStamp"] = DateTime.Now; client["CardSN"] = frm.txtCardSN.Text; client["Phone"] = frm.mtxtPhone.Text; client["Image"] = frm.pbClient.Image.ConvertTo64BaseString(); Dal.AddOrUpdateCustomer(client); } LoadData(); } catch (Exception ex) { ErrorMessage(ex.GetAllMessages()); } }
private void EditCUstomer(DataRow client) { if (client == null) { ErrorMessage("Failed to get customer record"); return; } using (var frm = new frmClient() { Text = "עריכת מנוי" }) { frm.btnAction.Text = "שמור"; frm.firstNameTextBox.Text = client.Field<string>("FirstName"); frm.lastNameTextBox.Text = client.Field<string>("LastName"); frm.identificationNumberTextBox.Text = client.Field<string>("IdentificationNumber"); frm.addressTextBox.Text = client.Field<string>("Address"); frm.emailTextBox.Text = client.Field<string>("Email"); frm.birthDateDateTimePicker.Value = client.Field<DateTime>("BirthDate"); frm.txtCardSN.Text = client.Field<string>("CardSN"); frm.mtxtPhone.Text = client.Field<string>("Phone"); var img = client.Field<string>("Image"); if (!string.IsNullOrEmpty(img)) frm.pbClient.Image = img.Base64StringToImage(); frm.CardSnExists = sn => { var clientID = Dal.GetClientIdByCardSn(sn); return clientID != 0 && clientID != client.Field<int>("Id"); }; frm.RemoveCardSnFromPrevious = sn => Dal.DeleteCardSn(sn); if (frm.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; client["FirstName"] = frm.firstNameTextBox.Text; client["LastName"] = frm.lastNameTextBox.Text; client["IdentificationNumber"] = frm.identificationNumberTextBox.Text; client["Address"] = frm.addressTextBox.Text; client["Email"] = frm.emailTextBox.Text; client["BirthDate"] = frm.birthDateDateTimePicker.Value; client["CardSN"] = frm.txtCardSN.Text; client["Phone"] = frm.mtxtPhone.Text; client["Image"] = frm.pbClient.Image.ConvertTo64BaseString(); } UpdateCustomer(client); // LoadData(); }