Exemplo n.º 1
0
        private void InsertScaleInfo(string text, Bascula bs)
        {
            try
            {
                BoletaEntidad nuevaBoleta = null;

                // Conexion
                string localConnectionString = "Data Source={0}; Initial Catalog={1}; {2}";
                string user = Properties.Settings.Default.Usuario;
                string pass = Properties.Settings.Default.Contrasena;
                string isWA = Properties.Settings.Default.IsAutenticacionWindows;
                string strWindowsAutentication = (isWA == "Unchecked") ? "User ID=" + user + "; Password="******";" : string.Empty;

                localConnectionString = string.Format(localConnectionString,
                                        Properties.Settings.Default.Servidor, Properties.Settings.Default.BD, strWindowsAutentication);

                SqlConnection localConnection = new SqlConnection(localConnectionString);
                localConnection.Open();

                if (localConnection.State == ConnectionState.Open)
                {
                    string gross = GetValorTipoPeso(bs.Marca, MyResource.Gross, text); //text.Substring(13, 7);
                    string tare = GetValorTipoPeso(bs.Marca, MyResource.Tare, text); //text.Substring(37, 6);
                    string net = GetValorTipoPeso(bs.Marca, MyResource.Net, text); //text.Substring(61, 6);
                    decimal grossDecimal = Convert.ToDecimal(gross);
                    decimal tareDecimal = Convert.ToDecimal(tare);
                    decimal netDecimal = Convert.ToDecimal(net);
                    string blt_Serie = bs.Blt_Proceso + bs.Blt_Periodo + bs.Blt_Bodega;
                    int correlativoBoleta = GetNumeroBoleta(blt_Serie);

                    // Para registrarlo en el GridView
                    nuevaBoleta = new BoletaEntidad()
                    {
                        Bascula = bs.Descripcion,
                        DireccionIp = bs.DireccionIp,
                        Fecha = DateTime.Now,
                        NumeroBoleta = correlativoBoleta,
                        SerieBoleta = blt_Serie,
                        Bruto = grossDecimal,
                        Tara = tareDecimal,
                        Neto = netDecimal
                    };

                    if (correlativoBoleta > 0)
                    {
                        string query = @" INSERT INTO SipBecamo_Boletas (Blt_Proceso, Blt_Periodo, Blt_Bodega, Blt_Serie, Blt_Numero, Blt_Fecha,
                                                                                Blt_Orden, Blt_Trilla, Blt_Procede, Blt_Bloque, Blt_Calidad,
                                                                                    Blt_Calidad_Interna, Blt_Bruto, Blt_Tara, Blt_Neto)
                                          VALUES('{0}', '{1}', '{2}', '{3}', {4}, '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}',
                                                                                                                    {12}, {13}, {14}) ";
                        query = string.Format(query, bs.Blt_Proceso, bs.Blt_Periodo, bs.Blt_Bodega, blt_Serie, correlativoBoleta, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                    bs.Blt_Orden, "-----", bs.Blt_Procede, bs.Blt_Bloque, bs.Blt_Calidad, bs.Blt_Calidad_Interna,
                                                     Convert.ToDecimal(gross), Convert.ToDecimal(tare), Convert.ToDecimal(net));

                        SqlCommand command = new SqlCommand(query, localConnection);
                        command.ExecuteNonQuery();
                    }

                    // Inserto en el GridView
                    //lock (this)
                    //{
                    //    gridControl1.BeginInvoke(new MethodInvoker(delegate()
                    //    {
                    //        DataRow newRow = DsBasculas.Tables["TblMonitor"].NewRow();
                    //        newRow["BASCULA"] = bs.Descripcion;
                    //        newRow["DIRECCION_IP"] = bs.DireccionIp;
                    //        newRow["FECHA"] = DateTime.Now;
                    //        newRow["NUMERO_BOLETA"] = correlativoBoleta;
                    //        newRow["SERIE_BOLETA"] = blt_Serie;
                    //        newRow["BRUTO"] = grossDecimal;
                    //        newRow["TARA"] = tareDecimal;
                    //        newRow["NETO"] = netDecimal;
                    //        DsBasculas.Tables["TblMonitor"].Rows.Add(newRow);
                    //    }));
                    //}
                }

                localConnection.Close();

                // Inserto en el GridView
                lock (this)
                {
                    gridControl1.BeginInvoke(new MethodInvoker(delegate()
                    {
                        gridDataList.Add(nuevaBoleta);
                        gridControl1.DataSource = gridDataList;
                    }));
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message + "\n" + ex.StackTrace, "Error en funcion InsertScaleInfo()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void InsertPingResult(Bascula bs, string pingResult)
        {
            try
            {
                // Conexion
                BoletaEntidad nuevaBoleta = null;
                string localConnectionString = "Data Source={0}; Initial Catalog={1}; {2}";
                string user = Properties.Settings.Default.Usuario;
                string pass = Properties.Settings.Default.Contrasena;
                string isWA = Properties.Settings.Default.IsAutenticacionWindows;
                string strWindowsAutentication = (isWA == "Unchecked") ? "User ID=" + user + "; Password="******";" : string.Empty;

                localConnectionString = string.Format(localConnectionString,
                                        Properties.Settings.Default.Servidor, Properties.Settings.Default.BD, strWindowsAutentication);

                SqlConnection localConnection = new SqlConnection(localConnectionString);
                localConnection.Open();

                if (localConnection.State == ConnectionState.Open)
                {

                    int correlativoBoleta = GetNumeroBoleta("P1112B5");

                    nuevaBoleta = new BoletaEntidad()
                    {
                        Bascula = bs.Descripcion,
                        DireccionIp = bs.DireccionIp,
                        Fecha = DateTime.Now,
                        NumeroBoleta = correlativoBoleta,
                        SerieBoleta = "P1112B5",
                        Bruto = 100,
                        Tara = 11,
                        Neto = 89
                    };

                    if (correlativoBoleta > 0)
                    {
                        //SetCulture();
                        string query = @" INSERT INTO SipBecamo_Boletas (Blt_Proceso, Blt_Periodo, Blt_Bodega, Blt_Serie, Blt_Numero, Blt_Fecha,
                                                                                Blt_Orden, Blt_Trilla, Blt_Procede, Blt_Bloque, Blt_Calidad,
                                                                                    Blt_Calidad_Interna, Blt_Bruto, Blt_Tara, Blt_Neto)
                                          VALUES('{0}', '{1}', '{2}', '{3}', {4}, '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}',
                                                                                                                    {12}, {13}, {14}) ";
                        query = string.Format(query, bs.Blt_Proceso, bs.Blt_Periodo, bs.Blt_Bodega, "P1112B5", correlativoBoleta, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                    bs.Blt_Orden, "-----", pingResult.Trim(), bs.Blt_Bloque, bs.Blt_Calidad, bs.Blt_Calidad_Interna,
                                                     150, 11, 139);

                        SqlCommand command = new SqlCommand(query, localConnection);
                        command.ExecuteNonQuery();
                    }
                }

                localConnection.Close();

                // Inserto en el GridView
                lock (this)
                {
                    gridControl1.BeginInvoke(new MethodInvoker(delegate()
                    {
                        //SetCulture();
                        gridDataList.Add(nuevaBoleta);
                        gridControl1.DataSource = gridDataList;
                    }));
                }

                //lock (this)
                //{
                //    gridControl1.BeginInvoke(new MethodInvoker(delegate()
                //    {
                //        // Para registrarlo en el GridView
                //        DataRow newRow = DsBasculas.Tables["TblMonitor"].NewRow();
                //        newRow["BASCULA"] = bs.Descripcion;
                //        newRow["DIRECCION_IP"] = bs.DireccionIp;
                //        newRow["FECHA"] = DateTime.Now;
                //        newRow["SERIE_BOLETA"] = pingResult;
                //        newRow["BRUTO"] = Thread.CurrentThread.ManagedThreadId;
                //        DsBasculas.Tables["TblMonitor"].Rows.Add(newRow);
                //    }));

                //}
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message + "\n" + ex.StackTrace, "Error en funcion InsertPingResult()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }