protected void btnSubmit_Click(object sender, EventArgs e) { string cellnumber = txtTo.Text; string message = txtComments.Text; SerialPort port = new SerialPort(); clsSMS objclsSMS = new clsSMS(); string portname = ConfigurationManager.AppSettings["ComPort"]; string baudrate = "57600"; port = objclsSMS.OpenPort(portname, baudrate); try { if (objclsSMS.sendMsg(port, portname, "57600", cellnumber, message)) { Label1.Text = "Sms-ul a fost trimis!"; } else { Label1.Text = "Trimitere esuata!"; } objclsSMS.ClosePort(port); } catch (Exception ex) { Label1.Text = ex.Message; objclsSMS.ClosePort(port); } }
public static void SendSms(Sms sms) { var smsArchiveManager = new SmsArchiveManager(ConfigurationManager.ConnectionStrings["fccl_v2"].ConnectionString); SerialPort port = new SerialPort(); clsSMS objclsSMS = new clsSMS(); string portname = ConfigurationManager.AppSettings["ComPort"].ToString(); string baudrate = "57600"; port = objclsSMS.OpenPort(portname, baudrate); try { if (objclsSMS.sendMsg(port, portname, "57600", sms.CellNr, sms.Message)) { Logger.Info(string.Format("SendSmsWorker | Sms-ul cu id-ul: {0} a fost trimis", sms.Id)); sms.DateSend = DateTime.Now; smsArchiveManager.UpdateSms(sms); } else { sms.TryNr++; smsArchiveManager.UpdateSms(sms); Logger.Error(string.Format("SendSmsWorker | Trimitere esuata a sms-ului cu id-ul: {0}", sms.Id)); } objclsSMS.ClosePort(port); } catch (Exception ex) { sms.TryNr++; smsArchiveManager.UpdateSms(sms); Logger.Error(string.Format("SendSmsWorker | Trimitere esuata a sms-ului cu id-ul: {0} error: {1}", sms.Id, ex.Message)); } finally { objclsSMS.ClosePort(port); } }
protected void Button1_Click(object sender, EventArgs e) { string adresafizicaserver = Server.MapPath("~"); string cale_rap = Server.MapPath("~/Documents/Sms/"); string cale_log = Server.MapPath("~/Documents/Sms/"); string logname = "LogSmsFerme" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt"; string smsname = "SmsTrimise" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt"; string fulllogname = adresafizicaserver + @"\Documents\Sms\" + logname; string fullsmsname = adresafizicaserver + @"\Documents\Sms\" + smsname; string datatestare = DataSelectie.Text; MostreDB mostre = new MostreDB(); List <MostreFabrica> mostresms = MostreFabrica.GetMostreSMS(datatestare); SerialPort port = new SerialPort(); clsSMS objclsSMS = new clsSMS(); string portname = ConfigurationManager.AppSettings["ComPort"].ToString(); string baudrate = "9600"; port = objclsSMS.OpenPort(portname, baudrate); StringBuilder updateSql = new StringBuilder("update mostretancuri set SentSms=1 where "); int countSms = 0; int countError = 0; mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "Data: " + DateTime.Now.ToString() + "**********"); mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "Data: " + DateTime.Now.ToString() + "**********"); int counter = 0; foreach (MostreFabrica ms in mostresms) { //create sms string // G:99,99;P:9,99;C:9,99;L:9,99;SUN:99,99;pH:9,99;Pct ing:-0,513; //Inhib:N;U:99,99;NTG:10000000;NCS:99999999 // G-grasime; P-proteina; C-cazeina; L-lactoza; SUN- subst. uscata negrasa; //Pct. ing- punct inghet; //Inhib- reziduuri inhibitori ce poate fi P-pozitiv sau N-negativ; U- uree //TODO : uncomment !!! if (!string.IsNullOrEmpty(ms.TelContact)) { if (ms.FermeNume.Length > 30) { ms.FermeNume = ms.FermeNume.Substring(0, 30); } StringBuilder sms = new StringBuilder(); sms.Append(ms.FermeNume + ";"); sms.Append("G:" + ms.Grasime + ";"); sms.Append("P:" + ms.Proteina + ";"); sms.Append("C:" + ms.Casein + ";"); sms.Append("L:" + ms.Lactoza + ";"); sms.Append("SUN:" + ms.Substu + ";"); sms.Append("pH:" + ms.Ph + ";"); sms.Append("Pct.ing.:" + ms.Puncti + ";"); sms.Append("Inhib:" + ms.Antib + ";"); sms.Append("U:" + ms.Urea + ";"); try { sms.Append("NTG:" + ms.NTG + "000;"); } catch { sms.Append("NTG:>10000000;"); } try { sms.Append("NCS:" + ms.NCS + "000;"); } catch { sms.Append("NCS:" + ms.NCS + ";"); } sms.Append("Cod:" + ms.CodBare); string cellnumber = Regex.Replace(ms.TelContact, @"[\s()-]", ""); cellnumber = (cellnumber.StartsWith("0") ? "+4" + cellnumber : cellnumber); try { bool res = objclsSMS.sendMsg(port, portname, "9600", cellnumber, sms.ToString()); if (res) { string strupdate = (countSms > 0) ? " or codbare ='" + ms.CodBare + "' " : " codbare ='" + ms.CodBare + "' "; updateSql.Append(strupdate); countSms++; mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, countSms + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString()); mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, sms.ToString()); } else { countError++; mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, countError + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString()); mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, sms.ToString()); } } catch (Exception ex) { mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, ex.Message + " - " + ex.StackTrace); } counter++; } } try { objclsSMS.ClosePort(port); } catch { } mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "End Data: " + DateTime.Now.ToString() + "**********"); mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "End Data: " + DateTime.Now.ToString() + "**********"); // update moste tancuri set sentsms=1 SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["fccl2ConnectionString"].ConnectionString); try { if (countSms > 0) { SqlCommand cmd = new SqlCommand(updateSql.ToString(), cnn); cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); } } catch (Exception exU) { Label1.Text = " Update MostreTancuri failed! " + exU.Message; } fissms.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + smsname; fissms.Visible = true; fislog.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + logname; fislog.Visible = true; }
protected void Button1_Click(object sender, EventArgs e) { string adresafizicaserver = Server.MapPath("~"); string cale_rap = Server.MapPath("~/Documents/Sms/"); string cale_log = Server.MapPath("~/Documents/Sms/"); string logname = "LogSmsFerme" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt"; string smsname = "SmsTrimise" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt"; string fulllogname = adresafizicaserver + @"\Documents\Sms\" + logname; string fullsmsname = adresafizicaserver + @"\Documents\Sms\" + smsname; DateTime datatestare = DateTime.Parse(DataSelectie.Text); MostreDB mostre = new MostreDB(); List <MostreFabrica> mostresms = MostreFabrica.GetMostreSMS(datatestare); SerialPort port = new SerialPort(); clsSMS objclsSMS = new clsSMS(); string portname = ConfigurationManager.AppSettings["ComPort"].ToString(); string baudrate = "9600"; port = objclsSMS.OpenPort(portname, baudrate); StringBuilder updateSql = new StringBuilder("update mostretancuri set SentSms=1 where "); int countSms = 0; int countError = 0; mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "Data: " + DateTime.Now.ToString() + "**********"); mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "Data: " + DateTime.Now.ToString() + "**********"); int counter = 0; foreach (MostreFabrica ms in mostresms) { // text sms //TODO : uncomment !!! if (!string.IsNullOrEmpty(ms.TelContact)) { if (ms.FermeNume.Length > 30) { ms.FermeNume = ms.FermeNume.Substring(0, 30); } // if (string.IsNullOrEmpty(ms.TelContact)) // ms.TelContact = "+40722217495"; StringBuilder sms = new StringBuilder(); // sms.Append(ms.FermeNume + " analizele sunt incarcate pe site"); sms.Append("In " + datatestare + " contul dvs. " + ms.FermeNume + " a fost actualizat cu rezultatele analizelor"); string cellnumber = Regex.Replace(ms.TelContact, @"[\s()-]", ""); cellnumber = (cellnumber.StartsWith("0") ? "+4" + cellnumber : cellnumber); try { //todo uncomment bool res = objclsSMS.sendMsg(port, portname, "9600", cellnumber, sms.ToString()); // bool res = true; if (res == true) { string cond = "(FermaID = " + ms.FermeId + " AND DataTestare = CONVERT(date, ''" + datatestare.ToShortDateString() + "', 103))"; string strupdate = (countSms > 0) ? " or " + cond : cond; updateSql.Append(strupdate); countSms++; mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, countSms + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString()); mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, sms.ToString()); } else { countError++; mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, countError + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString()); mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, sms.ToString()); } } catch (Exception ex) { mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, ex.Message + " - " + ex.StackTrace); } counter++; } } try { objclsSMS.ClosePort(port); } catch { } mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "End Data: " + DateTime.Now + "**********"); mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "End Data: " + DateTime.Now + "**********"); // update moste tancuri set sentsms=1 SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["fccl2ConnectionString"].ConnectionString); try { if (countSms > 0) { SqlCommand cmd = new SqlCommand(updateSql.ToString(), cnn); cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); } } catch (Exception exU) { Label1.Text = " Update MostreTancuri failed! " + exU.Message; } fissms.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + smsname; fissms.Visible = true; fislog.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + logname; fislog.Visible = true; }
public void Dispose() { objClsSms.ClosePort(phoneSerialPort); }