public ClientAddressForm(int _id) { id = _id; InitializeComponent(); BLAddress bLAddress = new BLAddress(); dataGridClientAddress.DataSource = bLAddress.Address(id); BLClient bLClient = new BLClient(); ClientModule client = new ClientModule(); client = bLClient.GetClientList(id, "", "", "", "", "")[0]; txtClientName.Text = client.ClientName; txtClientSurname.Text = client.ClientSurname; txtClientCode.Text = client.ClientCode; txtEmail.Text = client.Email; txtPhoneNo.Text = client.PhoneNo; dataGridClientAddress.Columns["ClientId"].Visible = false; dataGridClientAddress.Columns["ClientAddressId"].Visible = false; dataGridClientAddress.Columns["ClientName"].Visible = false; dataGridClientAddress.Columns["ClientSurname"].Visible = false; dataGridClientAddress.Columns["CityName"].HeaderText = "Oras"; dataGridClientAddress.Columns["CountyName"].HeaderText = "Judet"; dataGridClientAddress.Columns["StreetName"].HeaderText = "Nume Strada"; dataGridClientAddress.Columns["StreetNo"].HeaderText = "Numar Strada"; dataGridClientAddress.Columns["status"].Visible = false; dataGridClientAddress.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; }
private void BtnFilterPartner_Click(object sender, EventArgs e) { lblMessage.Text = "Selectati un client pentru a modifica sau sterge.\n" + "Pentru a vedea, modifica sau sterge adresa, dublu click perandul clientului "; string clientName = txtClientName.Text; string clientSurname = txtClientSurname.Text; string clientCode = txtClientCode.Text; string phoneNo = txtPhoneNo.Text; string email = txtEmail.Text; //int id = null; BLClient bLGetClient = new BLClient(); List <ClientModule> list = bLGetClient.GetClientList(-1, clientName, clientSurname, clientCode, phoneNo, email); if (list.Count == 0) { MessageBox.Show("Nu sunt inregistrari cu parametrii introdusi!!!", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); } dataGridClient.DataSource = list; dataGridClient.Columns["ClientId"].Visible = false; dataGridClient.Columns["ClientName"].HeaderText = "Nume Client"; dataGridClient.Columns["ClientSurname"].HeaderText = "Prenume Client"; dataGridClient.Columns["PhoneNo"].HeaderText = "Numar de telefon"; dataGridClient.Columns["Email"].HeaderText = "Email"; dataGridClient.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridClient.RowHeaderMouseDoubleClick += DataGridClient_RowHeaderMouseDoubleClick; //dataGridClient.RowHeaderMouseClick += DataGridClient_RowHeaderMouseClick; //dataGridClient.SelectedRows[0].Cells[0].Value; //dataGridClient.Columns.GetFirstColumn.Hide(); }
//private void BtnModify_Click(object sender, EventArgs e) //{ // if (dataGridClient.SelectedRows.Count == 0) // { // MessageBox.Show("Trebuie sa selectati un client."); // return; // } // else // { // ClientModule client = (ClientModule)dataGridClient.SelectedRows[0].DataBoundItem; // UpdateClientForm updateClientForm = new UpdateClientForm(client.ClientId); // updateClientForm.Show(); // this.Hide(); // updateClientForm.FormClosed += UpdateClientForm_FormClosed; // } //} //private void UpdateClientForm_FormClosed(object sender, FormClosedEventArgs e) //{ // this.Close(); //} private void BtnDelete_Click(object sender, EventArgs e) { if (dataGridClient.SelectedRows.Count == 0) { MessageBox.Show("Trebuie sa selectati un client."); return; } BLClient bLClient = new BLClient(); ClientModule client = (ClientModule)dataGridClient.SelectedRows[0].DataBoundItem; //UpdateClientForm updateClientForm = new UpdateClientForm(client.ClientId); if (MessageBox.Show("Sunteti sigur ca vreiti sa stergeti clientul " + client.ClientName + " " + client.ClientSurname + "?", "Mesaj de avertizare!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { bLClient.DeleteClient(client.ClientId); MessageBox.Show(client.ClientName + " " + client.ClientSurname + " a fost sters cu succes."); List <ClientModule> list = bLClient.GetClientList(-1, "", "", "", "", ""); dataGridClient.DataSource = list; } else { return; } }
public void Save(int id) { BLClient bl = new BLClient(); if (id != 0) { List <ClientModule> listUpdate = bl.GetClientList(id, "", "", "", "", ""); ClientModule client = listUpdate[0]; string clientName = txtClientName.Text; string clientSurname = txtClientSurname.Text; string clientCode = txtClientCode.Text; string email = txtEmail.Text; string phoneNo = txtPhoneNo.Text; if (!(clientName == client.ClientName & clientSurname == client.ClientSurname & clientCode == client.ClientCode & email == client.Email & phoneNo == client.PhoneNo)) { foreach (char c in txtPhoneNo.Text.ToCharArray()) { if (!(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9')) { MessageBox.Show("Tnumarul de telefon trebuie sa contina doar cife.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (!(new EmailAddressAttribute().IsValid(txtEmail.Text)) & !String.IsNullOrWhiteSpace(txtEmail.Text)) { MessageBox.Show("Emailul trebuie sa fie valid!", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //txtClientCode.TextChanged bool status = false; if (clientCode == client.ClientCode) { bl.UpdateClient(id, clientName, clientSurname, "", phoneNo, email, out status); } else { bl.UpdateClient(id, clientName, clientSurname, clientCode, phoneNo, email, out status); } //BLClient bl = new BLClient(); if (status) { MessageBox.Show("Modificare reusita."); } else { MessageBox.Show("Codul de client exista deja!"); return; } } BLAddress bLAddress = new BLAddress(); //List<AddressModel> list= new List<AddressModel>(); //list = bLAddress.Address(id); for (int i = 0; i < dataGridClientAddress.Rows.Count; i++) { AddressModel addressModel = new AddressModel(); addressModel = (AddressModel)dataGridClientAddress.Rows[i].DataBoundItem; if (addressModel.status == 1) { bLAddress.AddAddress(id, addressModel.CityName, addressModel.CountyName, addressModel.StreetName, addressModel.StreetNo); } //INSERT if (addressModel.status == 2) { bLAddress.UpdateAddress(id, addressModel.ClientAddressId, addressModel.CityName, addressModel.CountyName, addressModel.StreetName, addressModel.StreetNo); } //UPDATE if (addressModel.status == 3) { bLAddress.DeleteAddress(addressModel.ClientId, addressModel.ClientAddressId); } } } else { if (String.IsNullOrWhiteSpace(txtClientName.Text)) { MessageBox.Show("Numele clientului este obligatoriu", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (String.IsNullOrWhiteSpace(txtClientSurname.Text)) { MessageBox.Show("Prenumele utilizatorului eate obligatoriu", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (String.IsNullOrWhiteSpace(txtClientCode.Text)) { MessageBox.Show("codul de client este obligatoriu", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (char c in txtPhoneNo.Text.ToCharArray()) { if (!(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9')) { MessageBox.Show("Numarul de telefon trebuie sa contina doar cife.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (!(new EmailAddressAttribute().IsValid(txtEmail.Text)) & !String.IsNullOrWhiteSpace(txtEmail.Text)) { MessageBox.Show("Emailul trebuie sa fie valid!", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string clientName = txtClientName.Text; string clientSurname = txtClientSurname.Text; string clientCode = txtClientCode.Text; string phoneNo = String.IsNullOrWhiteSpace(txtPhoneNo.Text) ? null : txtPhoneNo.Text; string email = String.IsNullOrWhiteSpace(txtEmail.Text) ? null : txtEmail.Text;; bool status = true; bl.AddClient(clientName, clientSurname, clientCode, phoneNo, email, out status); if (status) { MessageBox.Show("Clientul " + clientName + " " + clientSurname + " a fost adaugat cu succes"); List <ClientModule> list = bl.GetClientList(-1, "", "", clientCode, "", ""); Save(list[0].ClientId);//RECURSIVITATE } //MessageBox.Show("Clientul " + clientName + " " + clientSurname + " a fost adaugat cu succes"); else { MessageBox.Show("Codul de client exista deja!"); } } }