private void GOBtn_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; //errorlbl.Text = ""; int[] TPV; try { switch (TPVBox.Text) { case "CAIXES MULTIMEDIA": TPV = new int[] { 1, 3 }; break; case "CAIXES JUGUETTOS/ABACUS": TPV = new int[] { 9, 14 }; break; case "CAIXES ALIMENTACIÓ": TPV = new int[] { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 70, 71, 72 }; break; case "CAIXES MR. BRICOLAGE": TPV = new int[] { 201, 202, 203 }; break; case "CAIXES UEXPRESS": TPV = new int[] { 301, 302, 303, 304 }; break; case "CAIXES CAPRABO": TPV = new int[] { 401, 402, 403, 404, 405, 406, 407, 408, 411, 412, 413, 414 }; break; case "CAIXES DUTY FREE": TPV = new int[] { 5, 6, 7 }; break; case "CAIXES CAFETERIA": TPV = new int[] { 63, 64, 66 }; break; case "CAIXES FRESH": TPV = new int[] { 501, 502, 503, 504 }; break; default: TPV = new int[] { Convert.ToInt32(TPVBox.Text.Substring(0, TPVBox.Text.IndexOf("-") - 1).Trim()) }; break; } ONETPV(TPV); Cursor.Current = Cursors.Default; } catch (Exception) { errorlbl.Text = "Ha de seleccionar OBLIGATORIAMENT el departament, la caixa i la data"; cur_Y = errorlbl.Location.Y; errorlbl.Location = new Point(errorlbl.Location.X, Location.Y - errorlbl.Height); errorlbl.Visible = true; errorlbl.ForeColor = Color.Red; mov_Y = errorlbl.Location.Y; Error_Timer.Interval = 1; Error_Timer.Start(); } }
private void Downloading_DoWork(object sender, DoWorkEventArgs e) { Invoke((MethodInvoker) delegate { if (!(PURCHASE_Date.Value.ToShortDateString() == DateTime.Now.ToShortDateString())) { try { FolderBrowserDialog ofd = new FolderBrowserDialog(); int[] numero; if (ofd.ShowDialog() == DialogResult.OK) { progressBar1.Value = 1; progressBar1.Step = 1; switch (TPVBox.Text) { case "CAIXES MULTIMEDIA": numero = new int[] { 1, 3 }; break; case "CAIXES JUGUETTOS/ABACUS": numero = new int[] { 9, 14 }; break; case "CAIXES ALIMENTACIÓ": numero = new int[] { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 70, 71, 72 }; break; case "CAIXES MR. BRICOLAGE": numero = new int[] { 201, 202, 203 }; break; case "CAIXES UEXPRESS": numero = new int[] { 301, 302, 303, 304 }; break; case "CAIXES CAPRABO": numero = new int[] { 401, 402, 403, 404, 405, 406, 407, 408, 411, 412, 413, 414 }; break; case "CAIXES DUTY FREE": numero = new int[] { 5, 6, 7 }; break; case "CAIXES CAFETERIA": numero = new int[] { 63, 64, 66 }; break; case "CAIXES FRESH": numero = new int[] { 501, 502, 503, 504 }; break; default: numero = new int[] { Convert.ToInt32(TPVBox.Text.Substring(0, TPVBox.Text.IndexOf("-") - 1).Trim()) }; break; } string Path = ofd.SelectedPath; MySqlConnection CNNFDL = new MySqlConnection(ConnectionFDL()); StringBuilder CommandFDL = new StringBuilder(); int count_rows = 0; CNNFDL.Close(); foreach (int nterm in numero) { CommandFDL = new StringBuilder(); CommandFDL.Append("SELECT COUNT(*) FROM tickets where fecha = @fecha and nterm = @nterm order by nterm, nreb, nlinea"); MySqlCommand CMDFDL = new MySqlCommand(CommandFDL.ToString(), CNNFDL); CMDFDL.Parameters.AddWithValue("@fecha", Convert.ToDateTime(PURCHASE_Date.Text).ToString("yyyyMMdd")); CMDFDL.Parameters.AddWithValue("@nterm", new string('0', 4 - nterm.ToString().Length) + nterm.ToString()); CNNFDL.Close(); CNNFDL.Open(); MySqlDataReader FDL = CMDFDL.ExecuteReader(); while (FDL.Read()) { count_rows += Convert.ToInt32(FDL[0]); } } CNNFDL.Close(); progressBar1.Maximum = count_rows; if (File.Exists(Path + @"\" + TPVBox.Text + ".txt")) { if (File.Exists(Path + @"\" + TPVBox.Text + ".txt.old")) { File.Delete(Path + @"\" + TPVBox.Text + ".txt.old"); } File.Move(Path + @"\" + TPVBox.Text + ".txt", Path + @"\" + TPVBox.Text + ".txt.old"); } foreach (int nterm in numero) { CommandFDL = new StringBuilder(); CommandFDL.Append("SELECT * FROM tickets where fecha = @fecha and nterm = @nterm order by nterm, nreb, nlinea"); MySqlCommand CMDFDL = new MySqlCommand(CommandFDL.ToString(), CNNFDL); CMDFDL.Parameters.AddWithValue("@fecha", Convert.ToDateTime(PURCHASE_Date.Text).ToString("yyyyMMdd")); CMDFDL.Parameters.AddWithValue("@nterm", new string('0', 4 - nterm.ToString().Length) + nterm.ToString()); CNNFDL.Close(); CNNFDL.Open(); //TICKETS_LIST.Text = string.Empty; MySqlDataReader FDL = CMDFDL.ExecuteReader(); //int count_rows = Convert.ToInt32(CMDFDL.ExecuteScalar()); while (FDL.Read()) { using (StreamWriter SW = File.AppendText(Path + @"\" + TPVBox.Text + ".txt")) { SW.WriteLine(FDL[0].ToString() + "\t" + FDL[1].ToString() + "\t" + FDL[2].ToString() + "\t" + FDL[3].ToString() + "\t" + Convert.ToDateTime(FDL[4]).ToString("dd/MM/yyyy") + "\t" + FDL[5].ToString() + "\t" + FDL[6].ToString()); } progressBar1.PerformStep(); } //errorlbl.Text = ""; } CNNFDL.Close(); errorlbl.Text = "Descarrega Completada"; cur_Y = errorlbl.Location.Y; errorlbl.Location = new Point(errorlbl.Location.X, Location.Y - errorlbl.Height); errorlbl.Visible = true; errorlbl.ForeColor = Color.Green; mov_Y = errorlbl.Location.Y; Error_Timer.Interval = 1; Error_Timer.Start(); //MessageBox.Show("Descarrega Completada", "Completat", MessageBoxButtons.OK, MessageBoxIcon.Information); Downloadlbl.Visible = false; progressBar1.Visible = false; Process.Start("explorer.exe", Path); } else { Downloadlbl.Visible = false; progressBar1.Visible = false; errorlbl.Text = "Descarrega cancel·lada"; cur_Y = errorlbl.Location.Y; errorlbl.Location = new Point(errorlbl.Location.X, Location.Y - errorlbl.Height); errorlbl.Visible = true; errorlbl.ForeColor = Color.Red; mov_Y = errorlbl.Location.Y; Error_Timer.Interval = 1; Error_Timer.Start(); //MessageBox.Show(""); return; } } catch { Downloadlbl.Visible = false; progressBar1.Visible = false; errorlbl.Text = "Ha de seleccionar OBLIGATORIAMENT el departament, la caixa i la data"; cur_Y = errorlbl.Location.Y; errorlbl.Location = new Point(errorlbl.Location.X, Location.Y - errorlbl.Height); errorlbl.Visible = true; errorlbl.ForeColor = Color.Red; mov_Y = errorlbl.Location.Y; Error_Timer.Interval = 1; Error_Timer.Start(); //MessageBox.Show("Empleni els camps obligatoris", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { errorlbl.Text = "No es pot descarregar el diari d'avui"; cur_Y = errorlbl.Location.Y; errorlbl.Location = new Point(errorlbl.Location.X, Location.Y - errorlbl.Height); errorlbl.Visible = true; errorlbl.ForeColor = Color.Red; mov_Y = errorlbl.Location.Y; Error_Timer.Interval = 1; Error_Timer.Start(); //MessageBox.Show("No es pot descarregar el diari d'avui", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }
public void ONETPV(int[] number) { try { DataTable dataTable = new DataTable(); DataRow rowTable = dataTable.NewRow(); TICKETS_LIST.Text = ""; string control = ""; decimal amount = 0; rowTable.Delete(); dataTable.Columns.Add("Caixa"); dataTable.Columns.Add("Núm Tiquet"); dataTable.Columns.Add("Hora"); dataTable.Columns.Add("Forma de pagament"); dataTable.Columns.Add("Import", typeof(decimal)); string Group_num = string.Empty; int n_caixes = 0; foreach (int Num in number) { if (Group_num != string.Empty) { Group_num += ","; n_caixes++; } Group_num += "'" + new string('0', 4 - Num.ToString().Length) + Num.ToString() + "'"; } MySqlConnection connectionTable = new MySqlConnection(ConnectionAXCAIXES()); StringBuilder CommandTable = new StringBuilder(); CommandTable.Append("SELECT nterm, nreb, hora, typlin, total FROM datacap where fecha = @fecha and nterm"); if (n_caixes == 0) { if (CLIENT_CODE.Text == "") { CommandTable.Append(" = " + Group_num); } else { CommandTable.Append(" = " + Group_num + " and cliente like @clientcode"); } } else { if (CLIENT_CODE.Text == "") { CommandTable.Append(" IN(" + Group_num + ")"); } else { CommandTable.Append(" IN(" + Group_num + ") and cliente like @clientcode"); } } if (In_Out.Checked) { CommandTable.Append(" and typtra IN('ENT','REC')"); } CommandTable.Append(" and typlin like 'FE%' order by tienda, nterm, nreb, nlinea"); MySqlCommand CMD = new MySqlCommand(CommandTable.ToString(), connectionTable); //CMD.Parameters.Add("@nterm",MySqlDbType.VarChar); CMD.Parameters.AddWithValue("@fecha", Convert.ToDateTime(PURCHASE_Date.Text).ToString("yyyyMMdd")); //CMD.Parameters.AddWithValue("@nterm", Group_num); CMD.Parameters.AddWithValue("@clientcode", "%" + CLIENT_CODE.Text + "%"); connectionTable.Close(); connectionTable.Open(); MySqlDataReader TABLE = CMD.ExecuteReader(); while (TABLE.Read()) { if (TABLE[1].ToString() == control) { rowTable.SetField(4, amount + Convert.ToDecimal(TABLE[4])); } else { rowTable = dataTable.NewRow(); rowTable[0] = TABLE[0].ToString(); rowTable[1] = TABLE[1].ToString(); control = rowTable[1].ToString(); rowTable[2] = TABLE[2].ToString(); rowTable[3] = GetPayment_Name(TABLE[3].ToString()); rowTable[4] = Convert.ToDecimal(TABLE[4].ToString()); amount = Convert.ToDecimal(rowTable[4]); dataTable.Rows.Add(rowTable); } } TABLE.Close(); connectionTable.Close(); TICKET_TABLE.DataSource = dataTable; TICKET_TABLE.Font = new Font("Century Gothic", 10F); DataGridViewCellStyle DGVCS = new DataGridViewCellStyle(); DGVCS.Font = new Font("Century Gothic", 8F); DGVCS.Alignment = DataGridViewContentAlignment.MiddleCenter; TICKET_TABLE.Columns[0].HeaderCell.Style = DGVCS; TICKET_TABLE.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; TICKET_TABLE.Columns[1].HeaderCell.Style = DGVCS; TICKET_TABLE.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; TICKET_TABLE.Columns[2].HeaderCell.Style = DGVCS; TICKET_TABLE.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; TICKET_TABLE.Columns[3].HeaderCell.Style = DGVCS; TICKET_TABLE.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; TICKET_TABLE.Columns[4].HeaderCell.Style = DGVCS; TICKET_TABLE.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; TICKET_TABLE.AutoSize = true; TICKET_TABLE.Width = TICKET_TABLE.Columns[0].Width + TICKET_TABLE.Columns[1].Width + TICKET_TABLE.Columns[2].Width + TICKET_TABLE.Columns[3].Width + TICKET_TABLE.Columns[4].Width; TICKETS_LIST.Location = new Point(TICKET_TABLE.Location.X + TICKET_TABLE.Width + 22, TICKETS_LIST.Location.Y); TICKETS_LIST.Width = Width - TICKET_TABLE.Location.X - TICKET_TABLE.Width - 22 - TICKET_TABLE.Location.X; Group_num = string.Empty; n_caixes = 0; foreach (int Num in number) { if (Group_num != string.Empty) { Group_num += ","; n_caixes++; } Group_num += "'" + Num.ToString() + "'"; } MySqlConnection connectionIP = new MySqlConnection(Connection()); StringBuilder CommandIP = new StringBuilder(); if (n_caixes == 0) { CommandIP.Append("SELECT LOC, LOC2 FROM `departaments-cca`.cca where DSC = '" + DPTBox.Text + "' and TPV = " + Group_num + ";"); } else { CommandIP.Append("SELECT LOC, LOC2 FROM `departaments-cca`.cca where DSC = '" + DPTBox.Text + "' and TPV IN(" + Group_num + ");"); } MySqlCommand CMDIP = new MySqlCommand(CommandIP.ToString(), connectionIP); connectionIP.Close(); connectionIP.Open(); MySqlDataReader IP = CMDIP.ExecuteReader(); List <string> FileIP = new List <string>(); while (IP.Read()) { if (PURCHASE_Date.Value.ToShortDateString() == DateTime.Now.ToShortDateString()) { FileIP.Add(@"\\serverpos\GEINSA\GnxServer\" + IP[1].ToString().Trim() + @"\"); } } if (FileIP.Count == 0) { goto siguiente; } foreach (string fl in FileIP) { DirectoryInfo dir = new DirectoryInfo(fl); foreach (var file in dir.GetFiles()) { if (file.CreationTime.Date.ToString().Substring(0, 10) == PURCHASE_Date.Text.ToString().Substring(0, 10) && file.Name.Contains("journal")) { if (File.Exists(Directory.GetCurrentDirectory() + @"\journal-copy.txt")) { File.Delete(Directory.GetCurrentDirectory() + @"\journal-copy.txt"); } File.Copy(fl + file.Name, Directory.GetCurrentDirectory() + @"\journal-copy.txt"); using (StreamReader sr = new StreamReader(Directory.GetCurrentDirectory() + @"\journal-copy.txt", Encoding.Default)) { TICKETS_LIST.Text += sr.ReadToEnd(); } } } } siguiente :; } catch (Exception) { errorlbl.Text = "ERROR! Envieu un correu a Fran d'informatica"; cur_Y = errorlbl.Location.Y; errorlbl.Location = new Point(errorlbl.Location.X, Location.Y - errorlbl.Height); errorlbl.Visible = true; errorlbl.ForeColor = Color.Red; mov_Y = errorlbl.Location.Y; Error_Timer.Interval = 1; Error_Timer.Start(); } }