public void RecieveSMS() { bool isRecieving = ((Form1)Application.OpenForms["Form1"]).IsRecievingProcessBusy; if (!isRecieving) { ((Form1)Application.OpenForms["Form1"]).IsRecievingProcessBusy = true; try { int LastRowIDFromWeb = new GhasedakWinService.niazpardaz.Send().GetInboxCount("c.alireza.a","2014",true); // connecting to service smsSoapClient sc = new smsSoapClient(); //niazpardaz.Send sc = new GhasedakWinService.niazpardaz.Send(); string str = sc.doReceiveSMS("mobtakeran", "mobtakeran", LastRowIDFromWeb); //------------- // parsing DataSet dataSet = new DataSet(); DataTable dataTable = new DataTable("sms"); dataTable.Columns.Add("rowID", typeof(string)); dataTable.Columns.Add("origAddr", typeof(string)); dataTable.Columns.Add("destAddr", typeof(string)); dataTable.Columns.Add("time", typeof(string)); dataTable.Columns.Add("message", typeof(string)); dataSet.Tables.Add(dataTable); System.IO.StringReader xmlSR = new System.IO.StringReader(str); dataSet.ReadXml(xmlSR, XmlReadMode.IgnoreSchema); //---------------------------- foreach (DataTable dt in dataSet.Tables) { foreach (DataRow dr in dt.Rows) { string msg = dr["message"].ToString(); string orgadd = dr["origAddr"].ToString(); int rowid =0; DateTime tm = DateTime.Now; if (dr["rowID"]!=null) rowid = Convert.ToInt32(dr["rowID"].ToString()); if (dr["time"] != null) tm = Convert.ToDateTime(dr["time"].ToString()); string destAddr = dr["destAddr"].ToString(); if (msg.Contains("..")) { msg = msg.Replace(".", " "); } //msg = Regex.Replace(msg, "..", ""); //msg = Regex.Replace(msg, "...", " "); //msg = Regex.Replace(msg, "....", " "); // msg = Regex.Replace(msg, ".....", " "); new tbl_sms_recievedTableAdapter().Insert( msg, orgadd, " ", rowid, tm, DateTime.Now, destAddr ); } } } catch (Exception __e) { string err = "Error in Recieving SMS Last RowID:" + __e.Message.ToString(); if (err.IndexOf("enough") > 10) { } else { ((Form1)Application.OpenForms["Form1"]).NewLog = err; } } ((Form1)Application.OpenForms["Form1"]).IsRecievingProcessBusy = false; } /* smsSoapClient sc = new smsSoapClient(); int lastRowID = 0; try { lastRowID = (int)new tbl_sms_recievedTableAdapter().GetLastRowID(); } catch (Exception ee) { lastRowID = 0; ((Form1)Application.OpenForms["Form1"]).NewLog = "Error in Recieving SMS Last RowID:" + ee.Message.ToString(); } string str = ""; try { str = sc.doReceiveSMS("dideban", "1234", lastRowID); } catch (Exception ee) { ((Form1)Application.OpenForms["Form1"]).NewLog = "Error in Recieving SMS SOAP :" + ee.Message.ToString(); } if (lastRowID > 0) { ((Form1)Application.OpenForms["Form1"]).LastRowIndex = lastRowID; } if (str != "") { DataSet dataSet = new DataSet(); DataTable dataTable = new DataTable("sms"); dataTable.Columns.Add("rowID", typeof(string)); dataTable.Columns.Add("origAddr", typeof(string)); dataTable.Columns.Add("destAddr", typeof(string)); dataTable.Columns.Add("time", typeof(string)); dataTable.Columns.Add("message", typeof(string)); dataSet.Tables.Add(dataTable); try { System.IO.StringReader xmlSR = new System.IO.StringReader(str); dataSet.ReadXml(xmlSR, XmlReadMode.IgnoreSchema); } catch (Exception ee) { ((Form1)Application.OpenForms["Form1"]).NewLog = "Error in Parsing SMS XML :" + ee.Message.ToString(); } foreach (DataTable dt in dataSet.Tables) { foreach (DataRow dr in dt.Rows) { try { new tbl_sms_recievedTableAdapter().Insert( dr["message"].ToString(), dr["origAddr"].ToString(), " ", Convert.ToInt32(dr["rowID"].ToString()), Convert.ToDateTime(dr["time"].ToString())); } catch (Exception ee) { ((Form1)Application.OpenForms["Form1"]).NewLog = "Error in Updating SMS Position in DB :" + ee.Message.ToString(); } } } }*/ }
public void SendIt() { if (((Form1)Application.OpenForms["Form1"]).IsSendingProcessBusy == false) { ((Form1)Application.OpenForms["Form1"]).IsSendingProcessBusy = true; string updatesql=""; //MainDataModuleTableAdapters.tbl_sms_sendTableAdapter unsendsmstbl = new tbl_sms_sendTableAdapter(); try { DataTable dt = new tbl_sms_sendTableAdapter().GetDataByPosition(0); updatesql = ""; string res = ""; //NiazPardaz.SendSoap ss = new NiazPardaz.SendSoap(); niazpardaz.Send ss = new GhasedakWinService.niazpardaz.Send(); foreach (DataRow dr in dt.Rows) { ss.SendSimpleSMS2( dr["s_username"].ToString(), dr["s_password"].ToString(), dr["s_cell_no"].ToString(), dr["s_smsCenterNo"].ToString(), dr["s_body"].ToString(), true); /* res = ss.doSendSMS( dr["s_username"].ToString(), dr["s_password"].ToString(), dr["s_smsCenterNo"].ToString(), dr["s_cell_no"].ToString(), dr["s_body"].ToString(), true);*/ Int64 _res = 0; try { _res = Convert.ToInt64(res); } catch { _res = -1; } //if (_res != -1) { Int64 gid = -1; try { if (dr["s_group_link"] != null) { gid = Convert.ToInt64(dr["s_group_link"].ToString()); } } catch { gid = -1; } updatesql = updatesql + " update tbl_sms_send set s_position=1,s_send_id=" + _res + " where s_id=" + dr["s_id"].ToString() + "; update tbl_sms_send_groups set sg_position=1 where sg_id=" + gid.ToString(); } } } catch (Exception __e) { ((Form1)Application.OpenForms["Form1"]).NewLog = "Error in creating SoapClient " + __e.Message; } if (updatesql != "") { System.Data.SqlClient.SqlConnection sqlc = new System.Data.SqlClient.SqlConnection(((Form1)Application.OpenForms["Form1"]).strConnectionString); sqlc.Open(); System.Data.SqlClient.SqlCommand sqlcm = new System.Data.SqlClient.SqlCommand(updatesql, sqlc); sqlcm.ExecuteNonQuery(); sqlc.Close(); } ((Form1)Application.OpenForms["Form1"]).IsSendingProcessBusy = false; } }