public void clear() { hfPurchaseId.Value = ""; txtQuantity.Text = txtOthers.Text = ""; DropDownProduct.ClearSelection(); DropDownSupplier.ClearSelection(); lblerrormessage.Text = lblsuccessmassage.Text = ""; btnsave.Text = "Save"; btndelete.Enabled = true; }
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!"); }
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(); }