Esempio n. 1
0
        public int InsertInventario(Inventario inventario)
        {
            int Valor;

            #region InsertString
            string Insert;
            if (inventario.EndTime.Year == 1)
            {
                Insert = "Insert INTO LO_inventory VALUES (@Nombre,@Descripcion,@CreacionDate,@InicioDate,NULL,@KOSU,@Status)";
            }
            else
            {
                Insert = "Insert INTO LO_inventory VALUES (@Nombre,@Descripcion,@CreacionDate,@InicioDate,@TerminoDate,@KOSU,@Status)";
            }

            #endregion

            try
            {
                ConnPlabal.Open();
                cmdPlabal = new SqlCommand(Insert, ConnPlabal);
                cmdPlabal.Parameters.AddWithValue("@Nombre", inventario.Name);
                cmdPlabal.Parameters.AddWithValue("@Descripcion", inventario.Description);
                cmdPlabal.Parameters.AddWithValue("@CreacionDate", inventario.DateCreate);
                cmdPlabal.Parameters.AddWithValue("@InicioDate", inventario.StartTime);
                if (inventario.EndTime.Year == 1)
                {
                }
                else
                {
                    cmdPlabal.Parameters.AddWithValue("@TerminoDate", inventario.EndTime);
                }

                cmdPlabal.Parameters.AddWithValue("@KOSU", inventario.KOSU);
                cmdPlabal.Parameters.AddWithValue("@Status", inventario.Status);


                cmdPlabal.ExecuteNonQuery();
                ConnPlabal.Close();


                string Select = "SELECT Id FROM LO_inventory WHERE Nombre=@Nombre AND Status=@Status AND CreacionDate=@CreacionDate AND KOSU=@KOSU";
                ConnPlabal.Open();
                cmdPlabal = new SqlCommand(Select, ConnPlabal);
                cmdPlabal.Parameters.AddWithValue("@Nombre", inventario.Name);
                cmdPlabal.Parameters.AddWithValue("@CreacionDate", inventario.DateCreate);
                cmdPlabal.Parameters.AddWithValue("@KOSU", inventario.KOSU);
                cmdPlabal.Parameters.AddWithValue("@Status", inventario.Status);
                drPlabal = cmdPlabal.ExecuteReader();
                drPlabal.Read();

                if (drPlabal.HasRows)
                {
                    Valor = Convert.ToInt32(drPlabal["Id"].ToString());
                }
                else
                {
                    Valor = 0;
                }

                drPlabal.Close();
                ConnPlabal.Close();
            }
            catch (Exception EX)
            {
                Valor = 0;
            }


            return(Valor);
        }