Ejemplo n.º 1
0
        private bool upYesterday()
        {
            bool bl = false;

            try
            {
                using (var client = new HttpClient())
                {
                    int    sta = 0;
                    string sms = "";
                    client.BaseAddress = new Uri("http://5cosmeda.homeunix.com:89/ApiFromPOS/");
                    //client.BaseAddress = new Uri("http://192.168.10.202:89/ApiFromPOS/");
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    var json = JsonConvert.SerializeObject(ListPOS);


                    JSONSTRING ss = new JSONSTRING();
                    ss.DATAJSON = json;

                    var response = client.PostAsJsonAsync("api/POS/InsertBill", ss).Result;
                    var details  = JObject.Parse(response.Content.ReadAsStringAsync().Result);

                    if ((int)response.StatusCode == 200)
                    {
                        sta = Convert.ToInt32(details["StatusCode"]);
                        sms = details["Messages"].ToString();

                        if (sta == 1)
                        {
                            upPosUL();
                            //upPosUL();
                            uplog(Whcode, "3>>YESTERDAY>>" + sms);
                        }
                        else if (sta == 2)
                        {
                            if (sms.Substring(1, 9) == "Violation" || sms == "Object reference not set to an instance of an object.")
                            {
                                uplog(Whcode, "5>>YESTERDAY>>" + sms);
                            }
                            else
                            {
                                upPosUL();
                                uplog(Whcode, "4>>YESTERDAY>>" + "Success");
                            }
                        }
                        else
                        {
                            uplog(Whcode, "2>>YESTERDAY>>" + sms);
                        }

                        bl = true;
                    }
                    else
                    {
                        uplog(Whcode, "1>>YESTERDAY>>" + response.StatusCode.ToString());
                        bl = false;
                    }
                }
            }
            catch (Exception ex)
            {
                bl = false;
                uplog(Whcode, "6>>YESTERDAY>>" + ex.Message);
            }

            return(bl);
        }
Ejemplo n.º 2
0
        private void autoSend()
        {
            try
            {
                ListPOS.Clear();

                if (getABBNO() == true)
                {
                    using (var client = new HttpClient())
                    {
                        if (ListPOS.Count > 0)
                        {
                            int    sta = 0;
                            string sms = "";
                            client.BaseAddress = new Uri("http://5cosmeda.homeunix.com:89/ApiFromPOS/");
                            //client.BaseAddress = new Uri("http://192.168.10.202:89/ApiFromPOS/");
                            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                            var json = JsonConvert.SerializeObject(ListPOS);

                            //---------------------------------------------------------------------//
                            var list = (from pp in ListPOS
                                        select pp).FirstOrDefault();

                            string abn = list.POSPT.ABBNO;
                            //---------------------------------------------------------------------//

                            JSONSTRING ss = new JSONSTRING();
                            ss.DATAJSON = json;

                            var response = client.PostAsJsonAsync("api/POS/InsertBill", ss).Result;
                            var details  = JObject.Parse(response.Content.ReadAsStringAsync().Result);

                            if ((int)response.StatusCode == 200)
                            {
                                sta = Convert.ToInt32(details["StatusCode"]);
                                sms = details["Messages"].ToString();

                                if (sta == 1)
                                {
                                    upPosUL(abn);
                                    //upPosUL();
                                    uplog(Whcode, "3" + sms);
                                }
                                else if (sta == 2)
                                {
                                    if (sms.Substring(1, 9) == "Violation" || sms == "Object reference not set to an instance of an object.")
                                    {
                                        uplog(Whcode, "5" + sms);
                                    }
                                    else
                                    {
                                        upPosUL(abn);
                                        uplog(Whcode, "4" + "Success");
                                    }
                                }
                                else
                                {
                                    uplog(Whcode, "2" + sms);
                                }
                            }
                            else
                            {
                                uplog(Whcode, "1" + response.StatusCode.ToString());
                            }
                        }
                        else
                        {
                            uplog(Whcode, "No bill");
                        }
                    }
                }
                else
                {
                    uplog(Whcode, "No bill");
                }
            }
            catch (Exception ex)
            {
                uplog(Whcode, "7" + ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void noBillSend(string ydt)
        {
            string sms        = "";
            var    restClient = new RestClient("http://5cosmeda.homeunix.com:89/ApiFromPOS/api/POS/InsertBill");
            //var restClient = new RestClient("http://192.168.10.202/ApiFromPOS/api/POS/InsertBill");
            var request = new RestRequest(Method.POST);

            request.RequestFormat = DataFormat.Json;

            int _wh_id = cmd.DEF_LOCALs.Select(s => s.WH_ID).FirstOrDefault();

            string sbrand = "";
            string fstr;

            fstr = Whcode.Substring(0, 1);

            if (fstr == "1" || fstr == "3")
            {
                sbrand = "BB";
            }
            else if (fstr == "5")
            {
                sbrand = "BC";
            }
            else
            {
                sbrand = "BM";
            }

            POSPTENDDAY PEnd = new POSPTENDDAY {
                WH_ID = _wh_id, ENDDAY = "Y", ENDDAY_DATE = ydt, ENDDAY_BY = "2558", BRAND = sbrand
            };


            var json = JsonConvert.SerializeObject(PEnd);

            JSONSTRING ss = new JSONSTRING();

            ss.DATAJSON  = "";
            ss.POSENDDAY = PEnd;

            //request.AddJsonBody(ss);

            request.AddBody(ss);

            var response = restClient.Execute(request);

            JsonDeserializer deserial = new JsonDeserializer();

            if ((int)response.StatusCode == 200)
            {
                List <Result> bl = deserial.Deserialize <List <Result> >(response);


                var item = bl.FirstOrDefault();

                if (item.StatusCode == "1")
                {
                    sms = "สำเร็จ";
                }
                else
                {
                    sms = item.Messages + "debug1";
                }
            }
            else
            {
                sms = response.ErrorException.Message + "Pro1";
            }

            uplog(Whcode, "YESTERDAY:" + sms);
        }