예제 #1
0
        public override void Update(Dictionary <string, int> cart, string name, double money)
        {
            try
            {
                if (!File.Exists(FilePath))
                {
                    string time = DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute;
                    Sell   s    = new Sell()
                    {
                        Time  = time,
                        Name  = name,
                        Cost  = money,
                        Goods = cart
                    };

                    SellsList obj = new SellsList();
                    obj.Sells.Add(s);

                    File.WriteAllText(FilePath, JsonConvert.SerializeObject(obj));
                }
                else
                {
                    SellsList obj = JsonConvert.DeserializeObject <SellsList>(File.ReadAllText(FilePath));

                    string time = DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute;
                    Sell   s    = new Sell()
                    {
                        Time  = time,
                        Name  = name,
                        Cost  = money,
                        Goods = cart
                    };

                    obj.Sells.Add(s);

                    File.WriteAllText(FilePath, JsonConvert.SerializeObject(obj));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка записи о совершённой покупке. Ошибка: " + ex.Message);
            }
        }
예제 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string password = tb1.Text;

            if (password == "valid") // Эмитируем проверку пароля
            {
                lb1.Items.Clear();
                bool   compact = (bool)cb1.IsChecked;
                string path    = compact ? "../../sells_short.json" : "../../sells.json";

                SellsList obj = JsonConvert.DeserializeObject <SellsList>(File.ReadAllText(path));
                foreach (Sell s in obj.Sells)
                {
                    lb1.Items.Add("Время: " + s.Time);
                    lb1.Items.Add("Имя: " + s.Name);
                    lb1.Items.Add("Куплено на сумму: " + s.Cost);
                    foreach (string name in s.Goods.Keys)
                    {
                        lb1.Items.Add(name + ": " + s.Goods[name]);
                    }
                    lb1.Items.Add("");
                }
            }
        }