示例#1
0
        private void context2_TextChanged(object sender, TextChangedEventArgs e)
        {
            string sql1 = String.Format("select * from Commondity where Id='{0}'", TextBox_Id.Text);

            try
            {
                List <string> counts = SqlManager.ReadColumn(sql1, "Count");
                TextBox_Count.Foreground = Brushes.Black;
                for (int i = 0; i < counts.Count; i++)
                {
                    if (int.Parse(TextBox_Count.Text) > int.Parse(counts[i]))
                    {
                        TextBox_Count.Foreground = Brushes.Red;
                    }
                }
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }

            // 还有一个隐患在于单次结算场景下的分配请求超量,例如库存为10时一次性不可添加11个,但可以先添加5个,再添加6个,显然不符合实际。
        }
示例#2
0
        public void Login(string userName, string password, string connString)
        {
            //获取用户名和密码匹配的行的数量的SQL语句
            string sql = String.Format("select count(*) from [User] where userName='******'and password='******'", userName, GetPasswordEncryption(password));

            try
            {
                if ((int)SqlManager.ExecuteScalar(sql) > 0)
                {
                    //如果有匹配的行,则表明用户名和密码正确
                    MessageBox.Show("欢迎进入商品销售管理系统!", "登录成功", 0, MessageBoxImage.Information);
                    ShowMainFrm();
                }
                else
                {
                    MessageBox.Show("您输入的用户名或密码错误!", "登录失败", 0, MessageBoxImage.Exclamation);
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "操作数据库出错!", 0, MessageBoxImage.Exclamation); }
        }
示例#3
0
        private void TextBox_Id_TextChanged(object sender, TextChangedEventArgs e)
        {
            if ("" == TextBox_Id.Text)
            {
                return;
            }
            TextBox_Id.Foreground = Brushes.Red;
            TextBox_Name.Text     = TextBox_Count.Text = TextBox_SinglePrice.Text = "";
            string        sql    = String.Format("select * from [Commondity] where Id={0}", TextBox_Id.Text);
            List <string> names  = SqlManager.ReadColumn(sql, "Name");
            List <string> prices = SqlManager.ReadColumn(sql, "Price");
            List <string> counts = SqlManager.ReadColumn(sql, "Count");

            for (int i = 0; i < names.Count; i++)
            {
                TextBox_Id.Foreground    = Brushes.Black;
                TextBox_Name.Text        = names[i].Trim();
                TextBox_SinglePrice.Text = prices[i].Trim();
                TextBox_Count.Text       = counts[i].Trim();
            }
        }
示例#4
0
        public SalesCalculation()
        {
            InitializeComponent();

            string sql1 = "select * from [Commondity]";

            try
            {
                List <string> ids    = SqlManager.ReadColumn(sql1, "Id");
                List <string> names  = SqlManager.ReadColumn(sql1, "Name");
                List <string> counts = new List <string>();
                List <string> moneys = new List <string>();
                foreach (string id in ids)
                {
                    int           count       = 0;
                    float         money       = 0;
                    string        sql_Id2Name = "select * from [Sale] where Id=" + id;
                    List <string> c           = SqlManager.ReadColumn(sql_Id2Name, "Count");
                    List <string> p           = SqlManager.ReadColumn(sql_Id2Name, "Price");
                    for (int i = 0; i < c.Count; i++)
                    {
                        count += int.Parse(c[i]); money += int.Parse(c[i]) * float.Parse(p[i]);
                    }
                    counts.Add(count.ToString());
                    moneys.Add(money.ToString());
                }

                float sum = 0;
                for (int i = 0; i < ids.Count; i++)
                {
                    listView.Items.Add(new SaltInfo {
                        Id = ids[i].Trim(), Count = counts[i].Trim(), Name = names[i].Trim(), Money = moneys[i].Trim()
                    }); sum += float.Parse(moneys[i]);
                }

                Label_Sum.Content = "销售总额:" + sum;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "查询失败", 0, MessageBoxImage.Error); }
        }
