Beispiel #1
0
    protected void filldropdownlist()
    {
        if (sqlcon.State == ConnectionState.Closed)
        {
            sqlcon.Open();
        }
        //for product dropdown

        string productquery = "SELECT ProductId,ProductName FROM Product";

        cmd = new SqlCommand(productquery, sqlcon);
        da  = new SqlDataAdapter(cmd);
        ds  = new DataSet();
        da.Fill(ds, "product");
        DropDownProduct.DataSource     = ds.Tables["product"];
        DropDownProduct.DataTextField  = "ProductName";
        DropDownProduct.DataValueField = "ProductId";
        DropDownProduct.DataBind();

        //for supplier dropdownlist

        string supplierquery = "SELECT SupplierId,CompanyName FROM Supplier";

        cmd = new SqlCommand(supplierquery, sqlcon);
        da  = new SqlDataAdapter(cmd);
        ds  = new DataSet();
        da.Fill(ds, "supplier");
        DropDownSupplier.DataSource     = ds.Tables["supplier"];
        DropDownSupplier.DataTextField  = "CompanyName";
        DropDownSupplier.DataValueField = "SupplierId";
        DropDownSupplier.DataBind();

        sqlcon.Close();
    }
Beispiel #2
0
    public void clear()
    {
        hfPurchaseId.Value = "";
        txtQuantity.Text   = txtOthers.Text = "";
        DropDownProduct.ClearSelection();
        DropDownSupplier.ClearSelection();

        lblerrormessage.Text = lblsuccessmassage.Text = "";
        btnsave.Text         = "Save";
        btndelete.Enabled    = true;
    }
Beispiel #3
0
    protected void btndelete_Click(object sender, EventArgs e)
    {
        if (sqlcon.State == ConnectionState.Closed)
        {
            sqlcon.Open();
        }
        SqlCommand cmd = new SqlCommand("PurchaseDeleteById", sqlcon);

        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@PurchaseId", Convert.ToInt32(hfPurchaseId.Value));
        cmd.ExecuteNonQuery();
        sqlcon.Close();
        hfPurchaseId.Value = "";
        txtQuantity.Text   = txtOthers.Text = "";
        DropDownProduct.ClearSelection();
        DropDownSupplier.ClearSelection();
        FillGridView();
        lblsuccessmassage.Text = ("Delete Successfully!");
    }
Beispiel #4
0
 //Refined Supplier Data Bind
 protected void SupplierBind(object sender, EventArgs e)
 {
     using (var conn = new MySqlConnection(strcon))
     {
         conn.Open();
         string Query = "";
         if ((DropDownCategory.SelectedIndex != 0 && DropDownSubCategory.SelectedIndex != 0) || DropDownSubCategory.SelectedIndex != 0)
         {
             Query = "SELECT DISTINCT Supplier.* FROM Supplier INNER JOIN SubCatSupplier ON Supplier.SupId = SubCatSupplier.SupId INNER JOIN SubCategory ON SubCatSupplier.SubCatId = SubCategory.SubCatId WHERE SubCatSupplier.SubCatId ='" + DropDownSubCategory.SelectedValue + "' AND SubCatSupplier.SupId = Supplier.SupId";
         }
         else if (DropDownCategory.SelectedIndex != 0)
         {
             Query = "SELECT DISTINCT Supplier.* FROM Supplier INNER JOIN SubCatSupplier ON Supplier.SupId = SubCatSupplier.SupId INNER JOIN SubCategory ON SubCatSupplier.SubCatId = SubCategory.SubCatId WHERE SubCatSupplier.SubCatId IN (SELECT SubCatId FROM SubCategory WHERE CatId = '" + DropDownCategory.SelectedValue + "') AND SubCatSupplier.SupId = Supplier.SupId";
         }
         else
         {
             Query = "SELECT DISTINCT Supplier.SupId, Supplier.SName FROM Supplier INNER JOIN SubCatSupplier ON Supplier.SupId = SubCatSupplier.SupId INNER JOIN SubCategory ON SubCatSupplier.SubCatId = SubCategory.SubCatId";
         }
         using (var cmd = new MySqlCommand(Query, conn))
         {
             using (var reader = cmd.ExecuteReader())
             {
                 if (reader.HasRows)
                 {
                     DropDownSupplier.DataSource     = reader;
                     DropDownSupplier.DataValueField = "SupId";
                     DropDownSupplier.DataTextField  = "SName";
                     DropDownSupplier.DataBind();
                     DropDownSupplier.Items.Insert(0, new ListItem("--- Choose One ---", "NA"));
                 }
                 else
                 {
                     DropDownSupplier.Items.Clear();
                     DropDownSupplier.Items.Insert(0, new ListItem("--- No Suppliers ---", "NA"));
                 }
             }
         }
     }
 }
