Ejemplo n.º 1
0
        public void removeDayBonuses(string cardInfo, string loginCard, string ip, decimal dayBonuses)
        {
            try
            {
                decimal balance = this.cardDayBonus;
                if (balance >= dayBonuses)
                {
                    ReplenishmentInfo replenishmentInfo = new ReplenishmentInfo(cardInfo, dayBonuses, 0, 0, loginCard, ip);
                    var httpWebRequest = (HttpWebRequest)WebRequest.Create(APP_PATH + "/api/cashiermashine/ReturnDayBonuses/");

                    httpWebRequest.ContentType = "application/json";
                    httpWebRequest.Method      = "POST";
                    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                    {
                        string json = JsonConvert.SerializeObject(replenishmentInfo);
                        streamWriter.Write(json);
                        streamWriter.Flush();
                        streamWriter.Close();
                    }
                    var    httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    Card   card         = new Card();
                    string result       = "";
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        result = streamReader.ReadToEnd();
                        if (result == "null")
                        {
                            throw new Exception("Ошибка списания бонусов");
                        }
                        else
                        {
                            string r = result.Remove(result.Length - 1);
                            var    k = JsonConvert.DeserializeObject(result);
                            card = JsonConvert.DeserializeObject <Card>(k.ToString());
                            this.cardDayBonus = card.cardDayBonus;
                        }
                    }
                }
                else
                {
                    throw new Exception("Недосточное количесво суточных бонусов");
                }
            }
            catch (Exception exc)
            {
                FormMessage formMessage = new FormMessage(exc.Message, "Касса");
                formMessage.Show();
            }
        }
Ejemplo n.º 2
0
        //Установка пакета
        public void setPacket(string cardInfo, int discount, string loginCard, string ip)
        {
            try
            {
                int balance = this.cardTicket;
                ReplenishmentInfo replenishmentInfo = new ReplenishmentInfo(cardInfo, discount, 0, 0, loginCard, ip);
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(APP_PATH + "/api/cashiermashine/SetPacket/");

                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = JsonConvert.SerializeObject(replenishmentInfo);
                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                var    httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                Card   card         = new Card();
                string result       = "";
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    result = streamReader.ReadToEnd();
                    if (result == "null" || result == "\"null\"")
                    {
                        throw new Exception("Ошибка установки пакета");
                    }
                    else
                    {
                        string r = result.Remove(result.Length - 1);
                        var    k = JsonConvert.DeserializeObject(result);
                        card          = JsonConvert.DeserializeObject <Card>(k.ToString());
                        this.cardSale = card.cardSale;
                    }
                }
            }
            catch (Exception exc)
            {
                FormMessage formMessage = new FormMessage(exc.Message, "Касса");
                formMessage.Show();
            }
        }
Ejemplo n.º 3
0
        //Пополнение баланса
        public void replenishment(string cardInfo, decimal cash, decimal cashlessPayment, decimal creditCard, string loginCard, string ip)
        {
            try
            {
                ReplenishmentInfo replenishmentInfo = new ReplenishmentInfo(cardInfo, cash, cashlessPayment, creditCard, loginCard, ip);
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(APP_PATH + "/api/cashiermashine/Replenishment/");

                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = JsonConvert.SerializeObject(replenishmentInfo);
                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                var    httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                Card   card         = new Card();
                string result       = "";
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    result = streamReader.ReadToEnd();
                    if (result == "null")
                    {
                        throw new Exception("Ошибка пополнения очков");
                    }
                    else
                    {
                        string r = result.Remove(result.Length - 1);
                        var    k = JsonConvert.DeserializeObject(result);
                        card           = JsonConvert.DeserializeObject <Card>(k.ToString());
                        this.cardCount = card.cardCount;
                    }
                }
            }
            catch (Exception exc)
            {
                FormMessage formMessage = new FormMessage(exc.Message, "Касса");
                formMessage.Show();
            }
        }
Ejemplo n.º 4
0
        public CardPrice PaidForCard()
        {
            APP_PATH = ConfigurationManager.AppSettings.Get("serverURI");
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(APP_PATH + "/api/cashiermashine/PaidForCard/");
            ReplenishmentInfo replenishmentInfo = new ReplenishmentInfo();

            if (radioButton1.Checked)
            {
                replenishmentInfo = new ReplenishmentInfo(cardInfo, cash, 0, 0, loginCardInfo, ip);
            }
            else if (radioButton2.Checked)
            {
                replenishmentInfo = new ReplenishmentInfo(cardInfo, 0, cash, 0, loginCardInfo, ip);
            }
            else if (radioButton3.Checked)
            {
                replenishmentInfo = new ReplenishmentInfo(cardInfo, 0, 0, cash, loginCardInfo, ip);
            }
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = JsonConvert.SerializeObject(replenishmentInfo);
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }
            var    httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            string result       = "";

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                result = streamReader.ReadToEnd();
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    if (result == "null")
                    {
                        throw new Exception("Ошибка оплаты карты");
                    }
                    else
                    {
                        string r = result.Remove(result.Length - 1);
                        var    k = JsonConvert.DeserializeObject(result);
                        return(JsonConvert.DeserializeObject <CardPrice>(k.ToString()));
                    }
                }
                else if (httpResponse.StatusCode == HttpStatusCode.NotFound)
                {
                    result = streamReader.ReadToEnd();
                    FormMessage formMessage = new FormMessage(result, "Касса");
                    formMessage.Show();
                }
                else if (httpResponse.StatusCode == HttpStatusCode.NotAcceptable)
                {
                    result = streamReader.ReadToEnd();
                    FormMessage formMessage = new FormMessage(result, "Касса");
                    formMessage.Show();
                }
                return(null);
            }
        }