private void Load_PortageBill() { try { string _SortOrderColumns = "DOA_HomePort , RANK_SORT_ORDER "; Dictionary <string, UDCHyperLink> DicLink = new Dictionary <string, UDCHyperLink>(); lblPageTitle.Text = "Portage Bill : " + Convert.ToString(ViewState["Vessel_Name"]) + " - " + DateTime.Parse(ViewState["PBDt"].ToString()).ToString("MMM-yyyy"); UDCHyperLink alink = new UDCHyperLink(); alink.Target = "_blank"; alink.NaviagteURL = "../crew/CrewDetails.aspx"; alink.QueryStringDataColumn = new string[] { "VoyageID", "CrewID" }; alink.QueryStringText = new string[] { "VoyageID", "ID" }; DicLink.Add("Code", alink); DataSet dsPb = BLL_PB_PortageBill.Get_PortageBill(Convert.ToInt32(DateTime.Parse(ViewState["PBDt"].ToString()).Month), Convert.ToInt32(DateTime.Parse(ViewState["PBDt"].ToString()).Year), Convert.ToInt32(ViewState["Vessel_ID"]), UDFLib.ConvertStringToNull(null), 0); dtcomment = dsPb.Tables["Comment"]; dtEntryType = dsPb.Tables["EntryType"]; DataTable dtpb = UDFLib.PivotTable("Description", "Amount", "Sort_Order", new string[] { "VOYAGEID", "PBMONTH", "PBYEAR" }, new string[] { "VOYAGEID", "PBMONTH", "PBYEAR", "RANK_SORT_ORDER", "IsFinalized", "DOA_HomePort", "RANK_SORT_ORDER", "Amount", "Description", "Sort_Order", "CrewID" }, _SortOrderColumns, DicLink, dsPb.Tables["Data"] ); totalEarnID = dtpb.Columns.IndexOf("Total Earning"); totalDedID = dtpb.Columns.IndexOf("Total Deduction"); BFid = dtpb.Columns.IndexOf("balance"); dtpb.DefaultView.RowFilter = "rank <> ''"; DataTable dt = dtpb.DefaultView.ToTable(); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { if (!string.IsNullOrEmpty(dr["From"].ToString())) { dr["From"] = UDFLib.ConvertUserDateFormat(Convert.ToDateTime(dr["From"].ToString()).ToString("dd/MM/yyyy"), UDFLib.GetDateFormat()); } if (!string.IsNullOrEmpty(dr["To"].ToString())) { dr["To"] = UDFLib.ConvertUserDateFormat(Convert.ToDateTime(dr["To"].ToString()).ToString("dd/MM/yyyy"), UDFLib.GetDateFormat()); } } } GridViewPB.DataSource = dt; GridViewPB.DataBind(); } catch (Exception ex) { UDFLib.WriteExceptionLog(ex); } }
protected void btnExportExcel_Click(object sender, ImageClickEventArgs e) { try { string _SortOrderColumns = "DOA_HomePort , RANK_SORT_ORDER "; Dictionary <string, UDCHyperLink> DicLink = new Dictionary <string, UDCHyperLink>(); lblPageTitle.Text = "Portage Bill : " + Convert.ToString(ViewState["Vessel_Name"]) + " - " + DateTime.Parse(ViewState["PBDt"].ToString()).ToString("MMM-yyyy"); UDCHyperLink alink = new UDCHyperLink(); alink.Target = "_blank"; alink.NaviagteURL = "../crew/CrewDetails.aspx"; alink.QueryStringDataColumn = new string[] { "VoyageID", "CrewID" }; alink.QueryStringText = new string[] { "VoyageID", "ID" }; DicLink.Add("Code", alink); DataSet dsPb = BLL_PB_PortageBill.Get_PortageBill(Convert.ToInt32(DateTime.Parse(ViewState["PBDt"].ToString()).Month), Convert.ToInt32(DateTime.Parse(ViewState["PBDt"].ToString()).Year), Convert.ToInt32(ViewState["Vessel_ID"]), UDFLib.ConvertStringToNull(null), 0); dtcomment = dsPb.Tables["Comment"]; dtEntryType = dsPb.Tables["EntryType"]; DataTable dtpb = UDFLib.PivotTable("Description", "Amount", "Sort_Order", new string[] { "VOYAGEID", "PBMONTH", "PBYEAR" }, new string[] { "VOYAGEID", "PBMONTH", "PBYEAR", "RANK_SORT_ORDER", "IsFinalized", "DOA_HomePort", "RANK_SORT_ORDER", "Amount", "Description", "Sort_Order", "CrewID" }, _SortOrderColumns, DicLink, dsPb.Tables["Data"] ); totalEarnID = dtpb.Columns.IndexOf("Total Earning"); totalDedID = dtpb.Columns.IndexOf("Total Deduction"); BFid = dtpb.Columns.IndexOf("balance"); dtpb.DefaultView.RowFilter = "rank <> ''"; DataTable dt = new DataTable(); dt = dtpb.DefaultView.ToTable(); string[] HeaderCaptions = { }; string[] DataColumnsName = { }; for (int i = 0; i < dt.Columns.Count; i++) { Array.Resize(ref HeaderCaptions, HeaderCaptions.Length + 1); HeaderCaptions[HeaderCaptions.Length - 1] = dt.Columns[i].ColumnName; Array.Resize(ref DataColumnsName, DataColumnsName.Length + 1); DataColumnsName[DataColumnsName.Length - 1] = dt.Columns[i].ColumnName; } foreach (DataRow row in dt.Rows) { string st = row["Code"].ToString(); int start = st.IndexOf('>'); int end = st.IndexOf('<', start); st = st.Substring(start + 1, end - start - 1); row["Code"] = st; } UDFLib.ChangeColumnDataType(dt, "To", typeof(string)); UDFLib.ChangeColumnDataType(dt, "From", typeof(string)); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["From"] = " " + UDFLib.ConvertUserDateFormat(Convert.ToString(dt.Rows[i]["From"].ToString()), UDFLib.GetDateFormat()); dt.Rows[i]["To"] = " " + UDFLib.ConvertUserDateFormat(Convert.ToString(dt.Rows[i]["To"].ToString()), UDFLib.GetDateFormat()); } } //RemoveLinks(GridViewPB); GridViewExportUtil.ExportToExcel(dt, HeaderCaptions, DataColumnsName, "PortageBill-" + Request.QueryString["arg"].Split('~')[2] + "-" + DateTime.Parse(Request.QueryString["arg"].Split('~')[1]).ToString("MMM-yyyy") + ".xls", "PortageBill-" + Request.QueryString["arg"].Split('~')[2] + "-" + DateTime.Parse(Request.QueryString["arg"].Split('~')[1]).ToString("MMM-yyyy")); //GridViewExportUtil.Export("PortageBill-" + Request.QueryString["arg"].Split('~')[2] + "-" + DateTime.Parse(Request.QueryString["arg"].Split('~')[1]).ToString("MMM-yyyy") + ".xls", GridView1); // GridView1.GridLines = GridLines.None; } catch (Exception ex) { UDFLib.WriteExceptionLog(ex); } }