Beispiel #5
0
    protected void btnsave_Click(object sender, EventArgs e)
    {
        //Console.Write(DropDownProduct.SelectedValue);
        //Console.Write(DropDownProduct.SelectedItem.Text);
        //Console.WriteLine(DropDownSupplier.SelectedValue);
        //Console.WriteLine(DropDownSupplier.SelectedItem.Text);


        if (sqlcon.State == ConnectionState.Closed)
        {
            sqlcon.Open();
        }
        SqlCommand sqlcmd = new SqlCommand("PurchaseCreateOrUpdate", sqlcon);

        sqlcmd.CommandType = CommandType.StoredProcedure;
        sqlcmd.Parameters.AddWithValue("@PurchaseId", hfPurchaseId.Value == "" ? 0 : Convert.ToInt32(hfPurchaseId.Value));
        sqlcmd.Parameters.AddWithValue("@ProductId", Convert.ToInt32(DropDownProduct.SelectedValue));
        sqlcmd.Parameters.AddWithValue("@SupplierId", Convert.ToInt32(DropDownSupplier.SelectedValue));
        sqlcmd.Parameters.AddWithValue("@Quantity", Convert.ToInt32(txtQuantity.Text.Trim()));
        sqlcmd.Parameters.AddWithValue("@Others", txtOthers.Text);
        sqlcmd.ExecuteNonQuery();
        sqlcon.Close();
        string PurchaseId = hfPurchaseId.Value;


        if (PurchaseId == "")
        {
            lblsuccessmassage.Text = "Saved Successfully";
        }
        else
        {
            lblsuccessmassage.Text = "Updated Successfully";
        }
        FillGridView();
        clear();
        DropDownProduct.ClearSelection();
        DropDownSupplier.ClearSelection();
    }
    protected void btnsave_Click(object sender, EventArgs e)
    {
        //Console.Write(DropDownProduct.SelectedValue);
        //Console.Write(DropDownProduct.SelectedItem.Text);
        //Console.WriteLine(DropDownSupplier.SelectedValue);
        //Console.WriteLine(DropDownSupplier.SelectedItem.Text);


        if (sqlcon.State == ConnectionState.Closed)
        {
            sqlcon.Open();
        }
        //SqlCommand sqlcmd = new SqlCommand("PurchaseCreateOrUpdate", sqlcon);
        //sqlcmd.CommandType = CommandType.StoredProcedure;
        //sqlcmd.Parameters.AddWithValue("@PurchaseId", hfPurchaseId.Value == "" ? 0 : Convert.ToInt32(hfPurchaseId.Value));
        //sqlcmd.Parameters.AddWithValue("@ProductId", Convert.ToInt32(DropDownProduct.SelectedValue));
        //sqlcmd.Parameters.AddWithValue("@SupplierId", Convert.ToInt32(DropDownSupplier.SelectedValue));
        //sqlcmd.Parameters.AddWithValue("@Quantity", Convert.ToInt32(txtQuantity.Text.Trim()));
        //sqlcmd.Parameters.AddWithValue("@DateOfPurchase", Convert.ToInt32(txtDate.Text.Trim()));
        //sqlcmd.Parameters.AddWithValue("@Others", txtOthers.Text);
        //sqlcmd.ExecuteNonQuery();
        //sqlcon.Close();
        //string PurchaseId = hfPurchaseId.Value;

        ///here productId is DepartmentId


        SqlCommand cmd = new SqlCommand("Insert into Purchase values(@PurchaseId,@ProductId,@SupplierId,@Quantity,@TotalAmount,@DateOfPurchase,@Others)", sqlcon);

        cmd.Parameters.AddWithValue("@PurchaseId", DropDownDepartment.SelectedValue);
        cmd.Parameters.AddWithValue("@ProductId", DropDownProduct.SelectedItem.Text);
        cmd.Parameters.AddWithValue("@SupplierId", DropDownSupplier.SelectedItem.Text);
        cmd.Parameters.AddWithValue("@Quantity", txtQuantity.Text.Trim());
        cmd.Parameters.AddWithValue("@TotalAmount", txtAmount.Text.Trim());
        cmd.Parameters.AddWithValue("@DateOfPurchase", txtDate.Text.Trim());
        cmd.Parameters.AddWithValue("@Others", txtOthers.Text.Trim());

        int i = cmd.ExecuteNonQuery();

        sqlcon.Close();
        string PurchaseId = hfPurchaseId.Value;

        if (i > 0)
        {
            lblsuccessmassage.Text = "Saved Successfully";
        }
        else
        {
            lblsuccessmassage.Text = "Updated Successfully";

            FillGridView();


            clear();
            DropDownProduct.ClearSelection();
            DropDownSupplier.ClearSelection();
            DropDownDepartment.ClearSelection();
        }
        //void FillGridView()
        //{
        //    if (sqlcon.State == ConnectionState.Closed)
        //        sqlcon.Open();
        //    string pronamequery = "Select Purchase.PurchaseID,Product.ProductName,Supplier.CompanyName,Purchase.Quantity,Purchase.Others from purchase INNER JOIN Product on Product.ProductId = Purchase.PurchaseId INNER JOIN Supplier on Supplier.SupplierId = Purchase.PurchaseId";
        //    SqlCommand scmd = new SqlCommand(pronamequery, sqlcon);
        //    SqlDataAdapter sda = new SqlDataAdapter(scmd);
        //    DataTable dt = new DataTable();
        //    sda.Fill(dt);
        //    sqlcon.Close();
        //    purchaseGrid.DataSource = dt;
        //    purchaseGrid.DataBind();

        //SqlDataAdapter sqlDa = new SqlDataAdapter("ViewPurchaseGrid", sqlcon);
        //sqlDa.SelectCommand.CommandType = CommandType.StoredProcedure;
        //DataTable dtbl = new DataTable();
        //sqlDa.Fill(dtbl);
        //sqlcon.Close();
        //purchaseGrid.DataSource = dtbl;
        //purchaseGrid.DataBind();
    }