public string GetOrderInformation(string sales_doc_number) { String server = "LTDANHO-4057\\SQLEXPRESS_2016"; String database = "DSRBAGCOUNTER"; String username0 = "sa"; String password = "******"; using (var db = new ePOD_DBEntities1()) { List <dds_config> dds_configs = db.dds_config.ToList(); foreach (var config_info in dds_configs) { server = config_info.ip_address; database = config_info.database_name; username0 = config_info.username; password = config_info.password; String ConnStr = "Data Source=" + server + ";Initial Catalog=" + database + ";User ID=" + username0 + ";Password="******";;MultipleActiveResultSets=True;Application Name=EntityFramework"; using (SqlConnection con = new SqlConnection()) { String sql = @"select * from atc_data WHERE sales_doc_number = '" + sales_doc_number + "'"; con.ConnectionString = ConnStr; DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand(sql, con); da.Fill(dt); //TODO: if unableto connect to db, then error occurs if (dt.Rows.Count == 0) { return("NOT FOUND"); } //get transaction_data //foreach (DataRow row in dt.Rows) //{ // var bilVal = new damage_table() // { // BagCnt1 = row["AddBagCnt1"].ToString(), // BagCnt2 = row["AddBagCnt2"].ToString(), // BagCntRes1 = row["AddBagRes1"].ToString(), // BagCntRes2 = row["AddBagRes2"].ToString(), // DateTimeItem = DateTime.Parse(row["AdBgResDtTim"].ToString()), // LineNum = int.Parse(row["LineNum"].ToString()) // }; // prod_list.Add(bilVal); //} } } } return("SUCCESS"); }
public base_customer GetPhoneNo(string customer_no) { String server = "LTDANHO-4057\\SQLEXPRESS_2016"; String database = "DSRBAGCOUNTER"; String username0 = "sa"; String password = "******"; using (var db = new ePOD_DBEntities1()) { List <dds_config> dds_configs = db.dds_config.ToList(); foreach (var config_info in dds_configs) { server = config_info.ip_address; database = config_info.database_name; username0 = config_info.username; password = config_info.password; String ConnStr = "Data Source=" + server + ";Initial Catalog=" + database + ";User ID=" + username0 + ";Password="******";;MultipleActiveResultSets=True;Application Name=EntityFramework"; using (SqlConnection con = new SqlConnection()) { String sql = @"select * from customer WHERE customer_no = '" + customer_no + "' and sms_enabled = 1"; con.ConnectionString = ConnStr; DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand(sql, con); da.Fill(dt); //TODO: if unableto connect to db, then error occurs if (dt.Rows.Count == 0) { return(null); } //get transaction_data foreach (DataRow row in dt.Rows) { string phone = row["phone"].ToString(); string customer_name = row["customer_name"].ToString(); return(new base_customer() { customer_name = customer_name, phone = phone }); } } } } return(null); }
public TwiMLResult Respond(SmsRequest incomingMessage) { string message_var = incomingMessage.Body; if (message_var.Trim() == "") { var messagingResponse0 = new MessagingResponse(); messagingResponse0.Message("Invalid Request"); return(TwiML(messagingResponse0)); } var message = message_var.Trim().Split(' '); string code = ""; string damaged = ""; string caked = ""; string missing = ""; int damaged_int = 0; int caked_int = 0; int missing_int = 0; string complaints = ""; if (message.Length > 0) { code = message[0].Trim(); } var messagingResponse_en = new MessagingResponse(); if (code.ToUpper() == "ORDER") { if (message.Length < 2) { messagingResponse_en.Message("Please enter an Order Number for more information."); return(TwiML(messagingResponse_en)); } string sales_doc_number = message[1].Trim(); //GET Specific Order Information messagingResponse_en.Message("ORDER INFORMATION"); return(TwiML(messagingResponse_en)); } else if (code.ToUpper() == "ORDERS") { //GET LAst 5 Orders Information messagingResponse_en.Message("Last 5 Orders"); return(TwiML(messagingResponse_en)); } //CHECK for differenet codes for (int i = 1; i < message.Length; i++) { if (message[i].Trim() != "") { string token = message[i].Trim(); if (token.Substring(0, 1) == "d") { damaged = token.Substring(1, token.Length - 1); } else if (token.Substring(0, 1) == "c") { caked = token.Substring(1, token.Length - 1); } else if (token.Substring(0, 1) == "m") { missing = token.Substring(1, token.Length - 1); } } } complaints = message_var.Replace(code, ""); complaints = complaints.Replace("d" + damaged, ""); complaints = complaints.Replace("c" + caked, ""); complaints = complaints.Replace("m" + missing, ""); complaints = complaints.Trim(); Int32.TryParse(damaged, out damaged_int); Int32.TryParse(caked, out caked_int); Int32.TryParse(missing, out missing_int); using (var db = new ePOD_DBEntities1()) { baseSM previous_sms = db.baseSMS.Where(a => a.code_b == code && a.customer_no == incomingMessage.From).FirstOrDefault(); if (previous_sms == null) { var messagingResponse1 = new MessagingResponse(); messagingResponse1.Message("Invalid Code. Please enter the code that is displayed on the waybill."); return(TwiML(messagingResponse1)); } SMSResponse new_response = new SMSResponse() { caked = caked_int, code_b = code, missing = missing_int, damaged = damaged_int, complaints = complaints, created_on = DateTime.Now, sms_request_id = previous_sms.Id }; db.SMSResponses.Add(new_response); db.SaveChanges(); } var messagingResponse = new MessagingResponse(); messagingResponse.Message("Thank you for your response. We are happy to serve you."); return(TwiML(messagingResponse)); }
public void SendSMSviaGateWayPH(string atc_no, string delivery_no, string waybill_no, string customer_no, string customer_name, string phone, string code_b) { int sms_id = 0; using (var db = new ePOD_DBEntities1()) { baseSM previous_sms = db.baseSMS.Where(a => a.atc_no == atc_no && a.delivery_no == delivery_no).FirstOrDefault(); if (previous_sms != null) { //messge exists } else { //New Message baseSM new_sms = new baseSM() { atc_no = atc_no, code_a = "code_a", code_b = code_b, customer_name = customer_name, customer_no = customer_no, create_datetime = DateTime.Now, delivery_no = delivery_no, phone_no = phone, waybill_no = waybill_no, sms_status = true }; db.baseSMS.Add(new_sms); db.SaveChanges(); sms_id = new_sms.Id; } string msg = ""; msg += "Dear " + customer_name + ", Dispatch Details."; msg += "ATC: " + atc_no + ", "; msg += "Del: " + delivery_no + ", "; msg += "WB: " + waybill_no + ", "; msg += "Code: " + code_b + ". Reply with Code shown on Waybill."; string user = "******"; string pass = "******"; string port = "1"; //Get list of ports string destination = HttpUtility.UrlEncode(phone); // "%2B2348150886674";// "%2B2349030061590";// "+2349030061590"; //Destination must have +234X0 string content = HttpUtility.UrlEncode(msg); // "Message+from+c%23+through+SMS+GateWay";// "Message from c# through SMS GateWay"; string sms_api = "http://172.18.19.7//cgi/WebCGI?1500101="; sms_api += "&account=" + user; sms_api += "&password="******"&port=" + port; sms_api += "&destination=" + destination; sms_api += "&content=" + content; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@sms_api); request.Credentials = new NetworkCredential("apiuser", "apipass"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string return_response = new StreamReader(response.GetResponseStream()).ReadToEnd(); //-- MessageBox.Show("Done.\n\n" + return_response); baseSM current_sms = db.baseSMS.Where(a => a.Id == sms_id).FirstOrDefault(); if (current_sms != null) { current_sms.response = return_response; db.Entry(current_sms).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } Context.Response.Write(JsonConvert.SerializeObject(return_response, Formatting.Indented, new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.IsoDateFormat, ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); } }