public async Task Run() { Stopwatch stopwatch1 = new Stopwatch(); Stopwatch stopwatch2 = new Stopwatch(); stopwatch1.Start(); await Question11.Method1Async(); long method1Result = stopwatch1.ElapsedMilliseconds; stopwatch2.Start(); await Question11.Method2Async(); long method2Result = stopwatch2.ElapsedMilliseconds; Console.WriteLine($"Method1Async is {method2Result - method1Result}ms faster than Method2Async"); }
static void Main(string[] args) { //var q = new Question3(); //Console.Write(q.LengthOfLongestSubstring("abcabcbb")); //Console.Write(q.LengthOfLongestSubstring("bbbbb")); //Console.Write(q.LengthOfLongestSubstring("pwwkew")); var y = new Question11(); var input = new int[9] { 1, 8, 6, 2, 5, 4, 8, 3, 7 }; Console.Write(y.MaxArea(input)); Console.ReadKey(); }
public async Task Run() { await Question11.RunAsync(); }
public void PDFGeneration() { MySqlConnection con1 = new MySqlConnection(); //SqlConnection con1 = new SqlConnection(); //con1.ConnectionString = ConfigurationManager.ConnectionStrings["DBconnection"].ConnectionString; //con1.ConnectionString = "Data Source = 123.176.34.15;port=4043;Integrated Security=False; Initial Catalog = survey; User ID = TestLogin; Password = ASD123!@#;"; con1.ConnectionString = _base.Decrypt(ConfigurationManager.ConnectionStrings["MysqlPath"].ConnectionString); //SqlDataAdapter da = new SqlDataAdapter("select * from question where submitted =1 AND MailStatus=0", con1); MySqlDataAdapter da = new MySqlDataAdapter("select * from question where submitted =1 AND MailStatus=0", con1); DataTable dt = new DataTable(); da.Fill(dt); Base @base = new Base(); foreach (DataRow dr in dt.Rows) { ReportDocument ss = new ReportDocument(); ConnectionInfo myConnectionInfo = new ConnectionInfo(); myConnectionInfo.AllowCustomConnection = true; myConnectionInfo.ServerName = _base.Decrypt(ConfigurationManager.AppSettings["SERVERNAME"].ToString()); myConnectionInfo.DatabaseName = _base.Decrypt(ConfigurationManager.AppSettings["DATABASE"].ToString()); myConnectionInfo.IntegratedSecurity = Convert.ToBoolean(ConfigurationManager.AppSettings["INTEGRATEDSECURITY"].ToString()); myConnectionInfo.UserID = _base.Decrypt(ConfigurationManager.AppSettings["USERID"].ToString()); myConnectionInfo.Password = _base.Decrypt(ConfigurationManager.AppSettings["PASSWORD"].ToString()); myConnectionInfo.Type = ConnectionInfoType.SQL; string Rpt_Path = System.Web.Hosting.HostingEnvironment.MapPath(ConfigurationManager.AppSettings["rptLocation"].ToString()); string outputPath = System.Web.Hosting.HostingEnvironment.MapPath(ConfigurationManager.AppSettings["OutputPath_pdf"].ToString()); try { JavaScriptSerializer scr = new JavaScriptSerializer(); Question2 Que2 = (Question2)scr.Deserialize(dr["la_q2"].ToString().Replace("\\", ""), typeof(Question2)); Question4 Que4 = (Question4)scr.Deserialize(dr["la_q4"].ToString().Replace("\\", ""), typeof(Question4)); Question7 Que7 = (Question7)scr.Deserialize(dr["la_q7"].ToString().Replace("\\", ""), typeof(Question7)); question8 Que8 = (question8)scr.Deserialize(dr["la_q8"].ToString().Replace("\\", ""), typeof(question8)); //List<string> Que9 = (List<string>)scr.Deserialize(dr["la_q9"].ToString().Replace("\\", ""), typeof(List<string>)); Question11 Que11 = (Question11)scr.Deserialize(dr["la_q11"].ToString().Replace("\\", ""), typeof(Question11)); //Question15 Que15 = (Question15)scr.Deserialize(dr["la_q15"].ToString().Replace("\\", ""), typeof(Question15)); FQ1 fq1 = (FQ1)scr.Deserialize(dr["fq1"].ToString().Replace("\\", ""), typeof(FQ1)); FQ2 fq2 = (FQ2)scr.Deserialize(dr["fq2"].ToString().Replace("\\", ""), typeof(FQ2)); FQ3 fq3 = (FQ3)scr.Deserialize(dr["fq3"].ToString().Replace("\\", ""), typeof(FQ3)); string que1 = dr["la_q1"].ToString(); string que3 = dr["la_q3"].ToString(); string que5 = dr["la_q5"].ToString(); string que6 = dr["la_q6"].ToString(); string que9 = dr["la_q9"].ToString(); string que10 = dr["la_q10"].ToString(); string que12 = dr["la_q12"].ToString(); string que13 = dr["la_q13"].ToString(); string que14 = dr["la_q14"].ToString(); string que15 = dr["la_q15"].ToString(); String User_ID = dr["User_ID"].ToString(); con1.Open(); string q = "Select * from users WHERE User_ID = " + User_ID + " "; MySqlCommand cmd3 = new MySqlCommand(q, con1); //var a = cmd3.ExecuteScalar(); MySqlDataReader reader = cmd3.ExecuteReader(); MySqlUser u = new MySqlUser(); while (reader.Read()) { u.FirstName = reader.GetString("First_Name"); u.SecoundName = reader.GetString("Second_Name"); u.Email = reader.GetString("Email"); u.Compnay = reader.GetString("Company_Name"); u.UserName = reader.GetString("User_Name"); } con1.Close(); CrystalReport crypt = new CrystalReport(); crypt.SetParameterValue("Company_Name", u.Compnay); crypt.SetParameterValue("User", u.FirstName + " " + u.SecoundName); crypt.SetParameterValue("Promantus_POC", "Promantus"); crypt.SetParameterValue("Q4.1", Que4.la_q4_1); crypt.SetParameterValue("Q4.2", Que4.la_q4_2); crypt.SetParameterValue("Q4.3", Que4.la_q4_3); //crypt.SetParameterValue("Q4.5", Que4.la_q4_5.ToString()); crypt.SetParameterValue("Q6", que6); crypt.SetParameterValue("Q11", Que11.la_q11_1.ToString() + " , " + Que11.la_q11_2.ToString()); crypt.SetParameterValue("Q12", que12); crypt.SetParameterValue("Q13", que13); crypt.SetParameterValue("Q14", que14); //crypt.SetParameterValue("Q15", Que15.la_q15_1 + " , " + Que15.la_q15_2.ToString()); crypt.SetParameterValue("Q15", que15); crypt.SetParameterValue("f1", fq1.f1); crypt.SetParameterValue("f2", fq1.f2); crypt.SetParameterValue("f3", fq1.f3); crypt.SetParameterValue("f4", fq2.f4); crypt.SetParameterValue("f5", fq2.f5); crypt.SetParameterValue("f6", fq2.f6); crypt.SetParameterValue("f7", fq3.f7); crypt.SetParameterValue("f8", fq3.f8); if (que3 == "no") { if (Que4.la_q4_1 != "SAP ECC6.0" && Que4.la_q4_1 != "EHP") { crypt.SetParameterValue("Img_Op1", true); crypt.SetParameterValue("Img_Op2", false); } else { crypt.SetParameterValue("Img_Op2", true); crypt.SetParameterValue("Img_Op1", false); } } foreach (CrystalDecisions.CrystalReports.Engine.Table myTable in crypt.Database.Tables) { TableLogOnInfo myTableLogonInfo = myTable.LogOnInfo; myTableLogonInfo.ConnectionInfo = myConnectionInfo; myTable.ApplyLogOnInfo(myTableLogonInfo); myTable.Location = myConnectionInfo.DatabaseName + ".dbo." + myTable.Location.Substring(myTable.Location.LastIndexOf(".") + 1); myTable.LogOnInfo.ConnectionInfo.ServerName = myConnectionInfo.ServerName; } CrystalReportViewer crb = new CrystalReportViewer(); crb.ReportSource = crypt; ss.Load(Rpt_Path); #region Q2 String Q2 = ""; if (Que2 != null) { if (Que2.la_q2_1 != "" && Que2.la_q2_1 != "undefined") { Q2 = Que2.la_q2_1 + ","; } if (Que2.la_q2_2 == "yes") { Q2 = Q2 + " Development,"; } if (Que2.la_q2_3 == "yes") { Q2 = Q2 + " Sandbox,"; } if (Que2.la_q2_4 == "yes") { Q2 = Q2 + " Quality / Test,"; } if (Que2.la_q2_5 == "yes") { Q2 = Q2 + " Production,"; } if (Que2.la_q2_6 != "") { Q2 = Q2 + Que2.la_q2_6;// " Any other System / Client in the SAP Landscape"; } #endregion Q2 ss.SetParameterValue("Q2", Q2); } ss.SetParameterValue("Q4.1", Que4.la_q4_1); ss.SetParameterValue("Q4.2", Que4.la_q4_2); ss.SetParameterValue("Q4.3", Que4.la_q4_3); //ss.SetParameterValue("Q4.5", Que4.la_q4_5.ToString()); ss.SetParameterValue("Q6", que6); if (que3 == "no") { if (Que4.la_q4_1 != "SAP ECC6.0" && Que4.la_q4_1 != "EHP") { ss.SetParameterValue("Img_Op1", true); ss.SetParameterValue("Img_Op2", false); } else { ss.SetParameterValue("Img_Op2", true); ss.SetParameterValue("Img_Op1", false); } } #region Q7 String Q7 = ""; if (Que7 != null) { if (Que7.la_q7_FI == "yes") { Q7 = Q7 + "Financials,"; } if (Que7.la_q7_CO == "yes") { Q7 = Q7 + " Controlling,"; } if (Que7.la_q7_MM == "yes") { Q7 = Q7 + " Materials Management,"; } if (Que7.la_q7_SD == "yes") { Q7 = Q7 + " Sales & Distribution,"; } if (Que7.la_q7_PP == "yes") { Q7 = Q7 + " Production Planning,"; } if (Que7.la_q7_QM == "yes") { Q7 = Q7 + " Quality Management,"; } if (Que7.la_q7_PS == "yes") { Q7 = " Project Systems,"; } if (Que7.la_q7_PM == "yes") { Q7 = Q7 + " Plant Maintenance,"; } if (Que7.la_q7_CS == "yes") { Q7 = Q7 + " Customer Service,"; } if (Que7.la_q7_HR == "yes") { Q7 = Q7 + " Human Resources,"; } if (Que7.la_q7_WM == "yes") { Q7 = Q7 + " Warehouse Management,"; } if (Que7.la_q7_LO_VC == "yes") { Q7 = Q7 + " Variant Configuration,"; } if (Que7.la_q7_LO_WTY == "yes") { Q7 = Q7 + " Warranty Management,"; } if (Que7.la_q7_LO_SPM == "yes") { Q7 = Q7 + " Spare Parts Management,"; } if (Que7.la_q7_other != "") { Q7 = Q7 + Que7.la_q7_other; } ss.SetParameterValue("Q7", Q7); } #endregion Q7 ss.SetParameterValue("Q11", Que11.la_q11_1.ToString() + " , " + Que11.la_q11_2.ToString()); ss.SetParameterValue("Q12", que12); ss.SetParameterValue("Q13", que13); ss.SetParameterValue("Q14", que14); ss.SetParameterValue("Q15", que15); //ss.SetParameterValue("Q15", Que15.la_q15_1 + " , " + Que15.la_q15_2.ToString()); ss.SetParameterValue("f1", fq1.f1); ss.SetParameterValue("f2", fq1.f2); ss.SetParameterValue("f3", fq1.f3); ss.SetParameterValue("f4", fq2.f4); ss.SetParameterValue("f5", fq2.f5); ss.SetParameterValue("f6", fq2.f6); ss.SetParameterValue("f7", fq3.f7); ss.SetParameterValue("f8", fq3.f8); ss.SetParameterValue("Company_Name", u.Compnay); ss.SetParameterValue("User", u.FirstName + " " + u.SecoundName); ss.SetParameterValue("Promantus_POC", "Promantus"); ExportOptions CrExportOptions; DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions(); PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions(); CrDiskFileDestinationOptions.DiskFileName = outputPath + User_ID + ".pdf"; CrExportOptions = ss.ExportOptions; { CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat; CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions; CrExportOptions.FormatOptions = CrFormatTypeOptions; } ss.Export(); // con1.Open(); // string q = "Select Email from users WHERE User_ID = " + User_ID + " "; // MySqlCommand cmd3 = new MySqlCommand(q, con1); //var a= cmd3.ExecuteScalar(); Boolean S = @base.AddQuestionnaire_Mail(Convert.ToInt32(User_ID), u.Email); con1.Open(); string myQuery = "UPDATE question SET MailStatus = " + S + " WHERE User_ID = " + User_ID + " "; MySqlCommand cmd2 = new MySqlCommand(myQuery, con1); cmd2.ExecuteNonQuery(); con1.Close(); } catch (Exception ex) { _log.createLog(ex, "-->CrystalReportPDF-->Loop" + ex.Message.ToString()); } finally { if (ss != null) { ss.Close(); ss.Dispose(); } } } }