public static string SendVendorOfflineInvoices() { string read = ""; string connectionError = ""; try { HttpClient client = new HttpClient(); client = BusinessAuthentication.SendAuthentication(); string apiUrl = ConfigurationManager.AppSettings["api_url"] + "sales"; string inputJson = (new JavaScriptSerializer()).Serialize(OfflineActivities.GetOfflineInvoices()); HttpContent inputContent = new StringContent(inputJson, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(apiUrl + "/salesofflineinvoice", inputContent).Result; if (response.IsSuccessStatusCode) { Sales sales = new Sales(); var readTask = response.Content.ReadAsAsync <List <Sales> >().Status; read = readTask.ToString(); SqlConnection conn = new SqlConnection(connStaticString); SqlCommand cmd = new SqlCommand("sp_ClientConnectionStatusInOfflineActivityToNullInSales_Master", conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } else { } } catch (SystemException ex) { read = "Exception: " + ex.Message.ToString(); } catch (Exception ex) { read = "Exception: " + ex.Message.ToString(); } return(read); }
/// <summary> /// THIS METHOD IS A STATIC ONE, IS USED TO SEND OFFLINE INVOICES ON WINDOWS FORM ACTIVATED METHOD WHENEVER THE CONNECTION GETS ONLINE /// THE EVENT IS INVOKED AND RESUMES THE PROCESS OF SENDING OFFLINE INVOICES FROM THE LOCAL MACHINE TO THE SERVER SITE /// /// </summary> public static string SendVendorOfflineSalesDetail() { string read = ""; string connectionError = ""; try { HttpClient client = new HttpClient(); client = BusinessAuthentication.SendAuthentication(); string apiUrl = ConfigurationManager.AppSettings["api_url"] + "sales"; string inputJson = (new JavaScriptSerializer()).Serialize(OfflineActivities.GetOfflineSalesDetail()); HttpContent inputContent = new StringContent(inputJson, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(apiUrl + "/SalesDetailOfflineInvoice", inputContent).Result; if (response.IsSuccessStatusCode) { SalesDetail sales = new SalesDetail(); var readTask = response.Content.ReadAsAsync <List <SalesDetail> >().Status; read = readTask.ToString(); SqlConnection conn = new SqlConnection(connStaticString); SqlCommand cmd = new SqlCommand("sp_ClientConnectionStatusInOfflineActivityToNullInSales_Details", conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } else { } } catch (SocketException ex) { string s = ex.ToString(); //return false; } //catch (System.Net.Sockets.SocketException socketEx) //{ // read += socketEx.Message + "\r\n" + socketEx.StackTrace; //} catch (System.Net.WebException socketEx) { read += socketEx.Message + "\r\n" + socketEx.StackTrace; } catch (AggregateException ex) { foreach (Exception inner in ex.InnerExceptions) { Console.WriteLine("Exception type {0} from {1}", inner.GetType(), inner.Source); read += inner.GetType() + " " + inner.Source; } } ////catch (SystemException sysEx) ////{ } ////catch (Exception ex) ////{ } //catch (System.Net.Sockets.SocketException socketEx) //{ // read += socketEx.Message + "\r\n"; //} //catch (System.Net.WebException socketEx) //{ // read += socketEx.Message + "\r\n"; //} return(read); }