//Bind Item Category #region [Bind Item Grid] public DataSet BindItemGrid_DL(EWA_PurchaseOrder objEWA) { DataSet ds = new DataSet(); try { prmList = new string[4]; prmList[0] = "@Action"; prmList[1] = "FetchItemData"; prmList[2] = "@SupplierId"; prmList[3] = objEWA.SupplierId; ds = ObjHelper.FillControl(prmList, "SP_PurchaseOrder"); if (ds.Tables[0].Rows.Count > 0) { return(ds); } else { DataTable dt = new DataTable(); dt.Columns.Add("ItemName"); dt.Rows.Add(); dt.Rows.Add(); dt.Rows.Add(); //return dsCode; } return(ds); } catch (Exception exp) { throw exp; } }
//Item Grid Bind #region [Item Category Grid Bind] private void BindItemGrid() { try { EWA_PurchaseOrder objEWA = new EWA_PurchaseOrder(); BL_PurchaseOrder objBL = new BL_PurchaseOrder(); objEWA.SupplierId = ddlSupplier.SelectedValue; objEWA.OrgId = orgId; DataSet ds = objBL.BindItemGrid_BL(objEWA); if (ds.Tables[0].Rows.Count == 0 || ds == null) { ds.Tables[0].Rows.Add(ds.Tables[0].NewRow()); GrdItem.DataSource = ds; GrdItem.DataBind(); int columncount = GrdItem.Rows[0].Cells.Count; GrdItem.Rows[0].Cells.Clear(); GrdItem.Rows[0].Cells.Add(new TableCell()); GrdItem.Rows[0].Cells[0].ColumnSpan = columncount; GrdItem.Rows[0].Cells[0].Text = "No Records Found"; } else { GrdItem.DataSource = ds; GrdItem.DataBind(); ItemName1.Text = ds.Tables[0].Rows[0]["ItemName"].ToString(); Category1.Text = ds.Tables[0].Rows[0]["CategoryName"].ToString(); Suppliername1.Text = ddlSupplier.SelectedItem.ToString(); } } catch (Exception exp) { GeneralErr(exp.Message.ToString()); } }
//Bind Supplier category #region [Bind Supplier] public DataSet BindSupplier_DL(EWA_PurchaseOrder objEWA) { DataSet ds = new DataSet(); try { prmList = new string[4]; prmList[0] = "@Action"; prmList[1] = "FetchSupplier"; prmList[2] = "@OrgId"; prmList[3] = Convert.ToString(objEWA.OrgId); ds = ObjHelper.FillControl(prmList, "SP_PurchaseOrder"); if (ds.Tables[0].Rows.Count > 0) { return(ds); } return(ds); } catch (Exception exp) { throw exp; } }
//Perform Action on Supplier Table #region [Perform Actions On Supplier] public DataSet POAction_DL(EWA_PurchaseOrder objEWA, DataTable dt) { DataSet ds = new DataSet(); try { cmd = new SqlCommand("SP_PurchaseOrder", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Action", objEWA.Action); cmd.Parameters.AddWithValue("@POId", objEWA.POId); cmd.Parameters.AddWithValue("@PODate", objEWA.PODate); cmd.Parameters.AddWithValue("@POCode", objEWA.POCode); cmd.Parameters.AddWithValue("@SupplierId", objEWA.SupplierId); cmd.Parameters.AddWithValue("@GrandTotal", objEWA.GrandTotal); cmd.Parameters.AddWithValue("@PaymentMode", objEWA.PaymentMode); cmd.Parameters.AddWithValue("@DeliveryMode", objEWA.DeliveryMode); cmd.Parameters.AddWithValue("@Remark", objEWA.Remark); cmd.Parameters.AddWithValue("@OrgId", objEWA.OrgId); cmd.Parameters.AddWithValue("@UserId", objEWA.UserId); // cmd.Parameters.AddWithValue("@Status", objEWA.Status); cmd.Parameters.AddWithValue("@IsActive", objEWA.IsActive); SqlParameter tblvaluetype = cmd.Parameters.AddWithValue("@PODetails", dt); //Passing table value parameter tblvaluetype.SqlDbType = SqlDbType.Structured; con.Open(); sqlTransaction = con.BeginTransaction(); cmd.Transaction = sqlTransaction; SqlDataAdapter ad = new SqlDataAdapter(cmd); ad.Fill(ds); //int flag = cmd.ExecuteNonQuery(); sqlTransaction.Commit(); } catch (Exception ex) { int err = ((System.Data.SqlClient.SqlException)(ex)).Number; if (err == 547 && objEWA.Action == "Delete") { throw new SystemException("Record is in use !!!"); } else { //throw ex; } } finally { cmd.Dispose(); con.Close(); } return(ds); }
//Item Grid Bind #region [Item Grid Bind] public DataSet BindItemGrid_BL(EWA_PurchaseOrder objEWA) { try { DL_PurchaseOrder objDL = new DL_PurchaseOrder(); DataSet ds = objDL.BindItemGrid_DL(objEWA); return(ds); } catch (Exception exp) { throw exp; } }
//Bind Supplier Category #region [Bind Supplier Category] public DataSet BindSupplier_BL(EWA_PurchaseOrder objEWA) { try { DL_PurchaseOrder objDL = new DL_PurchaseOrder(); DataSet ds = objDL.BindSupplier_DL(objEWA); return(ds); } catch (Exception) { throw; } }
//To Fetch CourseId #region [Fetch POCode] public DataSet GetPOCode_BL(EWA_PurchaseOrder objEWA) { try { DL_PurchaseOrder objDL = new DL_PurchaseOrder(); DataSet ds = objDL.GetPOCode_DL(objEWA); return(ds); } catch (Exception exp) { throw exp; } }
//Action Performed #region [ActionPerformed For Supplier ] public DataSet POAction_BL(EWA_PurchaseOrder objEWA, DataTable dt) { DataSet ds = new DataSet(); try { DL_PurchaseOrder objDL = new DL_PurchaseOrder(); ds = objDL.POAction_DL(objEWA, dt); } catch (Exception) { //throw; } return(ds); }
private void GetReportData() { crPurchaseOrder crt = new crPurchaseOrder(); EWA_PurchaseOrder objEWA = new EWA_PurchaseOrder(); DL_PurchaseOrder objDL = new DL_PurchaseOrder(); String POCode = Session["POCode"].ToString(); objEWA.POCode = POCode; DataSet ds = objDL.BindPurchaseOrderReport(objEWA); crt.SetDataSource(ds.Tables[0]); crvPO.ReportSource = crt; crvPO.RefreshReport(); Session.Add("CR_Session", crt); //Add Report into Session CR_Session }
private void BindSupplier() { try { EWA_PurchaseOrder objEWA = new EWA_PurchaseOrder(); BL_PurchaseOrder ObjBL = new BL_PurchaseOrder(); objEWA.OrgId = orgId; DataSet dsSupplier = ObjBL.BindSupplier_BL(objEWA); ddlSupplier.DataSource = dsSupplier; ddlSupplier.DataTextField = "SupplierName"; ddlSupplier.DataValueField = "SupplierId"; ddlSupplier.DataBind(); ddlSupplier.Items.Insert(0, "Select"); } catch (Exception exp) { GeneralErr(exp.Message.ToString()); } }
// Bind Purchase Order Report #region [Purchase Order Report] public DataSet BindPurchaseOrderReport(EWA_PurchaseOrder objEWA) { DataSet ds = new DataSet(); try { prmList = new string[4]; prmList[0] = "@Action"; prmList[1] = "PrintPO"; prmList[2] = "@POCode"; prmList[3] = objEWA.POCode; ds = ObjHelper.FillControl(prmList, "SP_PurchaseOrder"); return(ds); } catch (Exception ex) { throw ex; } }
private void GetPOCode() { try { EWA_PurchaseOrder objEWA = new EWA_PurchaseOrder(); BL_PurchaseOrder objBL = new BL_PurchaseOrder(); //Send it from Session objEWA.OrgId = orgId; DataSet POCodeds = objBL.GetPOCode_BL(objEWA); string POCode = POCodeds.Tables[0].Rows[0][0].ToString(); String POrdCode = "PO/" + orgId + "/" + POCode; // lblPOCode.Text = objEWA.OrgId + StaffId; ViewState["POCode"] = POrdCode; Session["POCode"] = POrdCode; txtPOCode.Text = ViewState["POCode"].ToString(); } catch (Exception exp) { GeneralErr(exp.Message.ToString()); } }
//Perform Action #region [Perform Action] private void Action(string strAction) { try { EWA_PurchaseOrder objEWA = new EWA_PurchaseOrder(); BL_PurchaseOrder objBL = new BL_PurchaseOrder(); objEWA.Action = strAction; if (strAction == "Update" || strAction == "Delete") { objEWA.POId = Convert.ToInt32(ViewState["POId"].ToString()); } objEWA.PODate = txtPODate.Text; objEWA.POCode = txtPOCode.Text.Trim(); objEWA.SupplierId = ddlSupplier.SelectedValue; objEWA.GrandTotal = ViewState["GrandTotal"].ToString(); objEWA.PaymentMode = ddlPaymentMode.SelectedItem.ToString(); objEWA.DeliveryMode = ddlDeliveryMode.SelectedItem.ToString(); objEWA.Remark = txtRemark.Text.Trim(); objEWA.OrgId = orgId; objEWA.UserId = Session["UserCode"].ToString(); objEWA.IsActive = "True"; //int count = GrdItem.Rows.Count; //DataTable dt = new DataTable(); //foreach (GridViewRow gvrow in GrdItem.Rows) //{ // CheckBox chk = (CheckBox)gvrow.FindControl("chkBxSelect"); // if (chk != null && chk.Checked) // { // if (ViewState["POItem"] == null) // { // dt.Columns.Add("ItemId"); // dt.Columns.Add("Quantity"); // dt.Columns.Add("Rate"); // DataRow rw = dt.NewRow(); // // rw["SupplierId"] = ddlPartyName.SelectedItem.Value.ToString(); // rw["ItemId"] = GrdItem.DataKeys[gvrow.RowIndex].Values["ItemId"].ToString(); // rw["Quantity"] = GrdItem.DataKeys[gvrow.RowIndex].Values["Quantity"].ToString(); // rw["Rate"] = GrdItem.DataKeys[gvrow.RowIndex].Values["Rate"].ToString(); // dt.Rows.Add(rw); // ViewState["POItems"] = dt as DataTable; // } // else // { // int cnt = 0; // dt = ViewState["POItems"] as DataTable; // foreach (DataRow drow in dt.Rows) // { // if (!chk.Checked) // { // cnt = 1; // } // } // if (cnt == 0) // { // DataRow rw = dt.NewRow(); // rw["ItemId"] = GrdItem.DataKeys[gvrow.RowIndex].Values["ItemId"].ToString(); // rw["Quantity"] = GrdItem.DataKeys[gvrow.RowIndex].Values["Quantity"].ToString(); // rw["Rate"] = GrdItem.DataKeys[gvrow.RowIndex].Values["Rate"].ToString(); // dt.Rows.Add(rw); // ViewState["POItem"] = dt as DataTable; // } // } // } // } DataTable dt = new DataTable(); int count = 0; if (GrdItem.Rows[0].Cells[2].Text == "" || GrdItem.Rows[0].Cells[2].Text == " ") { msgBox.ShowMessage("Please Select Supplier Items !!!", "Information", UserControls.MessageBox.MessageStyle.Information); return; } foreach (GridViewRow rw in GrdItem.Rows) { CheckBox chkItem = new CheckBox(); chkItem = rw.Cells[0].FindControl("chkBxSelect") as CheckBox; if (chkItem.Checked) { TextBox txtQty = new TextBox(); TextBox txtRate = new TextBox(); Label lblTotalAmt = new Label(); txtQty = rw.Cells[5].FindControl("txtQty") as TextBox; txtRate = rw.Cells[6].FindControl("txtRate") as TextBox; lblTotalAmt = rw.Cells[7].FindControl("lblTotalAmount") as Label; double chkout = 0; if (txtQty.Text == "") { msgBox.ShowMessage("Please Enter Product Quantity !!!", "Information", UserControls.MessageBox.MessageStyle.Information); return; } else if (txtRate.Text == "") { msgBox.ShowMessage("Please Enter Product Rate !!!", "Information", UserControls.MessageBox.MessageStyle.Information); return; } else if (double.TryParse(txtQty.Text, out chkout) == false) { msgBox.ShowMessage("Please Enter Valid Quantity !!!", "Information", UserControls.MessageBox.MessageStyle.Information); return; } else if (double.TryParse(txtRate.Text, out chkout) == false) { msgBox.ShowMessage("Please Enter Valid Rate !!!", "Information", UserControls.MessageBox.MessageStyle.Information); return; } if (ViewState["POItem"] != null) { dt = ViewState["POItem"] as DataTable; for (int i = 0; i < dt.Rows.Count; i++) { if (rw.Cells[2].Text == dt.Rows[i][2].ToString()) { msgBox.ShowMessage("This Item is Allready Exist !!!", "Information", UserControls.MessageBox.MessageStyle.Information); return; } } dt.Rows.Add(0, GrdItem.DataKeys[rw.RowIndex].Value, txtQty.Text, txtRate.Text, lblTotalAmt.Text); // dt.Rows.Add(0, GrdItem.DataKeys[rw.RowIndex].Value, rw.Cells[2].Text, rw.Cells[3].Text, rw.Cells[4].Text, txtQty.Text, txtRate.Text); } else { dt.Columns.Add("POId"); dt.Columns.Add("ItemId"); //dt.Columns.Add("ItemName"); //dt.Columns.Add("Category"); // dt.Columns.Add("Unit"); dt.Columns.Add("Qty"); dt.Columns.Add("Rate"); dt.Columns.Add("TotalAmt"); //dt.Rows.Add(0, GrdItem.DataKeys[rw.RowIndex].Value, rw.Cells[2].Text, rw.Cells[3].Text,rw.Cells[4].Text, txtQty.Text, txtRate.Text); dt.Rows.Add(0, GrdItem.DataKeys[rw.RowIndex].Value, txtQty.Text, txtRate.Text, lblTotalAmt.Text); ViewState["POItem"] = dt; //ItemName1.Text = GrdItem.Rows[0].Cells[1].ToString(); //Category1.Text = GrdItem.Rows[0].Cells[2].ToString(); qty1.Text = txtQty.Text; Rate1.Text = txtRate.Text; Tamt1.Text = lblTotalAmt.Text; } count = count + 1; } } if (count == 0) { msgBox.ShowMessage("Please Select Items !!!", "Information", UserControls.MessageBox.MessageStyle.Information); return; } else { //GrdSelectedItems.DataSource = dt; // GrdSelectedItems.DataBind(); //if (ViewState["DSItems"] != null) //{ // DataSet dsItemsOrg = ViewState["DSItems"] as DataSet; // GrdItem.DataSource = dsItemsOrg; // GrdItem.DataBind(); //} //CalculateAmt(); //Calculation(); // GrdTax.Enabled = true; } dt = ViewState["POItem"] as DataTable; DataSet ds = objBL.POAction_BL(objEWA, dt); if (ds.Tables[0].Rows.Count > 0) { if (strAction == "Save") { GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); Suppliername1.Text = ds.Tables[0].Rows[0]["SupplierName"].ToString(); ItemName1.Text = ds.Tables[0].Rows[0]["PODate"].ToString(); Tamt1.Text = ds.Tables[0].Rows[0]["GrandTotal"].ToString(); //lblPOCode.Text = ds.Tables[0].Rows[0]["POCode"].ToString(); msgBox.ShowMessage("Record Saved Successfully !!!", "Saved", UserControls.MessageBox.MessageStyle.Successfull); } else if (strAction == "Update") { msgBox.ShowMessage("Record Updated Successfully !!!", "Updated", UserControls.MessageBox.MessageStyle.Successfull); } else if (strAction == "Delete") { msgBox.ShowMessage("Record Deleted Successfully !!!", "Deleted", UserControls.MessageBox.MessageStyle.Successfull); } } else { if (strAction == "Save") { msgBox.ShowMessage("Unable to Save !!!", "Critical", UserControls.MessageBox.MessageStyle.Critical); } else if (strAction == "Update") { msgBox.ShowMessage("Unable to Update !!!", "Critical", UserControls.MessageBox.MessageStyle.Critical); } else if (strAction == "Delete") { msgBox.ShowMessage("Unable to Delete !!!", "Critical", UserControls.MessageBox.MessageStyle.Critical); } } } catch (Exception exp) { GeneralErr(exp.Message.ToString()); } }
//Save Data #region SaveData protected void btnSave_Click(object sender, EventArgs e) { EWA_PurchaseOrder objEWA = new EWA_PurchaseOrder(); BL_PurchaseOrder objBL = new BL_PurchaseOrder(); try { lock (this) { //ViewState["DocumentId"] = 0; int chk = 0;//= CheckData(); if (chk > 0) { msgBox.ShowMessage("Record Allready Exist !!!", "Information", UserControls.MessageBox.MessageStyle.Information); } else { Action("Save"); // int count = GrdItem.Rows.Count; // string[] Itemstock = new string[count]; // int i = 0; // foreach (GridViewRow gvrow in GrdItem.Rows) // { // TextBox txtQty = new TextBox(); // txtQty = gvrow.Cells[5].FindControl("txtQty") as TextBox; // CheckBox chk1 = (CheckBox)gvrow.FindControl("chkBxSelect"); // if (chk1 != null && chk1.Checked) // { // Itemstock[i] = GrdItem.DataKeys[gvrow.RowIndex].Values["ItemName"].ToString(); // // TextBox txtValueMain = GrdItem.Cells[1].FindControl("txtValue") as TextBox; // itemid = db.getDb_Value(" SELECT tblItem.ItemId FROM tblItem INNER JOIN tblItemSupplier ON tblItem.ItemId = tblItemSupplier.ItemId WHERE tblItem.OrgId = '" + orgId.ToString() + "' AND tblItem.ItemName = '" + Itemstock[i] + "' AND tblItemSupplier.SupplierId = '" + ddlSupplier.Text + "'"); // //for stock maintain // itemname12 = db.getDbstatus_Value("SELECT tblItem.ItemName FROM tblItem INNER JOIN tblItemSupplier ON tblItem.ItemId = tblItemSupplier.ItemId WHERE (tblItem.OrgId = '" + orgId.ToString() + "') AND (tblItem.ItemName = '" + Itemstock[i] + "') AND (tblItemSupplier.SupplierId = '" + ddlSupplier.Text + "')"); // stock = db.getDb_Value("select Stock from tblItem where OrgId='" + orgId.ToString() + "' and ItemName='" + itemname12 + "'"); // float upstock = stock + Convert.ToInt32(txtQty.Text); // db.cnopen(); // // db.insert("insert into tblItem (Stock,ItemName) values ('" + upstock + "','" + itemname12 + "' )"); // db.insert("update tblItem set Stock='" + upstock + "' where OrgId='" + orgId.ToString() + "' and ItemName='" + Itemstock[i] + "'"); // db.cnclose(); // i++; // } //} //BindSupplierGrid(); // btnNew.Enabled = false; btnSave.Enabled = false; btnPrint.Enabled = true; clear(); //GrdPurchaseOrder.DataSourceID = "SqlDataSource1"; GrdPurchaseOrder.DataBind(); GetPOCode(); } } } catch (Exception exp) { // GeneralErr(exp.Message.ToString()); } }