protected void btnMainStreets_Click(object sender, EventArgs e) { try { if (Session["UserID"].ToString() == "55") { lblFeedback.Text = ""; if (!bool.Parse(Session["canEdit"].ToString())) { throw new Exception(Feedback.NoPermissions()); } RequestID = Guid.NewGuid(); ThreadStart ts = new ThreadStart(CalculateMainStreets); Thread worker = new Thread(ts); worker.Start(); string url = string.Format("ResultMd.aspx?id={0}&All=0", RequestID.ToString()); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "RedirectScriptCoupon", "window.open('" + url + "', '_blank')", true); lblFeedback.Text = "تم الحساب بنجاح"; } else { lblFeedback.Text = Feedback.NoPermissions(); } } catch (Exception ex) { lblFeedback.Text = ex.Message; } }
static int DoJob(bool done, int Day, int Month, int Year, string serialPortNumber, byte slaveID, string sleepTime, DateTime PeriodDateFrom, DateTime PeriodDateTo, string numberAT, int param) { int RequestID; string queryString; Random rnd = new Random(); while (done == false) { RequestID = rnd.Next(100, 999); SendRequest_Mod(Day, Month, Year, RequestID, serialPortNumber, slaveID); Messaging($"Infromation for { numberAT } is requested { DateTime.Now.ToString() }. Request ID { RequestID.ToString() }\n"); Thread.Sleep(Convert.ToInt32(sleepTime)); var result = GetResponse_Mod(RequestID, serialPortNumber, slaveID); if (result.Item1 == 2) { try { queryString = $@"INSERT INTO MainTable(RequestDate, PeriodDateFrom, PeriodDateTo, At_Number, ProductVolume) VALUES ('{ DateTime.Now.ToString() }', '{ PeriodDateFrom.ToString() }', '{ PeriodDateTo.ToString() }', '{numberAT }', { result.Item2 })"; ConnectToDB(queryString, param); done = true; GlobalVariables.totalDone++; } catch (Exception ex) { Messaging(ex.ToString()); } } else { done = false; } } return(0); }