示例#5
0
        private void context1_TextChanged(object sender, TextChangedEventArgs e)
        {
            string sql1 = String.Format("select * from Commondity where Id='{0}'", TextBox_Id.Text);

            try
            {
                ItemInfo.Content = "未找到商品信息"; TextBox_Id.Foreground = Brushes.Red;
                List <string> ids    = SqlManager.ReadColumn(sql1, "Id");
                List <string> names  = SqlManager.ReadColumn(sql1, "Name");
                List <string> counts = SqlManager.ReadColumn(sql1, "Count");
                List <string> prices = SqlManager.ReadColumn(sql1, "Price");
                for (int i = 0; i < ids.Count; i++)
                {
                    TextBox_Id.Foreground = TextBox_Count.Foreground = Brushes.Black;
                    ItemInfo.Content      = names[i].Trim() + "  单价:" + prices[i].Trim() + "  库存:" + counts[i].Trim() + "件";
                    if (int.Parse(TextBox_Count.Text) > int.Parse(counts[i]))
                    {
                        TextBox_Count.Foreground = Brushes.Red;
                    }
                }
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
        }
示例#6
0
        public SalesRecordsWindow(string ShowId)
        {
            InitializeComponent();

            string sql1 = "select * from [Sale]";

            try
            {
                List <string> names  = new List <string>();
                List <string> ids    = SqlManager.ReadColumn(sql1, "Id");
                List <string> counts = SqlManager.ReadColumn(sql1, "Count");
                List <string> prices = SqlManager.ReadColumn(sql1, "Price");
                List <string> times  = SqlManager.ReadColumn(sql1, "Time");
                foreach (string id in ids)
                {
                    string sql_Id2Name = "select * from [Commondity] where Id=" + id;
                    names.Add(SqlManager.ReadColumn(sql_Id2Name, "name")[0]);
                }
                for (int i = 0; i < ids.Count; i++)
                {
                    if (ShowId == ids[i])
                    {
                        listView.Items.Add(new
                        {
                            Id       = ids[i].Trim(),
                            Count    = counts[i].Trim(),
                            Name     = names[i].Trim(),
                            Money    = prices[i].Trim(),
                            Time     = times[i].Trim(),
                            SumMoney = float.Parse(prices[i].Trim()) * int.Parse(counts[i].Trim())
                        });
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "查询失败", 0, MessageBoxImage.Error); }
        }
示例#7
0
        private void Button2_Click(object sender, RoutedEventArgs e) //结算
        {
            if (0 == ItemList.Items.Count)
            {
                MessageBox.Show("结算列表为空", "未执行结算", 0, MessageBoxImage.Exclamation);
                return;
            }

            List <PaymentItemInfo> successedList = new List <PaymentItemInfo>();
            List <PaymentItemInfo> failedList    = new List <PaymentItemInfo>();

            try
            {
                foreach (PaymentItemInfo info in ItemList.Items)
                {
                    string sql = String.Format("INSERT INTO Sale(Id, Count, Price) VALUES('{0}','{1}','{2}')", info.Id, info.Count, info.SinglePrice);
                    try
                    {
                        SqlManager.ExecuteCommand(String.Format("update Commondity set Count={0} where Id={1}", int.Parse(SqlManager.ReadColumn(String.Format("select * from Commondity where Id='{0}'", info.Id), "Count")[0]) - int.Parse(info.Count), info.Id));
                        SqlManager.ExecuteCommand(sql);
                    } catch (Exception) { failedList.Add(info); continue; }
                    successedList.Add(info);
                }
                if (ItemList.Items.Count - failedList.Count > 0)
                {
                    TextBox_Id.Text = TextBox_Count.Text = "";
                    foreach (PaymentItemInfo pi in successedList)
                    {
                        ItemList.Items.Remove(pi);
                    }
                    if (0 == failedList.Count)
                    {
                        MessageBox.Show("结算成功!", "结算成功", 0, MessageBoxImage.Information);
                    }
                    else
                    {
                        string failedString = "";
                        foreach (PaymentItemInfo pi in failedList)
                        {
                            failedString += pi.Id + " " + pi.Name + Environment.NewLine;
                        }
                        MessageBox.Show(successedList.Count + "样商品结算成功,以下是结算失败的商品:" + Environment.NewLine + failedString);
                    }
                }
                else
                {
                    MessageBox.Show("结算失败!", "结算失败", 0, MessageBoxImage.Error);
                }
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
        }