示例#1
0
        private void form_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if ((DateTime.Now - date) < TimeSpan.FromMilliseconds(30))
                {
                    if (e.KeyCode == Keys.Enter)
                    {
                        //string inputInfo = ";111=125001=3=63115235?";
                        //MatchCollection matches = Regex.Matches(inputInfo, @"([0-9])+");
                        MatchCollection matches   = Regex.Matches(Encoding.ASCII.GetString(stk.get()), @"([0-9])+");
                        string          inputInfo = Encoding.ASCII.GetString(stk.get());
                        if (matches.Count >= 3)
                        {
                            var ip = GetLocalIPAddress();
                            loginInfo = new LoginInfo(inputInfo, ip.MapToIPv4().ToString());

                            LoginInfo.LoginInfoResponce loginInfoResponce = new LoginInfo.LoginInfoResponce();
                            GetCashierInfo();
                            stk.clear();
                            return;
                        }
                        stk.clear();
                    }
                    stk.push((byte)e.KeyValue);
                }
            }
            catch (Exception exc)
            {
                stk.clear();
                FormMessage formMessage = new FormMessage(exc.Message, "Касса");
                formMessage.Show();
            }
        }
示例#2
0
        private void GetCashierInfo()
        {
            try
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(APP_PATH + "/api/cashiermashine/GetCashierInfo/");
                var ip             = GetLocalIPAddress();
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                LoginInfo newLoginInfo = new LoginInfo(loginInfo.cardInfo, ip.MapToIPv4().ToString());
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = JsonConvert.SerializeObject(newLoginInfo, Formatting.Indented, new JsonSerializerSettings
                    {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    });
                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                LoginInfo.LoginInfoResponce loginInfoResponce = new LoginInfo.LoginInfoResponce();
                string result = "";
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    result = streamReader.ReadToEnd();
                    if (result != "null")
                    {
                        string r = result.Remove(result.Length - 1);
                        var    k = JsonConvert.DeserializeObject(result);

                        loginInfoResponce = JsonConvert.DeserializeObject <LoginInfo.LoginInfoResponce>(k.ToString());
                    }
                    else
                    {
                        throw new Exception("Ошибка данных кассира/кассы");
                    }
                }
                if (loginInfoResponce != null)
                {
                    StartInfo startInfo = getStartInfo(newLoginInfo.cardInfo, ip.MapToIPv4().ToString());
                    if (startInfo != null)
                    {
                        form formCashRegister = new form(
                            loginInfoResponce.cashier,
                            loginInfoResponce.cashierRegister,
                            newLoginInfo.cardInfo,
                            ip.MapToIPv4().ToString(),
                            startInfo
                            );
                        this.Hide();
                        formCashRegister.ShowDialog();
                        this.Show();
                    }
                    else
                    {
                        FormMessage formMessage = new FormMessage("Ошибка получения начальных данных.", "Касса");
                        formMessage.Show();
                    }
                }
                else if (loginInfoResponce == null)
                {
                    FormMessage formMessage = new FormMessage("Ошибка входа.\nПроверьте карту.", "Касса");
                    formMessage.Show();
                }
                else
                {
                    FormMessage formMessage = new FormMessage(httpResponse.StatusDescription, "Касса");
                    formMessage.Show();
                }
            }
            catch (Exception exc)
            {
                FormMessage formMessage = new FormMessage(exc.Message, "Касса");
                formMessage.Show();
            }
        }