/** * @brief タスクアイテムを生成 * @param taskID タスクID * @return タスクデータ * @details 特になし */ private task_data create_item(int taskID) { task_data my_task = new task_data(); my_task.setup( my_file.get_data(taskID, 0), my_file.get_data(taskID, 1), my_file.get_data(taskID, 2), my_file.get_data(taskID, 3) ); return(my_task); }
public void test_setup() { task_data obj = new task_data(); string ID = "test_ID"; string name = "test_name"; string detail = "test_detail"; string status = "test_status"; obj.setup(ID, name, detail, status); Assert.AreEqual(ID, obj.ID); Assert.AreEqual(name, obj.name); Assert.AreEqual(detail, obj.detail); Assert.AreEqual(status, obj.status); }
private void button1_Click(object sender, RoutedEventArgs e) { var webClient = new WebClient(); string server_time = webClient.DownloadString("http://fuzonmedia.com/BC_Service_Important/server_time.txt"); //Configure the ProgressBar ProgressBar1.Minimum = 0; ProgressBar1.Value = 0; //Stores the value of the ProgressBar double p_value = 0; UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(ProgressBar1.SetValue); List <task_data> freport = new List <task_data>(); process_status.Content = "Please wait while we creating task ...."; button1.Content = "Wait..."; button1.IsEnabled = false; if (MessageBox.Show("Are you sure want to proceed?", "Warning!", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { try { ProgressBar1.Minimum = 0; ProgressBar1.Value = 0; ProgressBar1.Maximum = 50; WebRequest req_big_order_count = WebRequest.Create(big_storeurl.Text + "orders?status_id=11"); // WebRequest req_big_order_count = WebRequest.Create(big_storeurl.Text + "orders/2338"); HttpWebRequest httpreq_order_count = (HttpWebRequest)req_big_order_count; httpreq_order_count.Method = "GET"; httpreq_order_count.ContentType = "text/xml; charset=utf-8"; double timestamp = Convert.ToDouble(server_time); // First make a System.DateTime equivalent to the UNIX Epoch. System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); // Add the number of seconds in UNIX timestamp to be converted. dateTime = dateTime.AddSeconds(timestamp); // The dateTime now contains the right date/time so to format the string, // use the standard formatting methods of the DateTime object. string printDate = dateTime.GetDateTimeFormats()[104]; httpreq_order_count.IfModifiedSince = Convert.ToDateTime(printDate); httpreq_order_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_order = (HttpWebResponse)httpreq_order_count.GetResponse(); StreamReader rdr_product_count = new StreamReader(res_order.GetResponseStream()); string result_order = rdr_product_count.ReadToEnd(); //textBox1.Text = result_order; if (res_order.StatusCode == HttpStatusCode.OK || res_order.StatusCode == HttpStatusCode.Accepted) { XDocument doc_orders = XDocument.Parse(result_order); foreach (XElement order_data in doc_orders.Descendants("order")) { p_value += 1; Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, p_value }); task_data tsata = new task_data(); tsata.order_id = order_data.Element("id").Value.ToString(); // MessageBox.Show(tsata.order_id); tsata.c_message = order_data.Element("customer_message").Value.ToString().Replace("\"", "\\\"").Replace("\r\n", "\\n").Replace("\n", "\\n"); tsata.c_name = order_data.Element("billing_address").Element("first_name").Value.ToString() + " " + order_data.Element("billing_address").Element("last_name").Value.ToString(); tsata.total_cost = Convert.ToDouble(order_data.Element("total_inc_tax").Value.ToString()).ToString("0.00", CultureInfo.InvariantCulture); tsata.c_email = order_data.Element("billing_address").Element("email").Value.ToString(); tsata.c_phone = order_data.Element("billing_address").Element("phone").Value.ToString(); // MessageBox.Show("shiipping_Addes"); WebRequest req_big_shipping_count = WebRequest.Create(big_storeurl.Text + "orders/" + tsata.order_id + "/shippingaddresses"); HttpWebRequest httpreq_shipping_count = (HttpWebRequest)req_big_shipping_count; httpreq_shipping_count.Method = "GET"; httpreq_shipping_count.ContentType = "text/xml; charset=utf-8"; httpreq_shipping_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_shipping = (HttpWebResponse)httpreq_shipping_count.GetResponse(); StreamReader rdr_shipping_count = new StreamReader(res_shipping.GetResponseStream()); string result_shipping = rdr_shipping_count.ReadToEnd(); if (res_shipping.StatusCode == HttpStatusCode.OK || res_shipping.StatusCode == HttpStatusCode.Accepted) { XDocument doc_shippings = XDocument.Parse(result_shipping); foreach (XElement order_shipping in doc_shippings.Descendants("address")) { tsata.shipping_address = order_shipping.Element("street_1").Value.ToString() + " " + order_shipping.Element("street_2").Value.ToString(); tsata.shipping_address += "\\n" + order_shipping.Element("city").Value.ToString() + "," + order_shipping.Element("state").Value.ToString() + "," + order_shipping.Element("zip").Value.ToString(); break; } } // MessageBox.Show("Products"); WebRequest req_big_productcount = WebRequest.Create(big_storeurl.Text + "orders/" + tsata.order_id + "/products"); HttpWebRequest httpreq_product_count = (HttpWebRequest)req_big_productcount; httpreq_product_count.Method = "GET"; httpreq_product_count.ContentType = "text/xml; charset=utf-8"; httpreq_product_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_product = (HttpWebResponse)httpreq_product_count.GetResponse(); StreamReader rdr_product_data = new StreamReader(res_product.GetResponseStream()); string result_product = rdr_product_data.ReadToEnd(); // MessageBox.Show(result_product); if (res_product.StatusCode == HttpStatusCode.OK || res_product.StatusCode == HttpStatusCode.Accepted) { XDocument doc_products = XDocument.Parse(result_product); foreach (XElement order_product in doc_products.Descendants("product")) { string pr_op = ""; foreach (XElement order_product_options in order_product.Descendants("product_options").Descendants("option")) { // MessageBox.Show(order_product_options.Element("display_value").Value.ToString()); pr_op += order_product_options.Element("display_value").Value.ToString().Replace("\"", "\\\"") + " "; } tsata.item_details += order_product.Element("name").Value.ToString().Replace("\"", "\\\"") + " X " + order_product.Element("quantity").Value.ToString() + " - " + pr_op + " - $" + Convert.ToDouble(order_product.Element("price_inc_tax").Value.ToString()).ToString("0.00", CultureInfo.InvariantCulture) + "\\n"; } } // MessageBox.Show(tsata.shipping_address); // MessageBox.Show(tsata.item_details); // MessageBox.Show("Asana Set"); WebRequest req_asana = WebRequest.Create("https://app.asana.com/api/1.0/tasks"); HttpWebRequest httpreq_asana = (HttpWebRequest)req_asana; httpreq_asana.Method = "POST"; httpreq_asana.ContentType = "application/json"; httpreq_asana.Headers.Add("Authorization", "Basic " + asana_APIKey.Text); Stream str_asana = httpreq_asana.GetRequestStream(); StreamWriter strwriter_asana = new StreamWriter(str_asana, Encoding.ASCII); // string soaprequest_asana = "{\"data\":{\"workspace\":"+workSpaceID.Text+",\"name\":\""+"(#"+tsata.order_id+") "+tsata.c_name+" $"+tsata.total_cost+"\",\"notes\":\""+tsata.c_email+" - "+ tsata.c_phone +"\\n\\n" + tsata.shipping_address+"\\n\\n" +tsata.item_details+"\",\"assignee\":"+Assignee_ID.Text+"}}"; string soaprequest_asana = "{\"data\":{\"workspace\":" + workSpaceID.Text + ",\"name\":\"" + "(#" + tsata.order_id + ") " + tsata.c_name + " $" + tsata.total_cost + "\",\"notes\":\"" + tsata.c_email + " - " + tsata.c_phone + "\\n\\n" + tsata.shipping_address + "\\n\\n" + tsata.item_details + "\\n\\n" + tsata.c_message + "\",\"projects\":[812474455499]}}"; // MessageBox.Show(soaprequest_asana); textBox1.Text = soaprequest_asana.ToString(); strwriter_asana.Write(soaprequest_asana.ToString()); strwriter_asana.Close(); HttpWebResponse res_asana = (HttpWebResponse)httpreq_asana.GetResponse(); StreamReader rdr_asana = new StreamReader(res_asana.GetResponseStream()); string result_asana_task = rdr_asana.ReadToEnd(); // MessageBox.Show(result_asana_task); freport.Add(tsata); } } WebRequest req_big_time = WebRequest.Create(big_storeurl.Text + "time"); HttpWebRequest httpreq_time = (HttpWebRequest)req_big_time; httpreq_time.Method = "GET"; httpreq_time.ContentType = "text/xml; charset=utf-8"; httpreq_time.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_time = (HttpWebResponse)httpreq_time.GetResponse(); StreamReader rdr_time = new StreamReader(res_time.GetResponseStream()); string result_time = rdr_time.ReadToEnd(); // MessageBox.Show(result_time); if (res_time.StatusCode == HttpStatusCode.OK || res_time.StatusCode == HttpStatusCode.Accepted) { XDocument doc_time = XDocument.Parse(result_time); string stime = doc_time.Element("time").Element("time").Value.ToString(); var webClient_1 = new WebClient(); string readHtml_1 = webClient_1.DownloadString("http://fuzonmedia.com/BC_Service_Important/getData.php?time=" + stime); // File.WriteAllText("server_time.txt", stime); } p_value = 50; Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, p_value }); MessageBox.Show("Task Completed"); process_status.Content = "Task Completed"; button1.IsEnabled = true; button1.Content = "Create Task"; } catch (Exception ex) { if (ex.Message == "The remote server returned an error: (304) Not Modified.") { WebRequest req_big_time = WebRequest.Create(big_storeurl.Text + "time"); HttpWebRequest httpreq_time = (HttpWebRequest)req_big_time; httpreq_time.Method = "GET"; httpreq_time.ContentType = "text/xml; charset=utf-8"; httpreq_time.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_time = (HttpWebResponse)httpreq_time.GetResponse(); StreamReader rdr_time = new StreamReader(res_time.GetResponseStream()); string result_time = rdr_time.ReadToEnd(); // MessageBox.Show(result_time); if (res_time.StatusCode == HttpStatusCode.OK || res_time.StatusCode == HttpStatusCode.Accepted) { XDocument doc_time = XDocument.Parse(result_time); string stime = doc_time.Element("time").Element("time").Value.ToString(); var webClient_1 = new WebClient(); string readHtml_1 = webClient_1.DownloadString("http://fuzonmedia.com/BC_Service_Important/getData.php?time=" + stime); // File.WriteAllText("server_time.txt", stime); } MessageBox.Show("No New Orders yet "); process_status.Content = "No New Orders yet"; } else { MessageBox.Show(ex.Message.ToString()); process_status.Content = "Error :" + ex.Message.ToString(); } button1.IsEnabled = true; button1.Content = "Create Task"; // textBox1.Text = ex.Message.ToString(); } } else { button1.IsEnabled = true; process_status.Content = ""; button1.Content = "Create Task"; } }
private void button9_Click(object sender, RoutedEventArgs e) { if (added_order.Items.IsEmpty == false && Route_name.Text != "") { ProgressBar1.Minimum = 0; ProgressBar1.Value = 0; ProgressBar1.Maximum = added_order.Items.Count; double p_value = 0; UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(ProgressBar1.SetValue); List <task_data> task_list = new List <task_data>(); if (added_order.Items.Count > 0) { // List<result_data> rdata = new List<result_data>(); process_status.Content = "Please wait while we creating route ...."; Import_viamente.Content = "Wait..."; Import_viamente.IsEnabled = false; if (MessageBox.Show("Are you sure want to proceed?", "Warning!", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { for (int cnt = 0; cnt < added_order.Items.Count; cnt++) { p_value += 1; Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, p_value }); task_data tsata = new task_data(); tsata.order_id = ((ListBoxItem)added_order.Items[cnt]).Uid; try { WebRequest req_big_order_count = WebRequest.Create(big_storeurl.Text + "orders/" + ((ListBoxItem)added_order.Items[cnt]).Uid); HttpWebRequest httpreq_order_count = (HttpWebRequest)req_big_order_count; httpreq_order_count.Method = "GET"; httpreq_order_count.ContentType = "text/xml; charset=utf-8"; httpreq_order_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_order = (HttpWebResponse)httpreq_order_count.GetResponse(); StreamReader rdr_product_count = new StreamReader(res_order.GetResponseStream()); string result_order = rdr_product_count.ReadToEnd(); //textBox1.Text = result_order; bool order_send = false; if (res_order.StatusCode == HttpStatusCode.OK || res_order.StatusCode == HttpStatusCode.Accepted) { XDocument doc_orders = XDocument.Parse(result_order); foreach (XElement order_data in doc_orders.Descendants("order")) { // MessageBox.Show(tsata.order_id); // tsata.c_message = order_data.Element("customer_message").Value.ToString().Replace("\"", "\\\"").Replace("\r\n", "\\n").Replace("\n", "\\n"); tsata.c_name = order_data.Element("billing_address").Element("first_name").Value.ToString() + " " + order_data.Element("billing_address").Element("last_name").Value.ToString(); tsata.total_cost = Convert.ToDouble(order_data.Element("total_inc_tax").Value.ToString()).ToString("0.00", CultureInfo.InvariantCulture); tsata.c_phone = order_data.Element("billing_address").Element("phone").Value.ToString(); // MessageBox.Show("shiipping_Addes"); WebRequest req_big_shipping_count = WebRequest.Create(big_storeurl.Text + "orders/" + tsata.order_id + "/shippingaddresses"); HttpWebRequest httpreq_shipping_count = (HttpWebRequest)req_big_shipping_count; httpreq_shipping_count.Method = "GET"; httpreq_shipping_count.ContentType = "text/xml; charset=utf-8"; httpreq_shipping_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_shipping = (HttpWebResponse)httpreq_shipping_count.GetResponse(); StreamReader rdr_shipping_count = new StreamReader(res_shipping.GetResponseStream()); string result_shipping = rdr_shipping_count.ReadToEnd(); if (res_shipping.StatusCode == HttpStatusCode.OK || res_shipping.StatusCode == HttpStatusCode.Accepted) { XDocument doc_shippings = XDocument.Parse(result_shipping); foreach (XElement order_shipping in doc_shippings.Descendants("address")) { tsata.shipping_address = order_shipping.Element("street_1").Value.ToString() + " " + order_shipping.Element("street_2").Value.ToString(); tsata.shipping_address += " , " + order_shipping.Element("city").Value.ToString() + " , " + order_shipping.Element("state").Value.ToString() + " " + order_shipping.Element("zip").Value.ToString() + " , " + order_shipping.Element("country").Value.ToString(); tsata.oid_status = true; break; } } } } } catch (Exception ex) { // MessageBox.Show(ex.Message.ToString()); // rdata.Add(new result_data { order_id = ((ListBoxItem)added_order.Items[cnt]).Uid, status = ex.Message.ToString() }); tsata.oid_status = false; } task_list.Add(tsata); } display_result.ItemsSource = task_list; /// Import data into Viamente /// if (task_list.Count() > 0) { string order_import_json = ""; int order_count = 0; try { foreach (task_data single_task in task_list) { if (single_task.oid_status) { if (order_count > 0) { order_import_json += ",{\"name\": \"" + single_task.c_name + "\",\"serviceTimeMin\": 5 ,\"location\": {\"address\": \"" + single_task.shipping_address + "\"},\"customFields\": {\"orderID\": \"" + single_task.order_id + "\",\"phoneNumber\": \"" + single_task.c_phone + "\"}}"; } else { order_import_json += "{\"name\": \"" + single_task.c_name + "\",\"serviceTimeMin\": 5 ,\"location\": {\"address\": \"" + single_task.shipping_address + "\"},\"customFields\": {\"orderID\": \"" + single_task.order_id + "\",\"phoneNumber\": \"" + single_task.c_phone + "\"}}"; } order_count++; } } if (order_import_json != "") { // API call WebRequest req_viamente = WebRequest.Create("https://vrp.viamente.com/api/vrp/v2/routeplans?key=" + Viamente_apiKey.Text); HttpWebRequest httpreq_viamente = (HttpWebRequest)req_viamente; httpreq_viamente.Method = "POST"; httpreq_viamente.ContentType = "application/json"; // httpreq_mandrill.Headers.Add("Authorization", "Basic " + asana_APIKey.Text); Stream str_viamente = httpreq_viamente.GetRequestStream(); StreamWriter strwriter_viamente = new StreamWriter(str_viamente, Encoding.ASCII); string soaprequest_viamente = "{\"name\": \"" + Route_name.Text + "\",\"orders\": [" + order_import_json + "]}"; //MessageBox.Show(soaprequest_mandrill); strwriter_viamente.Write(soaprequest_viamente.ToString()); strwriter_viamente.Close(); HttpWebResponse res_viamentel = (HttpWebResponse)httpreq_viamente.GetResponse(); if (res_viamentel.StatusCode == HttpStatusCode.OK || res_viamentel.StatusCode == HttpStatusCode.Accepted) { StreamReader rdr_viamente = new StreamReader(res_viamentel.GetResponseStream()); string result_viamente = rdr_viamente.ReadToEnd(); MessageBox.Show("Route Created with Orders"); process_status.Content = "Route Created with Orders"; } } } catch (Exception exx) { MessageBox.Show(exx.Message); process_status.Content = exx.Message; } } else { process_status.Content = ""; Import_viamente.IsEnabled = true; Import_viamente.Content = "No Valid Order to import "; } display_result.ItemsSource = task_list; Import_viamente.IsEnabled = true; Import_viamente.Content = "Import Order Into Viamente"; } else { process_status.Content = ""; Import_viamente.IsEnabled = true; Import_viamente.Content = "Import Order Into Viamente"; } } else { MessageBox.Show("Please Enter at least one order ID "); } } else { MessageBox.Show("Please input a Route Name & order ID to process"); } }
private void importCallEm_Click(object sender, RoutedEventArgs e) { if (added_order.Items.Count > 0 && recorder_audio.SelectedIndex >= 0) { // Process // MessageBox.Show("Processing"); if (added_order.Items.IsEmpty == false && broadcastName.Text != "") { ProgressBar1.Minimum = 0; ProgressBar1.Value = 0; ProgressBar1.Maximum = added_order.Items.Count; double p_value = 0; UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(ProgressBar1.SetValue); List <task_data> task_list = new List <task_data>(); if (added_order.Items.Count > 0) { // List<result_data> rdata = new List<result_data>(); process_status.Content = "Please wait while we creating Broadcast List ...."; importCallEm.Content = "Wait..."; importCallEm.IsEnabled = false; if (MessageBox.Show("Are you sure want to proceed?", "Warning!", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { for (int cnt = 0; cnt < added_order.Items.Count; cnt++) { p_value += 1; Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, p_value }); task_data tsata = new task_data(); tsata.order_id = ((ListBoxItem)added_order.Items[cnt]).Uid; try { WebRequest req_big_order_count = WebRequest.Create(big_storeurl.Text + "orders/" + ((ListBoxItem)added_order.Items[cnt]).Uid); HttpWebRequest httpreq_order_count = (HttpWebRequest)req_big_order_count; httpreq_order_count.Method = "GET"; httpreq_order_count.ContentType = "text/xml; charset=utf-8"; httpreq_order_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_order = (HttpWebResponse)httpreq_order_count.GetResponse(); StreamReader rdr_product_count = new StreamReader(res_order.GetResponseStream()); string result_order = rdr_product_count.ReadToEnd(); //textBox1.Text = result_order; bool order_send = false; if (res_order.StatusCode == HttpStatusCode.OK || res_order.StatusCode == HttpStatusCode.Accepted) { XDocument doc_orders = XDocument.Parse(result_order); foreach (XElement order_data in doc_orders.Descendants("order")) { // MessageBox.Show(tsata.order_id); // tsata.c_message = order_data.Element("customer_message").Value.ToString().Replace("\"", "\\\"").Replace("\r\n", "\\n").Replace("\n", "\\n"); tsata.c_name = order_data.Element("billing_address").Element("first_name").Value.ToString() + " " + order_data.Element("billing_address").Element("last_name").Value.ToString(); tsata.total_cost = Convert.ToDouble(order_data.Element("total_inc_tax").Value.ToString()).ToString("0.00", CultureInfo.InvariantCulture); tsata.c_phone = order_data.Element("billing_address").Element("phone").Value.ToString(); // MessageBox.Show("shiipping_Addes"); WebRequest req_big_shipping_count = WebRequest.Create(big_storeurl.Text + "orders/" + tsata.order_id + "/shippingaddresses"); HttpWebRequest httpreq_shipping_count = (HttpWebRequest)req_big_shipping_count; httpreq_shipping_count.Method = "GET"; httpreq_shipping_count.ContentType = "text/xml; charset=utf-8"; httpreq_shipping_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_shipping = (HttpWebResponse)httpreq_shipping_count.GetResponse(); StreamReader rdr_shipping_count = new StreamReader(res_shipping.GetResponseStream()); string result_shipping = rdr_shipping_count.ReadToEnd(); if (res_shipping.StatusCode == HttpStatusCode.OK || res_shipping.StatusCode == HttpStatusCode.Accepted) { XDocument doc_shippings = XDocument.Parse(result_shipping); foreach (XElement order_shipping in doc_shippings.Descendants("address")) { tsata.shipping_address = order_shipping.Element("street_1").Value.ToString() + " " + order_shipping.Element("street_2").Value.ToString(); tsata.shipping_address += " , " + order_shipping.Element("city").Value.ToString() + " , " + order_shipping.Element("state").Value.ToString() + " " + order_shipping.Element("zip").Value.ToString() + " , " + order_shipping.Element("country").Value.ToString(); tsata.oid_status = true; break; } } } } } catch (Exception ex) { // MessageBox.Show(ex.Message.ToString()); // rdata.Add(new result_data { order_id = ((ListBoxItem)added_order.Items[cnt]).Uid, status = ex.Message.ToString() }); tsata.oid_status = false; } task_list.Add(tsata); } display_result.ItemsSource = task_list; if (task_list.Count() > 0) { string phone_numbers_import = ""; int order_count = 0; try { foreach (task_data single_task in task_list) { if (single_task.oid_status) { if (order_count > 0) { phone_numbers_import += "," + single_task.c_phone; } else { phone_numbers_import += single_task.c_phone; } order_count++; } } if (phone_numbers_import != "") { // API call create broadcast list in Call-Em string API_URI_acll_Em_all_endpoint = ""; if (call_test.IsChecked == true) { API_URI_acll_Em_all_endpoint = API_URI_acll_Em_all_saging; } else { API_URI_acll_Em_all_endpoint = API_URI_acll_Em_all_live; } WebRequest req_call_em = WebRequest.Create(API_URI_acll_Em_all_endpoint); HttpWebRequest httpreq_call_em = (HttpWebRequest)req_call_em; httpreq_call_em.Method = "POST"; httpreq_call_em.ContentType = "text/xml; charset=utf-8"; // httpreq_mandrill.Headers.Add("Authorization", "Basic " + asana_APIKey.Text); Stream str_call_em = httpreq_call_em.GetRequestStream(); StreamWriter strwriter_call_em = new StreamWriter(str_call_em, Encoding.ASCII); //string soaprequest_call_em = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://call-em-all.com/\"><SOAP-ENV:Body><ns1:ExtCreateBroadcast><ns1:myRequest><ns1:username>" + callEm_apiKey1.Text + "</ns1:username><ns1:pin>" + callEm_Password.Text + "</ns1:pin><ns1:broadcastName>" + broadcastName.Text + "</ns1:broadcastName><ns1:broadcastType>1</ns1:broadcastType><ns1:commaDelimitedPhoneNumbers>" + phone_numbers_import + "</ns1:commaDelimitedPhoneNumbers><ns1:messageID>" + ((ListBoxItem)recorder_audio.Items[recorder_audio.SelectedIndex]).Uid + "</ns1:messageID><ns1:phoneNumberSource>3</ns1:phoneNumberSource><ns1:launchDateTime>03/18/2016 10:10:10 AM</ns1:launchDateTime></ns1:myRequest></ns1:ExtCreateBroadcast></SOAP-ENV:Body></SOAP-ENV:Envelope>"; string soaprequest_call_em = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://call-em-all.com/\"><SOAP-ENV:Body><ns1:ExtCreateBroadcast><ns1:myRequest><ns1:username>" + callEm_apiKey1.Text + "</ns1:username><ns1:pin>" + callEm_Password.Text + "</ns1:pin><ns1:broadcastName>" + broadcastName.Text + "</ns1:broadcastName><ns1:broadcastType>1</ns1:broadcastType><ns1:commaDelimitedPhoneNumbers>" + phone_numbers_import + "</ns1:commaDelimitedPhoneNumbers><ns1:messageID>" + ((ListBoxItem)recorder_audio.Items[recorder_audio.SelectedIndex]).Uid + "</ns1:messageID><ns1:phoneNumberSource>3</ns1:phoneNumberSource></ns1:myRequest></ns1:ExtCreateBroadcast></SOAP-ENV:Body></SOAP-ENV:Envelope>"; //MessageBox.Show(soaprequest_mandrill); strwriter_call_em.Write(soaprequest_call_em.ToString()); strwriter_call_em.Close(); HttpWebResponse res_call_em = (HttpWebResponse)httpreq_call_em.GetResponse(); if (res_call_em.StatusCode == HttpStatusCode.OK || res_call_em.StatusCode == HttpStatusCode.Accepted) { StreamReader rdr_call_em = new StreamReader(res_call_em.GetResponseStream()); string result_call_em = rdr_call_em.ReadToEnd(); string Notificationdata = RemoveNameSpace.RemoveAllNamespaces(result_call_em); //MessageBox.Show(Notificationdata); XDocument doc_audio_list = XDocument.Parse(Notificationdata); XElement error_code = doc_audio_list.Descendants("errorCode").First(); if (Convert.ToInt32(error_code.Value.ToString()) == 0) { MessageBox.Show("Done!"); } else { MessageBox.Show("API Login Error"); } } } } catch (Exception exx) { MessageBox.Show(exx.Message); process_status.Content = exx.Message; } } else { process_status.Content = ""; importCallEm.IsEnabled = true; importCallEm.Content = "No Valid Order to import "; } process_status.Content = "Done!"; display_result.ItemsSource = task_list; importCallEm.IsEnabled = true; importCallEm.Content = "Import Into Call-em-all"; } else { process_status.Content = ""; importCallEm.IsEnabled = true; importCallEm.Content = "Import Into Call-em-all"; } } else { MessageBox.Show("Please Enter at least one order ID "); } } else { MessageBox.Show("Please input a Broadcast Name & order ID to process"); } } else { MessageBox.Show("Add BC Orders & Select Audio to assign "); } }
private void button4_Click(object sender, RoutedEventArgs e) { Cursor = Cursors.Wait; if (oid.Text != "") { bool add_able = false; for (int i = 0; i < added_order.Items.Count; i++) { if (((ListBoxItem)added_order.Items[i]).Uid == oid.Text) { add_able = true; MessageBox.Show("This Order ID is already added "); break; } } if (!add_able) { try { task_data tsata = new task_data(); tsata.order_id = oid.Text; WebRequest req_big_order_count = WebRequest.Create(big_storeurl.Text + "orders/" + oid.Text); HttpWebRequest httpreq_order_count = (HttpWebRequest)req_big_order_count; httpreq_order_count.Method = "GET"; httpreq_order_count.ContentType = "text/xml; charset=utf-8"; httpreq_order_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_order = (HttpWebResponse)httpreq_order_count.GetResponse(); StreamReader rdr_product_count = new StreamReader(res_order.GetResponseStream()); string result_order = rdr_product_count.ReadToEnd(); //textBox1.Text = result_order; bool order_send = false; if (res_order.StatusCode == HttpStatusCode.OK || res_order.StatusCode == HttpStatusCode.Accepted) { // MessageBox.Show(result_order); XDocument doc_orders = XDocument.Parse(result_order); foreach (XElement order_data in doc_orders.Descendants("order")) { // MessageBox.Show(tsata.order_id); // tsata.c_message = order_data.Element("customer_message").Value.ToString().Replace("\"", "\\\"").Replace("\r\n", "\\n").Replace("\n", "\\n"); tsata.c_name = order_data.Element("billing_address").Element("first_name").Value.ToString(); tsata.total_cost = Convert.ToDouble(order_data.Element("total_inc_tax").Value.ToString()).ToString("0.00", CultureInfo.InvariantCulture); tsata.c_phone = order_data.Element("billing_address").Element("phone").Value.ToString(); // MessageBox.Show("shiipping_Addes"); WebRequest req_big_shipping_count = WebRequest.Create(big_storeurl.Text + "orders/" + tsata.order_id + "/shippingaddresses"); HttpWebRequest httpreq_shipping_count = (HttpWebRequest)req_big_shipping_count; httpreq_shipping_count.Method = "GET"; httpreq_shipping_count.ContentType = "text/xml; charset=utf-8"; httpreq_shipping_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_shipping = (HttpWebResponse)httpreq_shipping_count.GetResponse(); StreamReader rdr_shipping_count = new StreamReader(res_shipping.GetResponseStream()); string result_shipping = rdr_shipping_count.ReadToEnd(); if (res_shipping.StatusCode == HttpStatusCode.OK || res_shipping.StatusCode == HttpStatusCode.Accepted) { XDocument doc_shippings = XDocument.Parse(result_shipping); foreach (XElement order_shipping in doc_shippings.Descendants("address")) { tsata.shipping_address = order_shipping.Element("street_1").Value.ToString() + " " + order_shipping.Element("street_2").Value.ToString(); tsata.shipping_address += " , " + order_shipping.Element("city").Value.ToString() + " , " + order_shipping.Element("state").Value.ToString() + " " + order_shipping.Element("zip").Value.ToString() + " , " + order_shipping.Element("country").Value.ToString(); tsata.oid_status = true; break; } } } if (tsata.oid_status && tsata.c_name != "" && tsata.c_phone != "" && tsata.shipping_address != "") { added_order.Items.Add(new ListBoxItem { Content = oid.Text, Uid = oid.Text, ToolTip = oid.Text }); oid.Text = ""; } else { MessageBox.Show("Order ID dont have customer name Or Address or phone Number . Application cant process such order ID"); } } else { MessageBox.Show("Order ID not found . Please check"); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); // rdata.Add(new result_data { order_id = ((ListBoxItem)added_order.Items[cnt]).Uid, status = ex.Message.ToString() }); // tsata.oid_status = false; } } } Cursor = Cursors.Arrow; }
private void button9_Click(object sender, RoutedEventArgs e) { ProgressBar1.Minimum = 0; ProgressBar1.Value = 0; ProgressBar1.Maximum = added_order.Items.Count; double p_value = 0; UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(ProgressBar1.SetValue); if (added_order.Items.Count > 0) { List <result_data> rdata = new List <result_data>(); process_status.Content = "Please wait while we sending email ...."; button1.Content = "Wait..."; button1.IsEnabled = false; if (MessageBox.Show("Are you sure want to proceed?", "Warning!", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { for (int cnt = 0; cnt < added_order.Items.Count; cnt++) { p_value += 1; Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, p_value }); try { WebRequest req_big_order_count = WebRequest.Create(big_storeurl.Text + "orders/" + ((ListBoxItem)added_order.Items[cnt]).Uid); HttpWebRequest httpreq_order_count = (HttpWebRequest)req_big_order_count; httpreq_order_count.Method = "GET"; httpreq_order_count.ContentType = "text/xml; charset=utf-8"; httpreq_order_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_order = (HttpWebResponse)httpreq_order_count.GetResponse(); StreamReader rdr_product_count = new StreamReader(res_order.GetResponseStream()); string result_order = rdr_product_count.ReadToEnd(); //textBox1.Text = result_order; bool order_send = false; if (res_order.StatusCode == HttpStatusCode.OK || res_order.StatusCode == HttpStatusCode.Accepted) { XDocument doc_orders = XDocument.Parse(result_order); foreach (XElement order_data in doc_orders.Descendants("order")) { task_data tsata = new task_data(); tsata.order_id = order_data.Element("id").Value.ToString(); // MessageBox.Show(tsata.order_id); tsata.c_message = order_data.Element("customer_message").Value.ToString().Replace("\"", "\\\"").Replace("\r\n", "\\n").Replace("\n", "\\n"); tsata.c_name = order_data.Element("billing_address").Element("first_name").Value.ToString(); tsata.total_cost = Convert.ToDouble(order_data.Element("total_inc_tax").Value.ToString()).ToString("0.00", CultureInfo.InvariantCulture); if (testmail_check.IsChecked == true) { tsata.c_email = test_emailID.Text; } else { tsata.c_email = order_data.Element("billing_address").Element("email").Value.ToString(); } tsata.c_phone = order_data.Element("billing_address").Element("phone").Value.ToString(); // MessageBox.Show("shiipping_Addes"); WebRequest req_big_shipping_count = WebRequest.Create(big_storeurl.Text + "orders/" + tsata.order_id + "/shippingaddresses"); HttpWebRequest httpreq_shipping_count = (HttpWebRequest)req_big_shipping_count; httpreq_shipping_count.Method = "GET"; httpreq_shipping_count.ContentType = "text/xml; charset=utf-8"; httpreq_shipping_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_shipping = (HttpWebResponse)httpreq_shipping_count.GetResponse(); StreamReader rdr_shipping_count = new StreamReader(res_shipping.GetResponseStream()); string result_shipping = rdr_shipping_count.ReadToEnd(); if (res_shipping.StatusCode == HttpStatusCode.OK || res_shipping.StatusCode == HttpStatusCode.Accepted) { XDocument doc_shippings = XDocument.Parse(result_shipping); foreach (XElement order_shipping in doc_shippings.Descendants("address")) { tsata.shipping_address = order_shipping.Element("street_1").Value.ToString() + " " + order_shipping.Element("street_2").Value.ToString(); tsata.shipping_address += "\\n" + order_shipping.Element("city").Value.ToString() + "," + order_shipping.Element("state").Value.ToString() + "," + order_shipping.Element("zip").Value.ToString(); break; } } // MessageBox.Show("Products"); WebRequest req_big_productcount = WebRequest.Create(big_storeurl.Text + "orders/" + tsata.order_id + "/products"); HttpWebRequest httpreq_product_count = (HttpWebRequest)req_big_productcount; httpreq_product_count.Method = "GET"; httpreq_product_count.ContentType = "text/xml; charset=utf-8"; httpreq_product_count.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_product = (HttpWebResponse)httpreq_product_count.GetResponse(); StreamReader rdr_product_data = new StreamReader(res_product.GetResponseStream()); string result_product = rdr_product_data.ReadToEnd(); //MessageBox.Show(result_product); string content_mandrill = ""; bool count_pr = false; if (res_product.StatusCode == HttpStatusCode.OK || res_product.StatusCode == HttpStatusCode.Accepted) { XDocument doc_products = XDocument.Parse(result_product); foreach (XElement order_product in doc_products.Descendants("product")) { if (order_product.Element("product_id").Value.ToString() != "0") { string pr_op = ""; foreach (XElement order_product_options in order_product.Descendants("product_options").Descendants("option")) { // MessageBox.Show(order_product_options.Element("display_value").Value.ToString()); pr_op += order_product_options.Element("display_value").Value.ToString().Replace("\"", "\\\"") + " "; } // tsata.item_details = order_product.Element("name").Value.ToString().Replace("\"", "\\\"") + " X " + order_product.Element("quantity").Value.ToString() + " - " + pr_op + " - $" + Convert.ToDouble(order_product.Element("price_inc_tax").Value.ToString()).ToString("0.00", CultureInfo.InvariantCulture) +"\\n"; tsata.item_details = order_product.Element("name").Value.ToString().Replace("\"", "\\\"") + " - " + pr_op; //MessageBox.Show(tsata.item_details); WebRequest req_big_productimg = WebRequest.Create(big_storeurl.Text + "products/" + order_product.Element("product_id").Value.ToString() + "/images"); HttpWebRequest httpreq_product_img = (HttpWebRequest)req_big_productimg; httpreq_product_img.Method = "GET"; httpreq_product_img.ContentType = "text/xml; charset=utf-8"; httpreq_product_img.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_product_img = (HttpWebResponse)httpreq_product_img.GetResponse(); StreamReader rdr_product_data_img = new StreamReader(res_product_img.GetResponseStream()); string result_product_img = rdr_product_data_img.ReadToEnd(); // MessageBox.Show(result_product_img); if (res_product_img.StatusCode == HttpStatusCode.OK || res_product_img.StatusCode == HttpStatusCode.Accepted) { XDocument doc_products_img = XDocument.Parse(result_product_img); foreach (XElement order_product_img in doc_products_img.Descendants("image")) { tsata.pr_img = order_product_img.Element("image_file").Value.ToString(); break; } } WebRequest req_big_product = WebRequest.Create(big_storeurl.Text + "products/" + order_product.Element("product_id").Value.ToString() + ".xml"); HttpWebRequest httpreq_product = (HttpWebRequest)req_big_product; httpreq_product.Method = "GET"; httpreq_product.ContentType = "text/xml; charset=utf-8"; httpreq_product.Credentials = new NetworkCredential(big_user.Text, big_pass.Text); HttpWebResponse res_product_single = (HttpWebResponse)httpreq_product.GetResponse(); StreamReader rdr_product_single = new StreamReader(res_product_single.GetResponseStream()); string result_product_single = rdr_product_single.ReadToEnd(); // MessageBox.Show(result_product_single); if (res_product_single.StatusCode == HttpStatusCode.OK || res_product_single.StatusCode == HttpStatusCode.Accepted) { XDocument doc_product_single = XDocument.Parse(result_product_single); foreach (XElement order_product_single in doc_product_single.Descendants("product")) { tsata.pr_url = "https://www.bigcommerce-domain.com" + order_product_single.Element("custom_url").Value.ToString() + "?utm_campaign=Reorder&utm_source=Mandrill&utm_medium=referral"; // tsata.pr_desc = order_product_single.Element("description").Value.ToString().Replace("\"", "\\\""); tsata.pr_desc = "Last Purchased Product"; break; } } if (!count_pr) { string tmp_pr = "<td valign=\\\"top\\\" width=\\\"180\\\" class=\\\"leftColumnContent\\\"><table border=\\\"0\\\" cellpadding=\\\"20\\\" cellspacing=\\\"0\\\" width=\\\"100%\\\"><tr><td valign=\\\"top\\\" align=\\\"center\\\"><a href=\\\"" + tsata.pr_url + "\\\"><img src=\\\"https://www.sandiegopetfooddelivery.com/product_images/" + tsata.pr_img + "\\\" style=\\\"border:#999 thin solid\\\" mc:label=\\\"image\\\" height=\\\"100\\\" width=\\\"100\\\" alt=\\\"" + tsata.pr_desc + "\\\"><div style=\\\"\\\"><h4 class=\\\"h4\\\">" + tsata.item_details + "</h4></div></a></td></tr></table></td>"; content_mandrill += "<tr>" + tmp_pr; count_pr = true; } else { string tmp_pr = "<td valign=\\\"top\\\" width=\\\"180\\\" class=\\\"rightColumnContent\\\"><table border=\\\"0\\\" cellpadding=\\\"20\\\" cellspacing=\\\"0\\\" width=\\\"100%\\\"><tr><td valign=\\\"top\\\" align=\\\"center\\\"><a href=\\\"" + tsata.pr_url + "\\\"><img src=\\\"https://www.sandiegopetfooddelivery.com/product_images/" + tsata.pr_img + "\\\" style=\\\"border:#999 thin solid\\\" mc:label=\\\"image\\\" height=\\\"100\\\" width=\\\"100\\\" alt=\\\"" + tsata.pr_desc + "\\\"><div style=\\\"\\\"><h4 class=\\\"h4\\\">" + tsata.item_details + "</h4></div></a></td></tr></table></td>"; content_mandrill += tmp_pr + "</tr>"; count_pr = false; } //MessageBox.Show(tsata.item_details); } } if (count_pr) { content_mandrill += "<td valign=\\\"top\\\" width=\\\"180\\\" class=\\\"rightColumnContent\\\"></td></tr>"; } } // MessageBox.Show(content_mandrill); WebRequest req_mandrill = WebRequest.Create("https://mandrillapp.com/api/1.0/messages/send-template.json"); HttpWebRequest httpreq_mandrill = (HttpWebRequest)req_mandrill; httpreq_mandrill.Method = "POST"; httpreq_mandrill.ContentType = "application/json"; // httpreq_mandrill.Headers.Add("Authorization", "Basic " + asana_APIKey.Text); Stream str_mandrill = httpreq_mandrill.GetRequestStream(); StreamWriter strwriter_mandrill = new StreamWriter(str_mandrill, Encoding.ASCII); string soaprequest_mandrill = "{\"key\": \"" + mandrill_apiKey.Text + "\",\"template_name\": \"" + REVIEW_template.Text + "\",\"template_content\": [{\"name\": \"customer_name\",\"content\": \"Hi " + tsata.c_name + ",\"}],\"message\": {\"subject\": \"Delivery Follow Up\",\"from_email\": \"[email protected]\",\"from_name\": \"SDPFD\",\"to\": [{\"email\": \"" + tsata.c_email + "\",\"name\": \"" + tsata.c_name + "\"}]}, \"async\": true}"; //MessageBox.Show(soaprequest_mandrill); strwriter_mandrill.Write(soaprequest_mandrill.ToString()); strwriter_mandrill.Close(); HttpWebResponse res_mandrill = (HttpWebResponse)httpreq_mandrill.GetResponse(); StreamReader rdr_mandrill = new StreamReader(res_mandrill.GetResponseStream()); string result_mandrill = rdr_mandrill.ReadToEnd(); // MessageBox.Show(result_mandrill); order_send = true; rdata.Add(new result_data { order_id = ((ListBoxItem)added_order.Items[cnt]).Uid, status = "Send Successfully" }); } } } catch (Exception ex) { // MessageBox.Show(ex.Message.ToString()); rdata.Add(new result_data { order_id = ((ListBoxItem)added_order.Items[cnt]).Uid, status = ex.Message.ToString() }); } } display_result.ItemsSource = rdata; process_status.Content = "Task Completed"; button1.IsEnabled = true; button1.Content = "Search & Send"; } else { process_status.Content = ""; button1.IsEnabled = true; button1.Content = "Search & Send"; } } else { MessageBox.Show("Please Enter at least one order ID "); } }