private void executeSp(string path, string numArchivos)
        {
            ConectionDB con = new ConectionDB();

            try
            {
                con.SqlConnect();

                SqlCommand cmd = new SqlCommand();
                //CONFIG OF THE COMMAND
                cmd.Connection  = con.GetConnection();
                cmd.CommandText = Sp;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@RUTA", path);
                cmd.Parameters.AddWithValue("@NUMARCHIVOS", numArchivos);

                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();

                MessageBox.Show("Se ejecutó con exito.", "Ejecución correcta", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en la conexion o ejecucion: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            con.SqlCloseConection();
        }
示例#2
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            string      fileName = txtFileName.Text;
            ConectionDB con      = new ConectionDB();

            computerName = con.GetComputerName();
            try
            {
                con.SqlConnect();//ABRIR CONEXION

                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = con.GetConnection();
                cmd.CommandText = "sp_generar_tmov";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@NOMBRE_DEL_EQUIPO", computerName);
                cmd.Parameters.AddWithValue("@RUTA", folderPath);
                cmd.Parameters.AddWithValue("@NOMBRE", fileName);


                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();
                txtFileName.Clear();
                MessageBox.Show("Se ejecutó con exito.", "Ejecución correcta", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en la conexion o ejecucion: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            con.SqlCloseConection();//CERRAR CONEXION
        }
示例#3
0
        private void createPrintFile()
        {
            conection = new ConectionDB();
            conection.SqlConnect();

            try
            {
                cmd             = new SqlCommand();
                cmd.Connection  = conection.GetConnection();
                cmd.CommandText = "sp_generar_txt_impresion";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@ruta", path);
                cmd.Parameters.AddWithValue("@nombre", fileName);
                cmd.Parameters.AddWithValue("@nombre_del_equipo", machineName);

                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();
            }
            catch (Exception err)
            {
                MessageBox.Show("No se pudo crear el archivo de texto con los datos del comprobante, " + err.Message);
            }

            conection.SqlCloseConection();
        }
示例#4
0
        private void btnSendProjection_Click(object sender, EventArgs e)
        {
            string parameter = txtProjection.Text;

            if (parameter != "")
            {
                ConectionDB con = new ConectionDB();
                try
                {
                    con.SqlConnect();

                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection  = con.GetConnection();
                    cmd.CommandText = "sp_aplica_proyeccion";
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@PROYECCION", parameter);
                    cmd.ExecuteNonQuery();

                    cmd.Parameters.Clear();
                    txtProjection.Clear();
                    MessageBox.Show("Se ejecutó con exito.", "Ejecución correcta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    double LabelX = (this.Location.X) * 0.8;
                    double LabelY = (this.Location.Y) * 0.2;
                    Label  err    = new Label();
                    err.Text      = "No se pudo ejecutar correctamente: " + ex.Message;
                    err.Visible   = true;
                    err.ForeColor = Color.Red;
                    err.Location  = new Point(Convert.ToInt32(LabelX), Convert.ToInt32(LabelY));
                }


                con.SqlCloseConection();
            }
            else
            {
                MessageBox.Show("El campo es obligatorio", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#5
0
        private void getPrinterName()
        {
            conn = new ConectionDB();
            try
            {
                conn.SqlConnect();
                cmd             = new SqlCommand();
                cmd.Connection  = conn.GetConnection();
                cmd.CommandText = selectPrint;
                cmd.CommandType = CommandType.Text;

                SqlDataReader reader = cmd.ExecuteReader();
            }
            catch (Exception err)
            {
                MessageBox.Show("Error: " + err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            conn.SqlCloseConection();
        }
示例#6
0
        private void insertPrinterName()
        {
            conn = new ConectionDB();
            try
            {
                conn.SqlConnect();
                cmd             = new SqlCommand();
                cmd.Connection  = conn.GetConnection();
                cmd.CommandText = "DELETE FROM " + tblName + "\nINSERT INTO " + tblName + " VALUES ('" + Printers.Text + "')";
                cmd.CommandType = CommandType.Text;

                var reader = cmd.ExecuteReader();
            }
            catch (Exception err)
            {
                MessageBox.Show("Error: " + err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            conn.SqlCloseConection();
        }
示例#7
0
        private void printTicket(object sender, EventArgs e)
        {
            //step 0 obtención de los datos

            //****DATOS DE LA FECHA****
            int    year       = initialDatePicker.Value.Year;
            int    month      = initialDatePicker.Value.Month;
            int    day        = initialDatePicker.Value.Day;
            string ticketDate = year.ToString() + month.ToString() + day.ToString(); //DATOS CONCATENADOS PARA EL PARAMETRO

            //****CONSECUTIVO DEL COMPROBANTE****
            string idTicket = txtIdTicket.Text;

            //****HORA DEL CIERRE DEL COMPROBANTE****
            string closeTime = cmbCloseTime.Text;

            //step 1 ejecutar sp del informe
            conection = new ConectionDB();
            conection.SqlConnect();

            try
            {
                cmd             = new SqlCommand();
                cmd.Connection  = conection.GetConnection();
                cmd.CommandText = "SP_IMP_COMP_DIARIO";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@NUMLIBRO", idTicket);
                cmd.Parameters.AddWithValue("@FECHACOMPDIARIO", ticketDate);
                cmd.Parameters.AddWithValue("@FECHACIERREDIARIO", ticketDate);
                cmd.Parameters.AddWithValue("@HORACIERREDIARIO", closeTime);

                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();

                conection.SqlCloseConection();
            }
            catch (Exception err)
            {
                MessageBox.Show("No se pudo generar el reporte: " + err.Message);
            }

            //step 2 Crear el archivo
            createPrintFile();



            //step 3 LEER EL ARCHIVO E IMPRIMIRLO
            string batName = "imprimir.bat";

            try
            {
                string script = @"print /D:LPT1 C:\Users\Public\Documents\Tickt.txt";

                File.WriteAllText(path + batName, script);

                Process.Start(path + batName).WaitForExit();
            }
            catch (Exception err)
            {
                MessageBox.Show("Error: " + err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }



            //step 4 LO ELIMINA DESPUES DE IMPRIMIRLO
            File.Delete(path + fileName + ".txt");
            File.Delete(path + batName);
        }
示例#8
0
        private void printTicket(object sender, EventArgs e)
        {
            //step 0 obtención de los datos
            string initConsec = txtInitConsec.Text;

            string finConsec = txtFinConcec.Text;

            string actualTime;

            if (txtTime.Text == "")
            {
                actualTime = new DateTime().Hour + ":" + new DateTime().Minute + ":" + new DateTime().Second;
            }
            else
            {
                actualTime = txtTime.Text;
            }


            string docType = txtDoc.Text;

            //step 1 ejecutar sp de la factura
            conection = new ConectionDB();
            conection.SqlConnect();

            try
            {
                cmd             = new SqlCommand();
                cmd.Connection  = conection.GetConnection();
                cmd.CommandText = cmdText;
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@TIPODOC_FACT", docType);
                cmd.Parameters.AddWithValue("@NUMERO_INI", initConsec);
                cmd.Parameters.AddWithValue("@NUMERO_FIN", finConsec);
                cmd.Parameters.AddWithValue("@HORA", actualTime);

                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();

                conection.SqlCloseConection();
            }
            catch (Exception err)
            {
                MessageBox.Show("No se pudo generar la factura: " + err.Message);
            }

            //step 2 Crear el archivo
            createPrintFile();

            //step 3 LEER EL ARCHIVO E IMPRIMIRLO
            string batName = "imprimir.bat";

            try
            {
                string script = @"print /D:LPT1 C:\Users\Public\Documents\Tickt.txt";

                File.WriteAllText(path + batName, script);

                Process.Start(path + batName).WaitForExit();
            }
            catch (Exception err)
            {
                MessageBox.Show("Error: " + err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }



            //step 4 LO ELIMINA DESPUES DE IMPRIMIRLO
            File.Delete(path + fileName + ".txt");
            File.Delete(path + batName);
        }