protected void Generate_Crew_Agreement() { int iCrewID = int.Parse(getQueryString("CrewID")); int VoyID = int.Parse(getQueryString("VoyID")); int Contract_template_ID = 0; BLL_Crew_CrewDetails objCrewBLL = new BLL_Crew_CrewDetails(); System.Data.DataTable dt = objCrewBLL.Get_CrewAgreementData(iCrewID, VoyID); System.Data.DataTable dtPersonal = objCrewBLL.Get_CrewPersonalDetailsByID1(iCrewID); System.Data.DataTable dtNOK = objCrewBLL.Get_Crew_DependentsByCrewID(iCrewID, 1); string Photo = ""; int NOK_Mandatory = 0, Photo_Mandatory = 0; DataTable dtMandatorySettings = objCrewAdmin.GetMandatorySettings(); if (dtMandatorySettings != null && dtMandatorySettings.Rows.Count > 0) { if (dtMandatorySettings.Rows[0]["Value"].ToString() == "1") { NOK_Mandatory = 1; } if (dtMandatorySettings.Rows[1]["Value"].ToString() == "1") { Photo_Mandatory = 1; } } if (dtPersonal.Rows.Count > 0) { Photo = dtPersonal.Rows[0]["PhotoURL"].ToString(); } if (Photo_Mandatory == 1 && Photo == "") { Response.Write("<h1>Contract can not be printed at this moment as Photo is not yet uploaded for the Crew</h1>"); Response.End(); } else if (NOK_Mandatory == 1 && dtNOK.Rows.Count == 0) { Response.Write("<h1>Contract can not be printed at this moment as Next Of Kin details is not yet updated</h1>"); Response.End(); } else if (dt.Rows.Count == 0) { Response.Write("<h1>Contract can not be printed at this moment. Please enter the voyage details for the crew.</h1>"); Response.End(); } else { try { DataSet ds = BLL_PortageBill.Get_CrewWagesByVoyage_ForAgreement(iCrewID, VoyID); ds.Relations.Add(new DataRelation("Parent", ds.Tables[0].Columns["Effective_Date"], ds.Tables[1].Columns["Effective_Date"])); ds.Tables[1].TableName = "Child"; ds.Tables[1].DefaultView.RowFilter = "amount > 0"; dataview = ds.Tables[1].DefaultView; DataTable dtCheckSalaryComponent = ds.Tables[1].DefaultView.ToTable(); dtCheckSalaryComponent.DefaultView.RowFilter = " ( Name like '%//%' OR Name like '%&%') "; if (dtCheckSalaryComponent.DefaultView.ToTable().Rows.Count > 0) { string js = "alert('Contract cannot be generated as Salary Component contains special charaters. Update Salary Components to generate contract');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "errorsaving", js, true); } else { rpt2.DataSource = dataview; rpt2.DataBind(); System.Data.DataTable dtVoy = objCrewBLL.Get_CrewVoyages(iCrewID, VoyID); int Vessel_Flag = UDFLib.ConvertToInteger(dtVoy.Rows[0]["Vessel_Flag"].ToString()); int UserCompanyID = UDFLib.ConvertToInteger(Session["USERCOMPANYID"].ToString()); int VesselID = UDFLib.ConvertToInteger(dtVoy.Rows[0]["Vessel_ID"].ToString()); System.Data.DataSet dtCompany = objCrewBLL.Get_Crew_CompanyDetails(UDFLib.ConvertIntegerToNull(VesselID)); System.Data.DataTable dtTemplate; int ContractId = UDFLib.ConvertToInteger(dtVoy.Rows[0]["ContractId"].ToString()); dtTemplate = objBLLCrewContract.Get_ContractTemplate(ContractId); string TemplateText = ""; string FooterText1 = ""; string FooterText2 = ""; FooterText = "."; if (dtTemplate.Rows.Count > 0) { Contract_template_ID = UDFLib.ConvertToInteger(dtTemplate.Rows[0]["ID"].ToString()); FooterText = dtTemplate.Rows[0]["FooterText"].ToString(); TemplateText = "<template><br></br><br></br>" + dtTemplate.Rows[0]["template_text"].ToString() + "</template>"; TemplateText = TemplateText.Replace(" ", " "); TemplateText = TemplateText.Replace(" & ", " & "); TemplateText = TemplateText.Replace(" & ", " and "); TemplateText = TemplateText.Replace("’", "'"); TemplateText = TemplateText.Replace("“", """); TemplateText = TemplateText.Replace("”", """); TemplateText = TemplateText.Replace("…", "."); TemplateText = TemplateText.Replace("–", "–"); //TemplateText = TemplateText.Replace("<p></p>", ""); XmlDocument _doc = new XmlDocument(); _doc.LoadXml(TemplateText); XmlNodeList wages = _doc.GetElementsByTagName("wages"); if (wages != null && wages.Count > 0) { StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); rpt2.RenderControl(hw); string tblWages = "<table style='width:100%'><tr style='background-color: #D8D8D8; color: Black; font-weight: bold;'><td>Earning/Deduction</td><td>Name</td><td>Currency</td><td>Amount</td><td>Salary Type</td></tr>"; tblWages += sw.ToString().Replace("\n\r", "").Replace("\r\n", "").Replace(" & ", " & "); tblWages += "</table>"; wages[0].InnerXml = string.Format(tblWages); } TemplateText = _doc.InnerXml; string ST_NAME = "<input name=\"STAFF_NAME\" type=\"text\" value=\"NAME\" />"; string ST_ADD = "<input name=\"ADDRESS\" type=\"text\" value=\"ADDRESS\" />"; string ST_RANK = "<input name=\"STAFF_RANK\" type=\"text\" value=\"RANK\" />"; string ST_RANK1 = "<input name=\"STAFF_RANK\" type=\"text\" value=\"RANK\" />"; string VSL = "<input name=\"VESSEL\" type=\"text\" value=\"VESSEL\" />"; string VSL1 = "<input name=\"VESSEL\" type=\"text\" value=\"VESSEL\" />"; string DURATION = "<input name=\"DURATION\" type=\"text\" value=\"0 Month(s) 0 Days \" />"; string DURATION1 = "<input name=\"DURATION\" type=\"text\" value=\"0 Month(s) 0 Days \" />"; string ST_DAY = "<input name=\"START_DAY\" type=\"text\" value=\"0\" />"; string ST_MONTH = "<input name=\"START_MONTH\" type=\"text\" value=\"MMM yyyy\" />"; string ST_DAY1 = "<input name=\"START_DAY\" type=\"text\" value=\"0\" />"; string ST_MONTH1 = "<input name=\"START_MONTH\" type=\"text\" value=\"MMM yyyy\" />"; string STAFF_CODE = "<input name=\"STAFF_CODE\" type=\"text\" value=\"STAFF_CODE\" />"; string PASSPORT_NO = "<input name=\"PASSPORT_NO\" type=\"text\" value=\"PASSPORT_NO\" />"; string CONTRACT_DATE = "<input name=\"CONTRACT_DATE\" type=\"text\" />"; string DOB = "<input name=\"DOB\" type=\"text\" />"; string BIRTH_PLACE = "<input name=\"BIRTH_PLACE\" type=\"text\" value=\"BIRTH_PLACE\" />"; string NATIONALITY = "<input name=\"NATIONALITY\" type=\"text\" value=\"NATIONALITY\" />"; string SEAMAN_NO = "<input name=\"SEAMAN_NO\" type=\"text\" value=\"SEAMAN_NO\" />"; //string MGR_Name = "<input name=\"Manager_Name\" type=\"text\" value=\"Manager_Name\" />"; string Comp_Name = "<input name=\"COMPANY_NAME\" type=\"text\" value=\"COMPANY_NAME\" />"; string Comp_Address = "<input name=\"COMPANY_ADDRESS\" type=\"text\" value=\"COMPANY_ADDRESS\" />"; TemplateText = TemplateText.Replace(ST_NAME, dt.Rows[0]["CrewName"].ToString()); TemplateText = TemplateText.Replace(ST_ADD, dt.Rows[0]["Address"].ToString()); TemplateText = TemplateText.Replace(ST_RANK, dt.Rows[0]["Rank_Name"].ToString()); TemplateText = TemplateText.Replace(ST_RANK1, dt.Rows[0]["Rank_Name"].ToString()); TemplateText = TemplateText.Replace(VSL, dt.Rows[0]["Vessel_Name"].ToString()); TemplateText = TemplateText.Replace(VSL1, dt.Rows[0]["Vessel_Name"].ToString()); TemplateText = TemplateText.Replace(DURATION, dt.Rows[0]["MonthDays"].ToString()); TemplateText = TemplateText.Replace(DURATION1, dt.Rows[0]["MonthDays"].ToString()); TemplateText = TemplateText.Replace(STAFF_CODE, dt.Rows[0]["STAFF_CODE"].ToString()); TemplateText = TemplateText.Replace(PASSPORT_NO, dt.Rows[0]["Passport_Number"].ToString()); TemplateText = TemplateText.Replace(CONTRACT_DATE, dt.Rows[0]["Joining_Date"].ToString() == "" ? "________________" : dt.Rows[0]["Joining_Date"].ToString()); TemplateText = TemplateText.Replace(DOB, dt.Rows[0]["DOB"].ToString()); TemplateText = TemplateText.Replace(BIRTH_PLACE, dt.Rows[0]["BIRTH_PLACE"].ToString()); TemplateText = TemplateText.Replace(NATIONALITY, dt.Rows[0]["NATIONALITY"].ToString()); TemplateText = TemplateText.Replace(SEAMAN_NO, dt.Rows[0]["Seaman_Book_Number"].ToString()); TemplateText = TemplateText.Replace(Comp_Name, dtCompany.Tables[0].Rows[0]["Company_Name"].ToString()); TemplateText = TemplateText.Replace(Comp_Address, dtCompany.Tables[0].Rows[0]["Address"].ToString()); //TemplateText = TemplateText.Replace(MGR_Name, dtCompany.Tables[1].Rows[0]["Manager_Name"].ToString()); string JoinDate = ""; if (dt.Rows[0]["Joining_Date"].ToString() != "") { JoinDate = dt.Rows[0]["Joining_Date"].ToString(); DateTime DtJoining = DateTime.Parse(JoinDate); TemplateText = TemplateText.Replace(ST_DAY, DtJoining.ToString("dd")); TemplateText = TemplateText.Replace(ST_MONTH, DtJoining.ToString("MMMM") + " " + DtJoining.ToString("yyyy")); TemplateText = TemplateText.Replace(ST_DAY1, DtJoining.ToString("dd")); TemplateText = TemplateText.Replace(ST_MONTH1, DtJoining.ToString("MMMM") + " " + DtJoining.ToString("yyyy")); } else { TemplateText = TemplateText.Replace(ST_DAY, "_______"); TemplateText = TemplateText.Replace(ST_MONTH, "________________"); } if (TemplateText != "") { string sFileName = iCrewID.ToString() + "_" + VoyID.ToString() + "_1" + ".pdf"; string filePath = Server.MapPath("~/Uploads/CrewDocuments/") + sFileName; //string filePath = Server.MapPath("~/Uploads/CrewDocuments/") + Flag_Attach; //FileUpload1.SaveAs(filePath); System.Data.DataTable dtAgreement = objCrewBLL.Get_CrewAgreementRecords(iCrewID, VoyID, 0, GetSessionUserID()); DataRow[] dr = dtAgreement.Select("agreement_stage = 1"); if (dr.Length > 0) { ViewState["pagecount"] = dr[0]["PageCounts"].ToString(); } else { ViewState["pagecount"] = 0; } //-- write pdf file -- /* Added by pranali_070715 License Key EO.Pdf*/ EO.Pdf.Runtime.AddLicense("p+R2mbbA3bNoqbTC4KFZ7ekDHuio5cGz4aFZpsKetZ9Zl6TNHuig5eUFIPGe" + "tcznH+du5PflEuCG49jjIfewwO/o9dB2tMDAHuig5eUFIPGetZGb566l4Of2" + "GfKetZGbdePt9BDtrNzCnrWfWZekzRfonNzyBBDInbW6yuCwb6y9xtyxdabw" + "+g7kp+rp2g+9RoGkscufdePt9BDtrNzpz+eupeDn9hnyntzCnrWfWZekzQzr" + "peb7z7iJWZekscufWZfA8g/jWev9ARC8W7zTv/vjn5mkBxDxrODz/+ihb6W0" + "s8uud4SOscufWbOz8hfrqO7CnrWfWZekzRrxndz22hnlqJfo8h8="); EO.Pdf.HtmlToPdf.Options.AfterRenderPage = new EO.Pdf.PdfPageEventHandler(On_AfterRenderPage); EO.Pdf.HtmlToPdf.Options.HeaderHtmlFormat = "<center><img alt='' src='" + System.Configuration.ConfigurationManager.AppSettings["APP_URL"].ToString() + "/images/Company_logo.jpg' height='60px' /></center>"; EO.Pdf.HtmlToPdf.Options.FooterHtmlFormat = "<div style='color:white;z-order:100'><table style='width:100%'><tr><td style='width:33%;text-align:left;height:40px;vertical-align:bottom;'>" + FooterText1 + "</td><td style='width:34%;text-align:center;height:40px;vertical-align:bottom;'>Page {page_number} of {total_pages}</td><td style='width:33%;text-align:right;height:40px;vertical-align:bottom;'>" + FooterText2 + "</td></tr></table></div>"; EO.Pdf.HtmlToPdf.ConvertHtml(TemplateText, filePath); Random r1 = new Random(); string ver1 = r1.Next().ToString(); int Pagecount = getNumberOfPdfPages(filePath); int DocID = objCrewBLL.Insert_CrewAgreementRecord(iCrewID, VoyID, 1, Contract_template_ID, "Crew Agreement", sFileName, sFileName, GetSessionUserID(), Pagecount); hdnCurrentDocID.Value = DocID.ToString(); if (DocID > 0) { //--Delete the existing file try { System.IO.FileInfo fi = new FileInfo(filePath); fi.Delete(); } catch { } //-- write pdf file -- /* Added by pranali_070715 License Key EO.Pdf*/ EO.Pdf.Runtime.AddLicense("p+R2mbbA3bNoqbTC4KFZ7ekDHuio5cGz4aFZpsKetZ9Zl6TNHuig5eUFIPGe" + "tcznH+du5PflEuCG49jjIfewwO/o9dB2tMDAHuig5eUFIPGetZGb566l4Of2" + "GfKetZGbdePt9BDtrNzCnrWfWZekzRfonNzyBBDInbW6yuCwb6y9xtyxdabw" + "+g7kp+rp2g+9RoGkscufdePt9BDtrNzpz+eupeDn9hnyntzCnrWfWZekzQzr" + "peb7z7iJWZekscufWZfA8g/jWev9ARC8W7zTv/vjn5mkBxDxrODz/+ihb6W0" + "s8uud4SOscufWbOz8hfrqO7CnrWfWZekzRrxndz22hnlqJfo8h8="); EO.Pdf.HtmlToPdf.Options.AfterRenderPage = new EO.Pdf.PdfPageEventHandler(On_AfterRenderPage); EO.Pdf.HtmlToPdf.Options.HeaderHtmlFormat = "<center><img alt='' src='" + System.Configuration.ConfigurationManager.AppSettings["APP_URL"].ToString() + "/images/Company_logo.jpg' height='60px' /></center>"; EO.Pdf.HtmlToPdf.Options.FooterHtmlFormat = "<div style='color:white;z-order:100'><table style='width:100%'><tr><td style='width:33%;text-align:left;height:40px;vertical-align:bottom;'>" + FooterText1 + "</td><td style='width:34%;text-align:center;height:40px;vertical-align:bottom;'>Page {page_number} of {total_pages}</td><td style='width:33%;text-align:right;height:40px;vertical-align:bottom;'>" + FooterText2 + "</td></tr></table></div>"; EO.Pdf.HtmlToPdf.ConvertHtml(TemplateText, filePath); Random r = new Random(); string ver = r.Next().ToString(); lblMessage.Text = "Crew Agreement Generated. The agreement is yet to be signed by the office."; } Load_Agreements(); Load_Agreement_Status(); } else { lblMessage.Text = "Contract template do not have wages section"; } } else { lblMessage.Text = "Contract template not found for the vessel flag"; } } } catch (Exception ex) { lblMessage.Text = ex.Message; } } }
protected void Page_Load(object sender, EventArgs e) { if (GetSessionUserID() == 0) { Response.Redirect("~/account/login.aspx"); } else { UserAccessValidation(); } if (!IsPostBack) { DataTable dt = objCrewAdmin.GetInterviewSettings(); Load_RankList(); if (dt != null && dt.Rows.Count > 0) { chkInterview_Mandatory.Checked = Convert.ToBoolean(dt.Rows[0]["Interview_Mandatory"]); chkRejectedCheck.Checked = Convert.ToBoolean(dt.Rows[0]["Check_Rejected_Interview"]); } DataTable dtRankList = objRank.Get_RankMandatoryList(); gvRankList.DataSource = dtRankList; gvRankList.DataBind(); DataTable dtWages = objCrewAdmin.GetWagesSettings(); if (dtWages != null && dtWages.Rows.Count > 0) { chkNationality.Checked = Convert.ToBoolean(dtWages.Rows[0]["NationalityConsidered"]); chkRankScale.Checked = Convert.ToBoolean(dtWages.Rows[0]["RankScaleConsidered"]); chkVesselFlag.Checked = Convert.ToBoolean(dtWages.Rows[0]["VesselFlagConsidered"]); } DataTable dtMandatorySettings = objCrewAdmin.GetMandatorySettings(); if (dtMandatorySettings != null && dtMandatorySettings.Rows.Count > 0) { chkNOK.Checked = Convert.ToBoolean(dtMandatorySettings.Rows[0]["Value"]); chkCrewPhoto.Checked = Convert.ToBoolean(dtMandatorySettings.Rows[1]["Value"]); chkBankAccDetails.Checked = Convert.ToBoolean(dtMandatorySettings.Rows[2]["Value"]); chkSeniority.Checked = Convert.ToBoolean(dtMandatorySettings.Rows[3]["Value"]); ddlRank.SelectedValue = dtMandatorySettings.Rows[4]["Value"].ToString(); chkLeaveWithhold.Checked = Convert.ToBoolean(dtMandatorySettings.Rows[5]["Value"]); DataRow[] dr = dtMandatorySettings.Select("key_Name='EvaluationDigitalSignature'"); if (dr.Length > 0) { chkEvalSign.Checked = Convert.ToBoolean(dtMandatorySettings.Rows[6]["Value"]); } } DataTable dtDocument = objCrewAdmin.GetDocumentSettings(); if (dtDocument != null && dtDocument.Rows.Count > 0) { if (Convert.ToBoolean(dtDocument.Rows[0]["VesselFlagConsidered"]) == true) { rdbConsider.SelectedValue = "VesselFlag"; } else { rdbConsider.SelectedValue = "Vessel"; } chkSTCWDeck.Checked = Convert.ToBoolean(dtDocument.Rows[0]["STCW_Deck_Considered"]); chkSTCWEngine.Checked = Convert.ToBoolean(dtDocument.Rows[0]["STCW_Engine_Considered"]); } DataTable dtSeniorityReset = objCrewAdmin.GetSeniorityResetSettings(); if (dtSeniorityReset != null && dtSeniorityReset.Rows.Count > 0) { if (Convert.ToBoolean(dtSeniorityReset.Rows[0]["AutomaticResetConsidered"]) == true) { chkSeniorityReset.Checked = true; ddlSeniorityYear.Enabled = true; ddlSeniorityYear.SelectedValue = dtSeniorityReset.Rows[0]["ResetYears"].ToString(); } else { chkSeniorityReset.Checked = false; ddlSeniorityYear.Enabled = false; } } else { chkSeniorityReset.Checked = false; ddlSeniorityYear.Enabled = false; } } }