private void TotalRecords() { using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString())) { string UserClass = Convert.ToString(Session["Userclass"]); Int64 UserIdno = 0; if (UserClass != "Admin") { UserIdno = Convert.ToInt64(Session["UserIdno"]); } CurrentStockRpt obj = new CurrentStockRpt(); Int64 YearId = Convert.ToInt64(ddlDateRange.SelectedValue); DataTable list1 = obj.SelectCurrentStockReport(ApplicationFunction.ConnectionString(), Convert.ToDateTime(hidmindate.Value), 0, "", 0, YearId); lblTotalRecord.Text = "T. Record (s): " + Convert.ToString(list1.Rows.Count); } }
private void BindGrid() { CurrentStockRpt obj = new CurrentStockRpt(); Int64 ItemIdno = Convert.ToInt64((ddlItemName.SelectedValue) == "" ? "0" : ddlItemName.SelectedValue); string serialNo = txtSerialNo.Text.Trim(); Int64 YearID = Convert.ToInt64(ddlDateRange.SelectedValue); Int64 LocIdno = Convert.ToInt64((ddlFromCity.SelectedValue) == "" ? "0" : ddlFromCity.SelectedValue); dt = obj.SelectCurrentStockReport(ApplicationFunction.ConnectionString(), Convert.ToDateTime(hidmindate.Value), ItemIdno, serialNo, LocIdno, YearID); obj = null; if (dt != null && dt.Rows.Count > 0) { DataColumn newNetTotal = new DataColumn("Qty", typeof(string)); newNetTotal.AllowDBNull = true; dt.Columns.Add(newNetTotal); string strItemIdno = Convert.ToString(dt.Rows[0]["ItemIdno"]); //outer variable double dqty = 0; double dItemRate = 0; // inner variable double ddqty = 0; Double ddItemRate = 0; for (int k = 0; k < dt.Rows.Count; k++) { dqty += 1; dt.Rows[k]["Qty"] = 1; dItemRate += Convert.ToDouble(dt.Rows[k]["RATE"].ToString()); // ***************************************************************************************************************************** if (Convert.ToString(dt.Rows[k]["ItemIdno"]) == strItemIdno) { //dt.Rows[k]["Qty"] = 1; ddqty += 1; ddItemRate += Convert.ToDouble(dt.Rows[k]["RATE"].ToString()); } else { DataRow dr = dt.NewRow(); dr.BeginEdit(); dr[0] = ""; dr[1] = ""; dr[3] = "Group Total:"; dr[7] = ddItemRate.ToString("N2"); dr[8] = ddqty.ToString(); dt.Rows.InsertAt(dr, k); dt.AcceptChanges(); ddqty = 0; ddItemRate = 0; if (k != 0) { ddqty += 1; ddItemRate += Convert.ToDouble(dt.Rows[k + 1]["RATE"].ToString()); } k++; strItemIdno = Convert.ToString(dt.Rows[k]["ItemIdno"]); } // ***************************************************************************************************************************** } DataRow dr1 = dt.NewRow(); dr1.BeginEdit(); dr1[0] = ""; dr1[1] = ""; dr1[3] = "Group Total:"; dr1[7] = ddItemRate.ToString("N2"); dr1[8] = ddqty.ToString(); dt.Rows.Add(dr1); DataRow dr2 = dt.NewRow(); dr2.BeginEdit(); dr2[0] = ""; dr2[1] = ""; dr2[2] = ""; dt.Rows.Add(dr2); DataRow dr3 = dt.NewRow(); dr3.BeginEdit(); dr3[0] = ""; dr3[1] = ""; dr3[3] = "Total:"; dr3[7] = dItemRate.ToString("N2"); dr3[8] = dqty.ToString(); dt.Rows.Add(dr3); grdMain.Columns.Clear(); for (int i = 0; i < dt.Columns.Count; i++) { BoundField bfield = new BoundField(); bfield.HeaderText = Convert.ToString(dt.Columns[i].ColumnName); bfield.DataField = Convert.ToString(dt.Columns[i].ColumnName); grdMain.Columns.Add(bfield); } if (dt != null && dt.Rows.Count > 0) { ViewState["Dt"] = dt; } grdMain.DataSource = dt; grdMain.DataBind(); grdMain.HeaderRow.Cells[0].Text = "Item Name"; grdMain.HeaderRow.Cells[1].Text = "Brand"; grdMain.HeaderRow.Cells[2].Text = "Serial No"; grdMain.HeaderRow.Cells[3].Text = "Type"; grdMain.HeaderRow.Cells[4].Text = "Days"; grdMain.HeaderRow.Cells[6].Text = "Location"; grdMain.Columns[0].HeaderStyle.Width = 140; grdMain.Columns[1].HeaderStyle.Width = 140; grdMain.Columns[2].HeaderStyle.Width = 140; grdMain.Columns[3].HeaderStyle.Width = 140; grdMain.Columns[4].HeaderStyle.Width = 140; grdMain.Columns[6].HeaderStyle.Width = 130; grdMain.Columns[7].HeaderStyle.Width = 130; grdMain.Columns[8].HeaderStyle.Width = 100; grdMain.Columns[0].HeaderStyle.HorizontalAlign = HorizontalAlign.Left; grdMain.Columns[1].HeaderStyle.HorizontalAlign = HorizontalAlign.Left; grdMain.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Left; grdMain.Columns[1].ItemStyle.HorizontalAlign = HorizontalAlign.Left; grdMain.Columns[2].ItemStyle.HorizontalAlign = HorizontalAlign.Left; grdMain.Columns[3].ItemStyle.HorizontalAlign = HorizontalAlign.Left; grdMain.Columns[4].ItemStyle.HorizontalAlign = HorizontalAlign.Left; grdMain.Columns[6].ItemStyle.HorizontalAlign = HorizontalAlign.Left; grdMain.Columns[7].ItemStyle.HorizontalAlign = HorizontalAlign.Right; grdMain.Columns[8].ItemStyle.HorizontalAlign = HorizontalAlign.Right; grdMain.Columns[5].Visible = false; lblTotalRecord.Text = "T. Record : " + dqty.ToString(); imgBtnExcel.Visible = true; } else { grdMain.DataSource = null; grdMain.DataBind(); lblTotalRecord.Text = "T. Record : 0 "; imgBtnExcel.Visible = false; } }