using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Interventi.Business; namespace Interventi.Client.Forms { public partial class frmClienti : Form { clsClienti clsClienti = new clsClienti(); public frmClienti() { InitializeComponent(); } private void PopolaCampi() { txtSEVIA.Text = dgvSEDI.SelectedRows[0].Cells[5].Value.ToString(); txtSECAP.Text = dgvSEDI.SelectedRows[0].Cells[6].Value.ToString(); txtSECOMU.Text = dgvSEDI.SelectedRows[0].Cells[7].Value.ToString(); txtSEPROV.Text = dgvSEDI.SelectedRows[0].Cells[8].Value.ToString(); txtSETEL1.Text = dgvSEDI.SelectedRows[0].Cells[9].Value.ToString(); txtSETEL2.Text = dgvSEDI.SelectedRows[0].Cells[10].Value.ToString(); txtSEFAX.Text = dgvSEDI.SelectedRows[0].Cells[11].Value.ToString(); txtSEPERS.Text = dgvSEDI.SelectedRows[0].Cells[12].Value.ToString(); txtSEPERC.Text = dgvSEDI.SelectedRows[0].Cells[13].Value.ToString(); txtSEPERM.Text = dgvSEDI.SelectedRows[0].Cells[14].Value.ToString(); } private void CreaArraydiTextBox(TextBox[] txtTextBox) { //UTCOD //CLULMO txtTextBox.SetValue(txtCLCOD, 0); txtTextBox.SetValue(txtCLRAGS, 1); txtTextBox.SetValue(txtCLPIVA, 2); //ISCOD txtTextBox.SetValue(txtCLVIA, 3); txtTextBox.SetValue(txtCLCAP, 4); txtTextBox.SetValue(txtCLCOMU, 5); txtTextBox.SetValue(txtCLPROV, 6); txtTextBox.SetValue(txtCLTEL1, 7); txtTextBox.SetValue(txtCLTEL2, 8); txtTextBox.SetValue(txtCLFAX, 9); txtTextBox.SetValue(txtCLWWW, 10); txtTextBox.SetValue(txtCLMAIL, 11); txtTextBox.SetValue(txtCLPERS, 12); txtTextBox.SetValue(txtCLPERC, 13); txtTextBox.SetValue(txtCLPERM, 14); //TPCOD //PGCOD //SSCOD txtTextBox.SetValue(txtCLNOTE, 15); } private void CreaArraydiCombo(ComboBox[] cboCombo) { cboCombo.SetValue(cboTPCOD, 0); cboCombo.SetValue(cboSSCOD, 1); cboCombo.SetValue(cboPGCOD, 2); } private void toolStripButton7_Click(object sender, EventArgs e) { this.Close(); } private void toolStripButton5_Click(object sender, EventArgs e) { frmClientiRic frmClRic = new frmClientiRic(); frmClRic.ShowDialog(); } private void button2_Click(object sender, EventArgs e) { frmComuni frmComuni = new frmComuni(); frmComuni.ShowDialog(); } private void button1_Click(object sender, EventArgs e) { frmComuni frmComuni = new frmComuni(); frmComuni.ShowDialog(); } private void cLPROVTextBox_TextChanged(object sender, EventArgs e) { } private void frmClienti_Load(object sender, EventArgs e) { ComboBox[] cboCombo = new ComboBox[3]; CreaArraydiCombo(cboCombo); clsClienti.PopolaCombo(cboCombo); txtCLCOD.Focus(); clsClienti.InizializiaGrid(dgvSEDI); } private void txtCLCOD_Leave(object sender, EventArgs e) { bool blnRicerca; TextBox[] txtTextBox = new TextBox[16]; ComboBox[] cbocombo = new ComboBox[3]; txtCLCOD.Text = txtCLCOD.Text.Trim().ToUpper(); if (txtCLCOD.Text.Trim() != "") { blnRicerca = clsClienti.EseguiRicerca(txtCLCOD.Text.Trim().ToUpper()); if (blnRicerca == true) { CreaArraydiTextBox(txtTextBox); CreaArraydiCombo(cbocombo); clsClienti.PopolaCampi(txtTextBox); clsClienti.SettaCombo(cbocombo, txtCLCOD.Text.Trim().ToUpper()); clsClienti.PopolaSedi(dgvSEDI, txtCLCOD.Text.Trim().ToUpper()); if (dgvSEDI.Rows.Count >= 1) { PopolaCampi(); } } } } private void button3_Click(object sender, EventArgs e) { frmClientiTipo frmTPCli = new frmClientiTipo(); frmTPCli.ShowDialog(); } private void button4_Click(object sender, EventArgs e) { frmTecnici frmTecnici = new frmTecnici(); frmTecnici.ShowDialog(); } private void button5_Click(object sender, EventArgs e) { FrmModPag frmModPag = new FrmModPag(); frmModPag.ShowDialog(); } private void dgvSEDI_SelectionChanged(object sender, EventArgs e) { //se non imposto questo if ogni volta che al load la clsasse clsutenti nasconde una colonna parte questo evento if (dgvSEDI.Rows.Count > 1 & dgvSEDI.Columns[0].Visible == false) { PopolaCampi(); } } } } using System; using System.Collections.Generic; using System.Data; using System.Windows.Forms; using Interventi.Data; using Interventi.Data.dsInterventiTableAdapters; namespace Interventi.Business { public class clsClienti { dsInterventi dsInterventi = new dsInterventi(); CLIENTITableAdapter taClienti = new CLIENTITableAdapter(); BindingSource bdnClienti = new BindingSource(); BindingSource bdnSedi = new BindingSource(); TPCLITableAdapter taTPcli = new TPCLITableAdapter(); SYSTEMTableAdapter taSystem = new SYSTEMTableAdapter(); MODPAGTableAdapter taModPag = new MODPAGTableAdapter(); SEDETableAdapter taSede = new SEDETableAdapter(); public void InizializiaGrid(DataGridView DGV) { taSede.FillByCLCOD(dsInterventi.SEDE, ""); bdnSedi.DataSource = dsInterventi; bdnSedi.DataMember = "SEDE"; DGV.DataSource = bdnSedi; /* UTCOD SEULMO SEPROG CLCOD ISCOD SEVIA SECAP SECOMU SEPROV SETEL1 SETEL2 SEFAX SEPERS SEPERC SEPERM */ DGV.Columns["UTCOD"].Visible = false; DGV.Columns["SEULMO"].Visible = false; DGV.Columns["SEPROG"].Visible = false; DGV.Columns["CLCOD"].Visible = false; DGV.Columns["ISCOD"].Visible = false; DGV.Columns["CLCOD"].Visible = false; DGV.Columns["SETEL1"].Visible = false; DGV.Columns["SETEL2"].Visible = false; DGV.Columns["SEFAX"].Visible = false; DGV.Columns["SEPERS"].Visible = false; DGV.Columns["SEPERC"].Visible = false; DGV.Columns["SEPERM"].Visible = false; DGV.Columns["SEVIA"].Width = 250; DGV.Columns["SEVIA"].HeaderText = "Via"; DGV.Columns["SECAP"].Width = 50; DGV.Columns["SECAP"].HeaderText = "CAP"; DGV.Columns["SECOMU"].Width = 100; DGV.Columns["SECOMU"].HeaderText = "Comune"; DGV.Columns["SEPROV"].Width = 40; DGV.Columns["SEPROV"].HeaderText = "Prov"; } public bool EseguiRicerca(string strCLCOD) { taClienti.FillByclCod(dsInterventi.CLIENTI, strCLCOD); if (dsInterventi.CLIENTI.Rows.Count > 0) return true; else return false; } public void PopolaCombo(ComboBox[] cboCombo) { taTPcli.Fill(dsInterventi.TPCLI); DataTableReader dtrTPCli = new DataTableReader(dsInterventi.TPCLI); //dtrTPCli.Read(); cboCombo[0].Items.Add("Selezionare un Tipo Cliente.."); while (dtrTPCli.Read()) { clsCombo combo = new clsCombo(); combo.Add(dtrTPCli[3].ToString(), dtrTPCli[2].ToString()); cboCombo[0].Items.Add(combo); } cboCombo[0].SelectedIndex = 0; taSystem.Fill(dsInterventi.SYSTEM); DataTableReader dtrSystem = new DataTableReader(dsInterventi.SYSTEM); cboCombo[1].Items.Add("Selezionare un Tecnico.."); while (dtrSystem.Read()) { clsCombo combo = new clsCombo(); combo.Add(dtrSystem[3].ToString() + " " + dtrSystem[4].ToString(),dtrSystem[2].ToString()); cboCombo[1].Items.Add(combo); } cboCombo[1].SelectedIndex = 0; taModPag.Fill(dsInterventi.MODPAG); DataTableReader dstModPag = new DataTableReader(dsInterventi.MODPAG); cboCombo[2].Items.Add("Selezionare una Modalità di Pagamento.."); while (dstModPag.Read()) { clsCombo combo = new clsCombo(); combo.Add(dstModPag[3].ToString(), dstModPag[2].ToString()); cboCombo[2].Items.Add(combo); } cboCombo[2].SelectedIndex = 0; } public void SettaCombo(ComboBox[] cboCombo, string strCLCOD) { //taClienti.FillByclCod(dsInterventi.CLIENTI, strCLCOD); dsInterventi.CLIENTIRow rowCliente; rowCliente = dsInterventi.CLIENTI.FindByCLCOD(strCLCOD); if (cboCombo[0].Items.Count > 0) { for (int i = 1; i < cboCombo[0].Items.Count; i++) { if (rowCliente.TPCOD == ((clsCombo)cboCombo[0].Items[i]).strNomeColnna) { cboCombo[0].SelectedIndex = i; break; } } } if (cboCombo[1].Items.Count > 0) { for (int i = 1; i < cboCombo[1].Items.Count; i++) { if (rowCliente.SSCOD == ((clsCombo)cboCombo[1].Items[i]).strNomeColnna) { cboCombo[1].SelectedIndex = i; break; } } } if (cboCombo[2].Items.Count > 0) { for (int i = 1; i < cboCombo[2].Items.Count; i++) { if (rowCliente.PGCOD == ((clsCombo)cboCombo[2].Items[i]).strNomeColnna) { cboCombo[2].SelectedIndex = i; break; } } } } public void PopolaCampi(TextBox[] txtTextbox) { dsInterventi.CLIENTIRow rowCliente; rowCliente = dsInterventi.CLIENTI.FindByCLCOD(txtTextbox[0].Text); txtTextbox[0].Enabled = false; txtTextbox[1].Text = rowCliente.CLRAGS; txtTextbox[2].Text = rowCliente.CLPIVA; txtTextbox[3].Text = rowCliente.CLVIA; txtTextbox[4].Text = rowCliente.CLCAP; txtTextbox[5].Text = rowCliente.CLCOMU; txtTextbox[6].Text = rowCliente.CLPROV; txtTextbox[7].Text = rowCliente.CLTEL1; txtTextbox[8].Text = rowCliente.CLTEL2; txtTextbox[9].Text = rowCliente.CLFAX; txtTextbox[10].Text = rowCliente.CLWWW; txtTextbox[11].Text = rowCliente.CLMAIL; txtTextbox[12].Text = rowCliente.CLPERS; txtTextbox[13].Text = rowCliente.CLPERC; txtTextbox[14].Text = rowCliente.CLPERM; txtTextbox[15].Text = rowCliente.CLNOTE; //DataTableReader dtrUtenti = new DataTableReader(dsInterventi.UTENTI); //dtrUtenti.Read(); } public void PopolaSedi(DataGridView DGV, string strUTCOD) { try { if (DGV.DataSource == null) InizializiaGrid(DGV); taSede.FillByCLCOD(dsInterventi.SEDE, strUTCOD); } catch (Exception e) { throw new System.ArgumentException(e.Message.ToString(), "clsClienti PopolaGrid"); } } } }