Esempio n. 1
0
    protected void farm_grid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Delete_farm")
        {
            using (SqlConnection Conn = new SqlConnection())
            {
                Conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBpath"].ConnectionString;
                SqlCommand Comm = new SqlCommand();
                Comm.Connection = Conn;
                Conn.Open();

                try
                {
                    Comm.CommandText = "DELETE FROM FARM WHERE ID=@ID";
                    Comm.Parameters.Add("@ID", SqlDbType.Int);
                    Comm.Parameters["@ID"].Value = Farm_grid.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString();

                    Comm.ExecuteNonQuery();
                    Farm_grid.DataBind();

                    Error_lb.ForeColor = Color.Green;
                    Error_lb.Text      = "Data deleted";
                }
                catch (SqlException E)
                {
                    Error_lb.Text = E.Message;
                    return;
                }
            }
        }
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataSource8.ConnectionString = ConfigurationManager.ConnectionStrings["DBpath"].ConnectionString;
        SqlDataSource8.SelectCommand    = "SELECT F.ID AS ID, F.QUANTITY AS QUANTITY, F.RATIONGROUP AS RATIONGROUP, AG.NAME AS BREED, AW.NAME AS WEIGHT, AA.NAME AS AGE, T.NAME AS TARGET FROM FARM F, ANIMALS A, ANIMALGROUP AG, ANIMALWEIGHT AW, ANIMALAGE AA, TARGETINCREASE TI,TARGETCATEGORY T WHERE F.ANIMALSID=A.ID AND A.ANIMALWEIGHTID=AW.ID AND A.ANIMALAGEID=AA.ID AND F.TARGETINCREASEID=TI.ID AND AG.ID=ANIMALGROUPID AND TI.TARGETCATEGORYID=T.ID";
        SqlDataSource5.ConnectionString = ConfigurationManager.ConnectionStrings["DBpath"].ConnectionString;
        SqlDataSource5.SelectCommand    = "SELECT A.ID AS ID, 'ANIMAL: '+ AG.NAME + ' AGE: ' + AA.NAME + ' WEIGHT: ' + AW.NAME AS NAME FROM ANIMALS A, ANIMALAGE AA, ANIMALWEIGHT AW, ANIMALGROUP AG WHERE A.ANIMALGROUPID=AG.ID AND A.ANIMALWEIGHTID=AW.ID AND A.ANIMALAGEID=AA.ID";

        SqlDataSource7.SelectCommand = "select t.name +' - '+ ti.name as name, ti.id as id from targetcategory t, targetincrease ti, ENERGYCHANGE EC WHERE TI.ID=EC.TARGETINCREASEID and ti.targetcategoryid=t.id";

        SqlDataSource1.SelectCommand = "SELECT FEED_STOCK.FEEDID, FEED_STOCK.WEIGHT, FEED.NAME AS FEEDNAME, FEED_STOCK.ID, FEED.ID AS FEED_ID FROM FEED_STOCK INNER JOIN FEED ON FEED_STOCK.FEEDID = FEED.ID AND USER_ID=@USER_ID";
        SqlDataSource1.SelectParameters.Clear();
        SqlDataSource1.SelectParameters.Add("USER_ID", TypeCode.Int32, USERID());



        Farm_grid.DataBind();
    }
Esempio n. 3
0
    protected void add_btn1_Click(object sender, EventArgs e)
    {
        Error_lb.Visible = true;
        Error_lb.Text    = "Popka durak";
        using (SqlConnection Conn = new SqlConnection())
        {
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBpath"].ConnectionString;
            SqlCommand Comm = new SqlCommand();
            Comm.Connection = Conn;
            Conn.Open();
            try
            {
                /*Comm.CommandText = @"INSERT INTO FARM (ANIMALSID, QUANTITY, RATIONGROUP, USER_ID) VALUES (@ANIMALSID, @QUANTITY, @RATIONGROUP, 2); INSERT INTO ANIMALS (ANIMALWEIGHTID, ANIMALAGEID) VALUES (@ANIMALWEIGHTID, @ANIMALAGEID); INSERT INTO TARGETCATEGORY (ID) VALUES (@TARGETCATEGORYID)";
                 * Comm.Parameters.Add("@RATIONGROUP", SqlDbType.NVarChar);
                 * Comm.Parameters["@RATIONGROUP"].Value = ration_edt.Text.Trim();
                 * Comm.Parameters.Add("@ANIMALSID", SqlDbType.Int);
                 * Comm.Parameters["@ANIMALSID"].Value = Breed_ddl.SelectedValue;
                 * Comm.Parameters.Add("@ANIMALAGEID", SqlDbType.Int);
                 * Comm.Parameters["@ANIMALAGEID"].Value = Age_ddl.SelectedValue;
                 * Comm.Parameters.Add("@ANIMALWEIGHTID", SqlDbType.Int);
                 * Comm.Parameters["@ANIMALWEIGHTID"].Value = Weight_ddl.SelectedValue;
                 * Comm.Parameters.Add("@TARGETCATEGORYID", SqlDbType.Int);
                 * Comm.Parameters["@TARGETCATEGORYID"].Value = Grow_ddl.SelectedValue;
                 * Comm.Parameters.Add("@QUANTITY", SqlDbType.Int);
                 * Comm.Parameters["@QUANTITY"].Value = Quantity_edt.Text.Trim();
                 *
                 * try
                 * {
                 *
                 *  Comm.ExecuteNonQuery();
                 *  stock_grid.DataBind();
                 * }
                 *
                 * catch (SqlException E)
                 * {
                 *  Label19.Text = E.Message;
                 * }
                 */

                //Begin Выбор ID животного с выбранными параметрами



                //End выбор ID животного

                //Внесение данных в базу

                Comm.CommandText = @"INSERT INTO FARM (ANIMALSID, QUANTITY, RATIONGROUP, USER_ID, TARGETINCREASEID) VALUES (@ANIMALSID,@QUANTITY, @RATIONGROUP, @USERID, @TARGETINCREASEID)";
                Comm.Parameters.Add("@RATIONGROUP", SqlDbType.NVarChar);
                Comm.Parameters["@RATIONGROUP"].Value = ration_edt.Text.Trim();
                Comm.Parameters.Add("@ANIMALSID", SqlDbType.Int);
                Comm.Parameters["@ANIMALSID"].Value = animal_ddl.SelectedValue;
                Comm.Parameters.Add("@TARGETINCREASEID", SqlDbType.Int);
                Comm.Parameters["@TARGETINCREASEID"].Value = Grow_ddl.SelectedValue;
                Comm.Parameters.Add("@QUANTITY", SqlDbType.Int);
                Comm.Parameters["@QUANTITY"].Value = Quantity_edt.Text.Trim();
                Comm.Parameters.Add("@USERID", SqlDbType.Int);
                Comm.Parameters["@USERID"].Value = USERID();



                Comm.ExecuteNonQuery();
                Farm_grid.DataBind();



                ration_edt.Text = "";

                animal_ddl.SelectedIndex = 0;

                Grow_ddl.SelectedIndex = 0;
                Quantity_edt.Text      = "";


                Error_lb.ForeColor = Color.Green;
                Error_lb.Text      = "Data added successfully";
            }
            catch (SqlException E)
            {
                Error_lb.Text = E.Message;
                return;
            }
        }
    }