private void SetInitRowPuritm() { DataTable dt = new DataTable(); DataRow dr = null; dt.Columns.Add(new DataColumn("ProNam", typeof(string))); dt.Columns.Add(new DataColumn("Dstk_ItmDes", typeof(string))); dt.Columns.Add(new DataColumn("Dstk_ItmQty", typeof(string))); dt.Columns.Add(new DataColumn("Dstk_Itmwght", typeof(string))); dt.Columns.Add(new DataColumn("Dstk_ItmUnt", typeof(string))); dt.Columns.Add(new DataColumn("Dstk_rat", typeof(string))); dt.Columns.Add(new DataColumn("Dstk_salrat", typeof(string))); dt.Columns.Add(new DataColumn("Dstk_purrat", typeof(string))); dr = dt.NewRow(); dr["ProNam"] = string.Empty; dr["Dstk_ItmDes"] = string.Empty; dr["Dstk_ItmQty"] = string.Empty; dr["Dstk_Itmwght"] = "0.00"; dr["Dstk_ItmUnt"] = "0.00"; dr["Dstk_rat"] = "0.00"; dr["Dstk_salrat"] = "0.00"; dr["Dstk_purrat"] = "0.00"; dt.Rows.Add(dr); //Store the DataTable in ViewState ViewState["dt_adItm"] = dt; GVStkItems.DataSource = dt; GVStkItems.DataBind(); }
protected void TBCat_TextChanged(object sender, EventArgs e) { try { query = " select * from tbl_producttype where ProductTypeName = '" + TBCat.Text.Trim() + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'"; dt_ = DBConnection.GetQueryData(query); if (dt_.Rows.Count > 0) { PurItm = dt_.Rows[0]["ProductTypeName"].ToString(); query = " select distinct(Dstk_unt) as [Dstk_sizes],'0.00' as [Dstk_ItmQty] from tbl_Dstk where procat = '" + PurItm + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'"; DataTable dtpro_ = new DataTable(); dtpro_ = DBConnection.GetQueryData(query); if (dtpro_.Rows.Count > 0) { GVStkItems.DataSource = dtpro_; GVStkItems.DataBind(); ViewState["dt_adItm"] = dtpro_; } } Session["cat"] = TBCat.Text.Trim(); } catch (Exception ex) { throw ex; } }
protected void GVStkItems_RowDeleting(object sender, GridViewDeleteEventArgs e) { if (ViewState["dt_adItm"] != null) { DataTable dt = (DataTable)ViewState["dt_adItm"]; DataRow drCurrentRow = null; int rowIndex = Convert.ToInt32(e.RowIndex); if (dt.Rows.Count > 1) { dt.Rows.Remove(dt.Rows[rowIndex]); drCurrentRow = dt.NewRow(); ViewState["dt_adItm"] = dt; GVStkItems.DataSource = dt; GVStkItems.DataBind(); SetPreRowitm(); //float GTotal = 0; //for (int j = 0; j < GVGRNItems.Rows.Count; j++) //{ // TextBox total = (TextBox)GVGRNItems.Rows[j].FindControl("TbAddPurNetTtl"); // GTotal += Convert.ToSingle(total.Text); //} //TBGrssTotal.Text = GTotal.ToString(); } } }
protected void ddlStckOut_SelectedIndexChanged(object sender, EventArgs e) { try { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = " select CONVERT(VARCHAR(8), MSal_dat, 3) as [MSalDate], CustomerID from tbl_MSal where MSal_id = '" + ddlStckOut.SelectedValue.Trim() + "' and tbl_MSal.ISActive = 'True' "; cmd.Connection = con; con.Open(); DataTable dpurdat = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(dpurdat); if (dpurdat.Rows.Count > 0) { //select CONVERT(VARCHAR(8), MPurDate, 3) as [MPurDate],ven_id,* from MPurchaseinner join DPurchase on MPurchase.MPurID = DPurchase.MPurID where MPurchase.MPurID = 20 and ck_Act = 'True' TBSaldat.Text = dpurdat.Rows[0]["MSalDate"].ToString(); ddl_cust.SelectedValue = dpurdat.Rows[0]["CustomerID"].ToString(); cmd.CommandText = " select tbl_DSal.ProductID as [ProNam], Dsal_ItmDes as [Dstk_ItmDes], Dsal_ItmQty as [Dstk_ItmQty], " + " '' as Dstk_Itmwght, Dsal_ItmUnt as [Dstk_ItmUnt] , Products.Cost as [Dstk_rat], " + " '' as Dstk_salrat, '' as Dstk_purrat from tbl_MSal inner join tbl_DSal on tbl_MSal.MSal_id = tbl_DSal.MSal_id " + " inner join Products on tbl_DSal.ProductID = Products.ProductID " + " where tbl_MSal.ISActive = 'True' and tbl_MSal.MSal_id = '" + ddlStckOut.SelectedValue.Trim() + "'"; cmd.Connection = con; DataTable dtpurdtl = new DataTable(); SqlDataAdapter adppurdt = new SqlDataAdapter(cmd); adppurdt.Fill(dtpurdtl); if (dtpurdtl.Rows.Count > 0) { GVStkItems.DataSource = dtpurdtl; GVStkItems.DataBind(); for (int i = 0; i < GVStkItems.Rows.Count; i++) { DropDownList ddlitem = (DropDownList)GVStkItems.Rows[i].FindControl("ddlstkItm"); Label lbl_pro = (Label)GVStkItems.Rows[i].FindControl("lblPurItm"); ddlitem.SelectedValue = lbl_pro.Text.Trim(); } } } con.Close(); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this, this.GetType(), "isActive", "Alert();", true); lbl_Heading.Text = "Error!"; lblalert.Text = ex.Message; } }
protected void TBItms_TextChanged(object sender, EventArgs e) { try { query = " select * from Products where ProductName = '" + TBItms.Text.Trim() + "'"; dt_ = DBConnection.GetQueryData(query); if (dt_.Rows.Count > 0) { PurItm = dt_.Rows[0]["ProductID"].ToString(); query = " select '0.00' as [Dstk_ItmQty],RDstk_unt as [Dstk_sizes] from tbl_RDstk where ProductID = '" + PurItm + "'"; DataTable dtpro_ = new DataTable(); dtpro_ = DBConnection.GetQueryData(query); if (dtpro_.Rows.Count > 0) { GVStkItems.DataSource = dtpro_; GVStkItems.DataBind(); ViewState["dt_adItm"] = dtpro_; } } else { query = " INSERT INTO Products " + " ([ProductName],[ProductType],[CompanyId],[BranchId],[IsActive]) VALUES('" + TBItms.Text.Trim() + "','" + TBCat.Text.Trim() + "','" + Session["CompanyID"] + "','" + Session["BranchID"] + "','1')"; con.Open(); using (SqlCommand cmd = new SqlCommand(query, con)) { cmd.ExecuteNonQuery(); } con.Close(); } } catch (Exception ex) { throw ex; } }
private void SetInitRow() { DataTable dt = new DataTable(); //DataRow dr = null; dt.Columns.Add(new DataColumn("PRODUCT", typeof(string))); dt.Columns.Add(new DataColumn("SIZE", typeof(string))); dt.Columns.Add(new DataColumn("QTY", typeof(string))); dt.Columns.Add(new DataColumn("RATE", typeof(string))); dt.Columns.Add(new DataColumn("AMT", typeof(string))); dt.Columns.Add(new DataColumn("DSal_id", typeof(string))); ViewState["dt_salItms"] = dt; GVItms.DataSource = dt; GVItms.DataBind(); // For Stock DataTable dtstk = new DataTable(); //DataRow drstk = null; dtstk.Columns.Add(new DataColumn("SIZE", typeof(string))); dtstk.Columns.Add(new DataColumn("QTY", typeof(string))); ViewState["dt_salItm"] = dtstk; GVStkItems.DataSource = dtstk; GVStkItems.DataBind(); //dr = dt.NewRow(); //dr["PRODUCT"] = string.Empty; //dr["SIZE"] = string.Empty; //dr["QTY"] = string.Empty; //dr["RATE"] = string.Empty; //dr["AMT"] = string.Empty; //dr["DSal_id"] = string.Empty; //dt.Rows.Add(dr); //Store the DataTable in ViewState }
protected void ddlstckIn_SelectedIndexChanged(object sender, EventArgs e) { try { string cmdtxt1 = " select CONVERT(VARCHAR(10), MPurDate, 101) as [MPurDate], ven_id from MPurchase where MPurID = " + ddlstckIn.SelectedValue.Trim() + " and ck_Act = 'True' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'"; DataTable dpurdat = new DataTable(); dpurdat = DataAccess.DBConnection.GetDataTable(cmdtxt1); if (dpurdat.Rows.Count > 0) { TBPurdat.Text = dpurdat.Rows[0]["MPurDate"].ToString(); ddl_ven.SelectedValue = dpurdat.Rows[0]["ven_id"].ToString(); string cmdText2 = " select DPurchase.ProductID as [ProNam],DPurchase.ProDes as [Dstk_ItmDes], DPurchase.Qty as [Dstk_ItmQty], " + " '' as Dstk_Itmwght, DPurchase.Unit as [Dstk_ItmUnt] , Products.Cost as [Dstk_rat], " + " '' as Dstk_salrat, '' as Dstk_purrat from MPurchase inner join DPurchase on MPurchase.MPurID = DPurchase.MPurID " + " inner join Products on DPurchase.ProductID = Products.ProductID where ck_Act = 'True' and MPurchase.MPurID = '" + ddlstckIn.SelectedValue.Trim() + "' and Products.CompanyId='" + Session["CompanyID"] + "' and Products.BranchId='" + Session["BranchID"] + "'"; DataTable dtpurdtl = new DataTable(); dtpurdtl = DataAccess.DBConnection.GetDataTable(cmdText2); if (dtpurdtl.Rows.Count > 0) { GVStkItems.DataSource = dtpurdtl; GVStkItems.DataBind(); for (int i = 0; i < GVStkItems.Rows.Count; i++) { DropDownList ddlitem = (DropDownList)GVStkItems.Rows[i].FindControl("ddlstkItm"); Label lbl_pro = (Label)GVStkItems.Rows[i].FindControl("lblPurItm"); ddlitem.SelectedValue = lbl_pro.Text.Trim(); } } } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this, this.GetType(), "isActive", "Alert();", true); lbl_Heading.Text = "Error!"; lblalert.Text = ex.Message; } }
protected void GVStkItems_RowDeleting(object sender, GridViewDeleteEventArgs e) { if (ViewState["dt_adItm"] != null) { DataTable dt = (DataTable)ViewState["dt_adItm"]; DataRow drCurrentRow = null; int rowIndex = Convert.ToInt32(e.RowIndex); if (dt.Rows.Count > 1) { dt.Rows.Remove(dt.Rows[rowIndex]); drCurrentRow = dt.NewRow(); ViewState["dt_adItm"] = dt; GVStkItems.DataSource = dt; GVStkItems.DataBind(); SetPreRowitm(); } } }
private void AddNewRow() { int rowIndex = 0; if (ViewState["dt_adItm"] != null) { DataTable dt = (DataTable)ViewState["dt_adItm"]; DataRow drRow = null; if (dt.Rows.Count > 0) { for (int i = 1; i <= dt.Rows.Count; i++) { //extract the TextBox values TextBox itmsiz = (TextBox)GVStkItems.Rows[rowIndex].Cells[0].FindControl("itmsiz"); TextBox ItmQty = (TextBox)GVStkItems.Rows[rowIndex].Cells[1].FindControl("ItmQty"); drRow = dt.NewRow(); dt.Rows[i - 1]["Dstk_sizes"] = itmsiz.Text; dt.Rows[i - 1]["Dstk_ItmQty"] = ItmQty.Text; rowIndex++; } dt.Rows.Add(drRow); ViewState["dt_adItm"] = dt; GVStkItems.DataSource = dt; GVStkItems.DataBind(); } } else { Response.Write("ViewState is null"); } //Set Previous Data on GRNstbacks SetPreRowitm(); }
private void AddNewRow() { int rowIndex = 0; if (ViewState["dt_adItm"] != null) { DataTable dt = (DataTable)ViewState["dt_adItm"]; DataRow drRow = null; if (dt.Rows.Count > 0) { for (int i = 1; i <= dt.Rows.Count; i++) { //extract the TextBox values DropDownList ddlstkItm = (DropDownList)GVStkItems.Rows[rowIndex].Cells[0].FindControl("ddlstkItm"); TextBox ItmDscptin = (TextBox)GVStkItems.Rows[rowIndex].Cells[1].FindControl("ItmDscptin"); TextBox ItmQty = (TextBox)GVStkItems.Rows[rowIndex].Cells[2].FindControl("ItmQty"); TextBox Tbwght = (TextBox)GVStkItems.Rows[rowIndex].Cells[3].FindControl("Tbwght"); TextBox Tbunts = (TextBox)GVStkItems.Rows[rowIndex].Cells[4].FindControl("Tbunts"); TextBox Tbrat = (TextBox)GVStkItems.Rows[rowIndex].Cells[5].FindControl("Tbrat"); TextBox Tbsalrat = (TextBox)GVStkItems.Rows[rowIndex].Cells[6].FindControl("Tbsalrat"); TextBox Tbpurrat = (TextBox)GVStkItems.Rows[rowIndex].Cells[7].FindControl("Tbpurrat"); drRow = dt.NewRow(); dt.Rows[i - 1]["ProNam"] = ddlstkItm.SelectedValue; dt.Rows[i - 1]["Dstk_ItmDes"] = ItmDscptin.Text; dt.Rows[i - 1]["Dstk_ItmQty"] = ItmQty.Text; dt.Rows[i - 1]["Dstk_Itmwght"] = Tbwght.Text; dt.Rows[i - 1]["Dstk_ItmUnt"] = Tbunts.Text; dt.Rows[i - 1]["Dstk_rat"] = Tbrat.Text; dt.Rows[i - 1]["Dstk_salrat"] = Tbsalrat.Text; dt.Rows[i - 1]["Dstk_purrat"] = Tbpurrat.Text; rowIndex++; //float GTotal = 0, CRAmt = 0, DBAmt = 0; //for (int j = 0; j < GVStkItems.Rows.Count; j++) //{ // TextBox total = (TextBox)GVStkItems.Rows[j].FindControl("TbAddPurNetTtl"); // TextBox CRAmtttl = (TextBox)GVStkItems.Rows[j].FindControl("Tbcramt"); // TextBox DBAmtttl = (TextBox)GVStkItems.Rows[j].FindControl("Tbdbamt"); // GTotal += Convert.ToSingle(total.Text); // CRAmt += Convert.ToSingle(CRAmtttl.Text); // DBAmt += Convert.ToSingle(DBAmtttl.Text); //} //TBGrssTotal.Text = GTotal.ToString(); //TBCRAmtttl.Text = CRAmt.ToString(); //TBDBAmtttl.Text = DBAmt.ToString(); ddlstkItm.Focus(); } dt.Rows.Add(drRow); ViewState["dt_adItm"] = dt; GVStkItems.DataSource = dt; GVStkItems.DataBind(); } } else { Response.Write("ViewState is null"); } //Set Previous Data on GRNstbacks SetPreRowitm(); }
protected void TBItms_TextChanged(object sender, EventArgs e) { try { query = " select * from Products where ProductName = '" + TBItms.Text.Trim() + "'"; dt_ = DBConnection.GetQueryData(query); if (dt_.Rows.Count > 0) { PurItm = dt_.Rows[0]["ProductID"].ToString(); //query = " select '0.00' as [Dstk_ItmQty],Dstk_unt as [Dstk_sizes] from tbl_Dstk where ProductID = '" + PurItm + "'"; query = " select Dstk_ItmDes as [PRODUCT],Dstk_unt as [SIZE], Dstk_Qty as [QTY], Dstk_rat as [RATE], " + " (Dstk_rat * Dstk_Qty) as [AMT], '' as [DSal_id] from tbl_Dstk where ProductID = '" + PurItm + "'"; DataTable dtpro_ = new DataTable(); dtpro_ = DBConnection.GetQueryData(query); if (dtpro_.Rows.Count > 0) { TB_Rat.Text = dtpro_.Rows[0]["RATE"].ToString(); //decimal ttl = 0; //DataRow dr; //dr = dtpro_.NewRow(); //for (int i = 0; i <= dtpro_.Rows.Count; i++) //{ // dr[0] = TBItms.Text; // dr[1] = dtpro_.Rows[0]["SIZE"].ToString(); // dr[2] = dtpro_.Rows[0]["QTY"].ToString(); // dr[3] = TB_Rat.Text; // ttl = Convert.ToDecimal(dtpro_.Rows[0]["QTY"]) * Convert.ToDecimal(TB_Rat.Text.Trim()); // dr[4] = ttl.ToString(); //} //dtpro_.Rows.Add(dr); GVStkItems.DataSource = dtpro_; GVStkItems.DataBind(); DataRow dr; decimal ttl = 0; foreach (GridViewRow row in GVStkItems.Rows) { TextBox itmsiz = (TextBox)row.FindControl("itmsiz"); TextBox ItQty = (TextBox)row.FindControl("ItQty"); dr = dtpro_.NewRow(); dr[0] = TBItms.Text; dr[1] = itmsiz.Text; dr[2] = ItQty.Text; dr[3] = TB_Rat.Text; ttl = Convert.ToDecimal(ItQty.Text.Trim()) * Convert.ToDecimal(TB_Rat.Text.Trim()); dr[4] = ttl.ToString(); dtpro_.Rows.Add(dr); } ViewState["dt_salItm"] = dtpro_; } } else { query = " INSERT INTO Products " + " ([ProductName],[ProductType],[CompanyId],[BranchId],[IsActive]) VALUES('" + TBItms.Text.Trim() + "','" + TBCat.Text.Trim() + "','" + Session["CompanyID"] + "','" + Session["BranchID"] + "','1')"; con.Open(); using (SqlCommand cmd = new SqlCommand(query, con)) { cmd.ExecuteNonQuery(); } con.Close(); } } catch (Exception ex) { throw ex; } }