Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string name      = txtName.Text;
            string id        = txtId.Text;
            double inprice   = Convert.ToDouble(numInprice.Value);
            double price     = Convert.ToDouble(numPrice.Value);
            int    inventory = Convert.ToInt32(numInventory.Value);
            string kind      = txtKind.Text;

            if (name.Length != 0 && id.Length != 0 && price != 0 && kind.Length != 0)
            {
                MySqlConnection conn = MysqlConnector.GetInstance();
                try
                {
                    conn.Open();
                    string       mysqlstr = string.Format("select goods_id from tb_goodsinfo where goods_num='{0}';", id);
                    MySqlCommand comm     = new MySqlCommand(mysqlstr, conn);
                    object       reo      = comm.ExecuteScalar();
                    if (reo != null)
                    {
                        MessageBox.Show(this, "商品条码已存在");
                    }
                    else
                    {
                        string       sqlstr = string.Format("insert into tb_goodsinfo(goods_name,goods_num,goods_inprice,goods_price,goods_left,goods_kind) value('{0}','{1}',{2},{3},{4},'{5}');", name, id, inprice, price, inventory, kind);
                        MySqlCommand comm1  = new MySqlCommand(sqlstr, conn);
                        int          re     = comm1.ExecuteNonQuery();
                        if (re == 1)
                        {
                            ListViewItem item = new ListViewItem();
                            item.Text = ((listView1.Items.Count + 1).ToString());
                            item.SubItems.Add(name);
                            item.SubItems.Add(id);
                            item.SubItems.Add(inprice.ToString());
                            item.SubItems.Add(price.ToString());
                            item.SubItems.Add(inventory.ToString());
                            item.SubItems.Add(kind);
                            listView1.Items.Add(item);
                            MessageBox.Show(this, "添加成功");
                        }
                        else
                        {
                            MessageBox.Show(this, "添加失败");
                        }
                    }
                }
                catch (Exception e1)
                {
                    MessageBox.Show(this, string.Format("Exception: {0}", e1));
                }
                finally
                {
                    conn.Close();
                }
            }
            else
            {
                MessageBox.Show(this, "数据不允许为空或0");
            }
        }
Ejemplo n.º 2
0
        public int InitLvMembers()
        {
            listView1.Items.Clear();
            int             n    = 0;
            MySqlConnection conn = MysqlConnector.GetInstance();

            try
            {
                conn.Open();
                string          sqlstr = "select * from tb_member;";
                MySqlCommand    comm   = new MySqlCommand(sqlstr, conn);
                MySqlDataReader reader = comm.ExecuteReader();
                while (reader.Read())
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = ((++n).ToString());
                    item.SubItems.Add(reader.GetString(1));
                    item.SubItems.Add(reader.GetString(2));
                    item.SubItems.Add(reader.GetInt32(3).ToString());
                    item.SubItems.Add(reader.GetInt32(4).ToString());
                    listView1.Items.Add(item);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e));
            }
            finally
            {
                conn.Close();
            }
            return(n);
        }
Ejemplo n.º 3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;

            if (username.Length == 0 || password.Length == 0)
            {
                MessageBox.Show(this, "用户名和密码不能为空");
            }
            else
            {
                MySqlConnection conn = MysqlConnector.GetInstance();
                if (conn != null)
                {
                    try
                    {
                        string sqlstr = string.Format("select * from tb_admin where admin_username='******' and admin_password='******';", username, password);
                        conn.Open();
                        MySqlCommand    com    = new MySqlCommand(sqlstr, conn);
                        MySqlDataReader reader = com.ExecuteReader();
                        if (reader.Read())
                        {
                            DialogResult = DialogResult.OK;     // 设置模态窗口状态为OK,代表登录成功
                            bool issu = reader.GetBoolean("admin_isowner");
                            if (issu)
                            {
                                GlobalVar.login = new SuperAdmin();
                            }
                            else
                            {
                                GlobalVar.login = new Admin();
                            }
                            GlobalVar.login.Username = username;
                            GlobalVar.login.Id       = reader.GetInt32(0);
                        }
                        else
                        {
                            MessageBox.Show(this, "登录失败,用户名或密码错误");
                        }
                        reader.Close();
                    }
                    catch (Exception e1)
                    {
                        MessageBox.Show(this, string.Format("Exception: {0}", e1));
                    }
                    finally
                    {
                        conn.Close();
                    }
                    if (GlobalVar.login != null)
                    {
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show(this, "数据库连接失败");
                }
            }
        }
Ejemplo n.º 4
0
        private void btnChange_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show(this, "未选中任何项");
                return;
            }
            string username    = txtUsername.Text;
            string password    = txtPassword.Text;
            int    point       = Convert.ToInt32(numPoint.Value);
            int    level       = Convert.ToInt32(numLevel.Value);
            string oldusername = listView1.SelectedItems[0].SubItems[1].Text;

            MySqlConnection conn = MysqlConnector.GetInstance();

            try
            {
                conn.Open();
                if (!username.Equals(oldusername))
                {
                    string       sqlstr = string.Format("select mem_id from tb_member where mem_username='******';", username);
                    MySqlCommand comm   = new MySqlCommand(sqlstr, conn);
                    object       re     = comm.ExecuteScalar();
                    if (re != null)
                    {
                        throw new MemberUsernameRepeat("用户名已存在");
                    }
                }
                string mysqlstr = string.Format("update tb_member set mem_username='******',mem_password='******',mem_points={2},mem_level={3} where mem_username='******';",
                                                username, password, point, level, oldusername);
                MySqlCommand comm1 = new MySqlCommand(mysqlstr, conn);
                int          res   = comm1.ExecuteNonQuery();
                if (res != 0)
                {
                    listView1.SelectedItems[0].SubItems[1].Text = username;
                    listView1.SelectedItems[0].SubItems[2].Text = password;
                    listView1.SelectedItems[0].SubItems[3].Text = point.ToString();
                    listView1.SelectedItems[0].SubItems[4].Text = level.ToString();
                    MessageBox.Show(this, "修改成功");
                }
                else
                {
                    MessageBox.Show(this, "修改失败");
                }
            }
            catch (MemberUsernameRepeat e1)
            {
                MessageBox.Show(this, e1.Message);
            }
            catch (Exception e1)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e1));
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;

            if (username.Length != 0 && password.Length != 0)
            {
                MySqlConnection conn = MysqlConnector.GetInstance();
                try
                {
                    conn.Open();
                    string       mysqlstr = string.Format("select admin_id from tb_admin where admin_username='******';", username);
                    MySqlCommand comm     = new MySqlCommand(mysqlstr, conn);
                    object       reo      = comm.ExecuteScalar();
                    if (reo != null)
                    {
                        throw new AdminUsernameRepeat("用户名已存在");
                    }
                    else
                    {
                        string       sqlstr = string.Format("insert into tb_admin(admin_username,admin_password) value('{0}','{1}');", username, password);
                        MySqlCommand comm1  = new MySqlCommand(sqlstr, conn);
                        int          re     = comm1.ExecuteNonQuery();
                        if (re == 1)
                        {
                            ListViewItem item = new ListViewItem();
                            item.Text = ((listView1.Items.Count + 1).ToString());
                            item.SubItems.Add(username);
                            item.SubItems.Add(password);
                            listView1.Items.Add(item);
                            MessageBox.Show(this, "添加成功");
                        }
                        else
                        {
                            MessageBox.Show(this, "添加失败");
                        }
                    }
                }
                catch (AdminUsernameRepeat e1)
                {
                    MessageBox.Show(this, e1.Message);
                }
                catch (Exception e1)
                {
                    MessageBox.Show(this, string.Format("Exception: {0}", e1));
                }
                finally
                {
                    conn.Close();
                }
            }
            else
            {
                MessageBox.Show(this, "用户名和密码不允许为空");
            }
        }
Ejemplo n.º 6
0
        public int InitLvSaleRecord()
        {
            listView1.Items.Clear();
            int             n    = 0;
            MySqlConnection conn = MysqlConnector.GetInstance();

            try
            {
                conn.Open();
                string mysqlstr =
                    @"SELECT
  *, COUNT(`money`) AS `pinleishu`, SUM(`money`) AS `total`
FROM
  (SELECT
    `sale_billnum`,
    `sale_datetime`,
    `mem_username`,
    `admin_username`,
    (`sale_amount` * `goods_price`) AS 'money'
  FROM
    `tb_sale` a,
    `tb_goodsinfo` b,
    `tb_admin` c,
    `tb_member` d
  WHERE
    `a`.`admin_id` = `c`.`admin_id` AND `a`.`goods_id` = `b`.`goods_id` AND `a`.`mem_id` = `d`.`mem_id`) AS subtb
GROUP BY
  `sale_billnum`;";

                MySqlCommand    comm   = new MySqlCommand(mysqlstr, conn);
                MySqlDataReader reader = comm.ExecuteReader();
                while (reader.Read())
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = (++n).ToString();
                    item.SubItems.Add(reader.GetString(0));
                    var date = reader.GetMySqlDateTime(1);
                    item.SubItems.Add(string.Format("{0:D4}-{1:D2}-{2:D2} {3:D2}:{4:D2}:{5:D2}", date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second));
                    item.SubItems.Add(reader.GetString(2));
                    item.SubItems.Add(reader.GetString(3));
                    item.SubItems.Add(reader.GetString(5));
                    item.SubItems.Add(reader.GetString(6));
                    listView1.Items.Add(item);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e));
            }
            finally
            {
                conn.Close();
            }
            return(n);
        }
Ejemplo n.º 7
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;
            int    point    = Convert.ToInt32(numPoint.Value);
            int    level    = Convert.ToInt32(numLevel.Value);

            if (username.Length != 0 && password.Length != 0)
            {
                MySqlConnection conn = MysqlConnector.GetInstance();
                try
                {
                    conn.Open();
                    string       mysqlstr = string.Format("select mem_id from tb_member where mem_username='******';", username);
                    MySqlCommand comm     = new MySqlCommand(mysqlstr, conn);
                    object       reo      = comm.ExecuteScalar();
                    if (reo != null)
                    {
                        MessageBox.Show(this, "用户名已存在");
                    }
                    else
                    {
                        string       sqlstr = string.Format("insert into tb_member(mem_username,mem_password,mem_points,mem_level) value('{0}','{1}',{2},{3});", username, password, point, level);
                        MySqlCommand comm1  = new MySqlCommand(sqlstr, conn);
                        int          re     = comm1.ExecuteNonQuery();
                        if (re == 1)
                        {
                            ListViewItem item = new ListViewItem();
                            item.Text = ((listView1.Items.Count + 1).ToString());
                            item.SubItems.Add(username);
                            item.SubItems.Add(password);
                            item.SubItems.Add(point.ToString());
                            item.SubItems.Add(level.ToString());
                            listView1.Items.Add(item);
                            MessageBox.Show(this, "添加成功");
                        }
                        else
                        {
                            MessageBox.Show(this, "添加失败");
                        }
                    }
                }
                catch (Exception e1)
                {
                    MessageBox.Show(this, string.Format("Exception: {0}", e1));
                }
                finally
                {
                    conn.Close();
                }
            }
            else
            {
                MessageBox.Show(this, "用户名和密码不允许为空");
            }
        }
Ejemplo n.º 8
0
        private void btnChange_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show(this, "未选中任何项");
                return;
            }
            string username    = txtUsername.Text;
            string password    = txtPassword.Text;
            string oldusername = listView1.SelectedItems[0].SubItems[1].Text;

            MySqlConnection conn = MysqlConnector.GetInstance();

            try
            {
                conn.Open();
                if (!username.Equals(oldusername))
                {
                    string       sqlstr = string.Format("select admin_id from tb_admin where admin_username='******';", username);
                    MySqlCommand comm   = new MySqlCommand(sqlstr, conn);
                    object       re     = comm.ExecuteScalar();
                    if (re != null)
                    {
                        throw new AdminUsernameRepeat("用户名已存在");
                    }
                }
                string mysqlstr = string.Format("update tb_admin set admin_username='******',admin_password='******' where admin_username='******';",
                                                username, password, oldusername);
                MySqlCommand comm1 = new MySqlCommand(mysqlstr, conn);
                int          res   = comm1.ExecuteNonQuery();
                if (res != 0)
                {
                    listView1.SelectedItems[0].SubItems[1].Text = username;
                    listView1.SelectedItems[0].SubItems[2].Text = password;
                    MessageBox.Show(this, "修改成功");
                }
                else
                {
                    MessageBox.Show(this, "修改失败");
                }
            }
            catch (AdminUsernameRepeat e1)
            {
                MessageBox.Show(this, e1.Message);
            }
            catch (Exception e1)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e1));
            }
            finally
            {
                conn.Close();
            }
        }
        public int InitLvPurRecord()
        {
            listView1.Items.Clear();
            int             n    = 0;
            MySqlConnection conn = MysqlConnector.GetInstance();

            try
            {
                conn.Open();
                string mysqlstr =
                    @"SELECT
  *, COUNT(`money`) AS 'pinleishu', SUM(`money`) AS 'total'
FROM
  (SELECT
    `pur_billnum`, `pur_date`, `admin_username`, (`pur_amount` * `goods_inprice`) AS 'money'
  FROM
    `tb_purchase` a,
    `tb_goodsinfo` b,
    `tb_admin` c
  WHERE
    `a`.`admin_id` = `c`.`admin_id` AND `a`.`goods_id` = `b`.`goods_id`) AS subtable
GROUP BY
  `pur_billnum`;";

                MySqlCommand    comm   = new MySqlCommand(mysqlstr, conn);
                MySqlDataReader reader = comm.ExecuteReader();
                while (reader.Read())
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = (++n).ToString();
                    item.SubItems.Add(reader.GetString(0));
                    var date = reader.GetMySqlDateTime(1);
                    item.SubItems.Add(string.Format("{0:D4}-{1:D2}-{2:D2}", date.Year, date.Month, date.Day));
                    item.SubItems.Add(reader.GetString(2));
                    item.SubItems.Add(reader.GetString(4));
                    item.SubItems.Add(reader.GetString(5));
                    listView1.Items.Add(item);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e));
            }
            finally
            {
                conn.Close();
            }
            return(n);
        }
Ejemplo n.º 10
0
        private void btnChangeself_Click(object sender, EventArgs e)
        {
            string oldpassword = txtSelfOldPassword.Text;
            string password    = txtSelfNewPassword.Text;
            string confirm     = txtSelfConfirm.Text;

            if (oldpassword.Length != 0 && password.Length != 0 && confirm.Length != 0)
            {
                if (password.Equals(confirm))
                {
                    MySqlConnection conn = MysqlConnector.GetInstance();
                    try
                    {
                        conn.Open();
                        string mysqlstr = string.Format("update tb_admin set admin_password='******' where admin_id={1} and admin_password='******';",
                                                        password, GlobalVar.login.Id, oldpassword);
                        MySqlCommand comm = new MySqlCommand(mysqlstr, conn);
                        int          res  = comm.ExecuteNonQuery();
                        if (res != 0)
                        {
                            MessageBox.Show(this, "修改成功");
                            txtSelfConfirm.Text     = "";
                            txtSelfNewPassword.Text = "";
                            txtSelfOldPassword.Text = "";
                        }
                        else
                        {
                            MessageBox.Show(this, "修改失败");
                        }
                    }
                    catch (Exception e1)
                    {
                        MessageBox.Show(this, String.Format("Exception: {0}", e1));
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
                else
                {
                    MessageBox.Show(this, "两次输入的密码不一致");
                }
            }
            else
            {
                MessageBox.Show(this, "信息不能为空");
            }
        }
Ejemplo n.º 11
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show(this, "未选中任何项");
                return;
            }
            int             n        = listView1.SelectedItems[0].Index;
            string          username = listView1.SelectedItems[0].SubItems[1].Text;
            MySqlConnection conn     = MysqlConnector.GetInstance();

            try
            {
                conn.Open();
                string       sqlstr = string.Format("delete from tb_member where mem_username='******';", username);
                MySqlCommand comm   = new MySqlCommand(sqlstr, conn);
                int          re     = comm.ExecuteNonQuery();
                if (re == 1)
                {
                    RemoveItemAndUpdate(n);
                    MessageBox.Show(this, "删除成功");
                }
                else
                {
                    MessageBox.Show(this, "删除失败");
                }
            }
            catch (MySqlException e1)
            {
                MessageBox.Show(this, "无法删除此会员,因为此管理员有购买记录,不可删除!");
            }
            catch (Exception e1)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e1));
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 12
0
        private int InitLvAdmin()
        {
            listView1.Items.Clear();
            int             n    = 0;
            MySqlConnection conn = MysqlConnector.GetInstance();

            try
            {
                conn.Open();
                string          mysqlstr = "select * from tb_admin";
                MySqlCommand    comm     = new MySqlCommand(mysqlstr, conn);
                MySqlDataReader reader   = comm.ExecuteReader();
                while (reader.Read())
                {
                    if (reader.GetBoolean(3))
                    {
                        continue;
                    }
                    ListViewItem item = new ListViewItem();
                    item.Text = (++n).ToString();
                    item.SubItems.Add(reader.GetString(1));
                    item.SubItems.Add(reader.GetString(2));
                    listView1.Items.Add(item);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e));
            }
            finally
            {
                conn.Close();
            }
            return(n);
        }
Ejemplo n.º 13
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            bool   update   = false;
            string goodsnum = txtGoodsid.Text;
            int    amount   = Convert.ToInt32(numAmount.Value);

            if (goodsnum.Length == 0)
            {
                MessageBox.Show(this, "商品条码不能为空");
                return;
            }
            if (amount == 0)
            {
                MessageBox.Show(this, "数量不能为0");
                return;
            }

            int i = listvGoods.Items.Count;  // list中的项数
            int m = 0;

            for (m = 0; m < i; m++)
            {
                if (listvGoods.Items[m].SubItems[2].Text.Equals(goodsnum))
                {
                    break;
                }
            }
            if (m == i)
            {
                MySqlConnection conn = MysqlConnector.GetInstance();
                try
                {
                    conn.Open();
                    string          sqlstr = string.Format("select goods_name,goods_num,goods_price,goods_left from tb_goodsinfo where goods_num='{0}';", goodsnum);
                    MySqlCommand    comm   = new MySqlCommand(sqlstr, conn);
                    MySqlDataReader reader = comm.ExecuteReader();
                    if (reader.Read())
                    {
                        inventory.Add(goodsnum, reader.GetInt32(3));
                        if (amount > inventory[goodsnum])
                        {
                            reader.Close();
                            inventoryNotEnoughEvent();
                        }
                        MakeBillNum();
                        ListViewItem item = new ListViewItem();
                        item.Text = (i + 1).ToString();
                        item.SubItems.Add(reader.GetString(0));
                        item.SubItems.Add(reader.GetString(1));
                        item.SubItems.Add(reader.GetDouble(2).ToString());
                        item.SubItems.Add(amount.ToString());
                        item.SubItems.Add((reader.GetDouble(2) * amount).ToString());
                        listvGoods.Items.Add(item);
                        update = true;
                    }
                    else
                    {
                        MessageBox.Show(this, "未查询到商品信息,请先添加商品信息");
                    }
                }
                catch (InventoryNotEnoughException e1)
                {
                    MessageBox.Show(this, e1.Message);
                }
                catch (Exception e1)
                {
                    MessageBox.Show(this, string.Format("Exception: {0}", e1));
                }
                finally
                {
                    conn.Close();
                }
            }
            else
            {
                int oldn = Convert.ToInt32(listvGoods.Items[m].SubItems[4].Text);
                if ((oldn + amount) > inventory[goodsnum])
                {
                    MessageBox.Show(this, "库存不足");
                    return;
                }
                double price = Convert.ToDouble(listvGoods.Items[m].SubItems[3].Text);
                double money = (oldn + amount) * price;
                listvGoods.Items[m].SubItems[4].Text = (oldn + amount).ToString();
                listvGoods.Items[m].SubItems[5].Text = money.ToString();
                update = true;
            }
            if (update)
            {
                SumMoneyAndUpdate();
            }
        }
Ejemplo n.º 14
0
        private void btnSum_Click(object sender, EventArgs e)
        {
            string billnum = txtBillnum.Text;
            string mem_num = txtMemberId.Text;
            string money   = numMoney.Value.ToString();
            string sum     = txtSum.Text;

            if (Convert.ToDouble(money) < Convert.ToDouble(sum))
            {
                MessageBox.Show(this, "实付款不得小于总金额");
                return;
            }
            if (mem_num.Length == 0)
            {
                MessageBox.Show(this, "会员卡号不能为空");
                return;
            }

            MySqlConnection conn = MysqlConnector.GetInstance();

            try
            {
                conn.Open();
                string       sqlstr = string.Format("select sale_id from tb_sale where sale_billnum='{0}';", billnum);
                MySqlCommand comm   = new MySqlCommand(sqlstr, conn);
                object       re     = comm.ExecuteScalar();
                if (re != null)
                {
                    throw new SaleBillnumRepeat("流水号重复");
                }
                int memid = GetMemberId(mem_num, conn);
                if (memid == 0)
                {
                    throw new NoneGoodsNum("会员卡号不存在");
                }
                string mysqlstr = "";
                foreach (ListViewItem item in listvGoods.Items)
                {
                    int goodsid = GetGoodsId(item.SubItems[2].Text, conn);
                    if (goodsid == 0)
                    {
                        throw new NoneGoodsNum(string.Format("商品编号:{0},不存在", item.SubItems[2].Text));
                    }
                    mysqlstr += string.Format("insert into tb_sale(mem_id,goods_id,sale_amount, sale_billnum, sale_money,admin_id,sale_datetime) value({0},{1},{2},'{3}',{4},'{5}','{6}-{7}-{8} {9}:{10}:{11}');",
                                              memid, goodsid, item.SubItems[4].Text, billnum, money, GlobalVar.login.Id,
                                              billnum.Substring(0, 4),
                                              billnum.Substring(4, 2),
                                              billnum.Substring(6, 2),
                                              billnum.Substring(8, 2),
                                              billnum.Substring(10, 2),
                                              billnum.Substring(12, 2));
                    mysqlstr += string.Format("update tb_goodsinfo set goods_left=goods_left-{0} where goods_id='{1}';", item.SubItems[4].Text, goodsid);
                }
                mysqlstr += string.Format("update tb_member set mem_points=mem_points+{0} where mem_id='{1}';", sum, memid);
                MySqlCommand comm1 = new MySqlCommand(mysqlstr, conn);
                int          res   = comm1.ExecuteNonQuery();
                if (res != 0)
                {
                    MessageBox.Show(this, "结算成功");
                    inventory.Clear();
                    listvGoods.Items.Clear();
                    txtBillnum.Text  = "";
                    txtGoodsid.Text  = "";
                    txtMemberId.Text = "";
                    numAmount.Value  = 1;
                    numMoney.Value   = 0;
                    txtSum.Text      = "0";
                }
                else
                {
                    MessageBox.Show(this, "结算失败");
                }
            }
            catch (SaleBillnumRepeat e1)
            {
                MessageBox.Show(this, e1.Message);
            }
            catch (NoneMemberNum e1)
            {
                MessageBox.Show(this, e1.Message);
            }
            catch (NoneGoodsNum e1)
            {
                MessageBox.Show(this, e1.Message);
            }
            catch (Exception e1)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e1));
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 15
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            bool   update = false;
            string id     = txtGoodsid.Text;
            int    n      = Convert.ToInt32(numAmount.Value);

            if (id.Length == 0)
            {
                MessageBox.Show(this, "商品id不能为空");
                return;
            }
            if (n == 0)
            {
                MessageBox.Show(this, "数量不得为0");
                return;
            }
            int i = listView1.Items.Count;  // list中的项数
            int m = 0;

            for (m = 0; m < i; m++)
            {
                if (listView1.Items[m].SubItems[2].Text.Equals(id))
                {
                    break;
                }
            }
            if (m == i)
            {
                MySqlConnection conn = MysqlConnector.GetInstance();
                try
                {
                    conn.Open();
                    string          sqlstr = string.Format("select goods_name,goods_num,goods_inprice from tb_goodsinfo where goods_num='{0}';", id);
                    MySqlCommand    comm   = new MySqlCommand(sqlstr, conn);
                    MySqlDataReader reader = comm.ExecuteReader();
                    if (reader.Read())
                    {
                        ListViewItem item = new ListViewItem();
                        item.Text = (i + 1).ToString();
                        item.SubItems.Add(reader.GetString(0));
                        item.SubItems.Add(reader.GetString(1));
                        item.SubItems.Add(reader.GetDouble(2).ToString());
                        item.SubItems.Add(n.ToString());
                        item.SubItems.Add((reader.GetDouble(2) * n).ToString());
                        listView1.Items.Add(item);
                        update = true;
                    }
                    else
                    {
                        MessageBox.Show(this, "未查询到商品信息,请先添加商品信息");
                    }
                }
                catch (Exception e1)
                {
                    MessageBox.Show(this, string.Format("Exception: {0}", e1));
                }
                finally
                {
                    conn.Close();
                }
            }
            else
            {
                int    oldn    = Convert.ToInt32(listView1.Items[m].SubItems[4].Text);
                double inprice = Convert.ToDouble(listView1.Items[m].SubItems[3].Text);
                double money   = (oldn + n) * inprice;
                listView1.Items[m].SubItems[4].Text = (oldn + n).ToString();
                listView1.Items[m].SubItems[5].Text = money.ToString();
                update = true;
            }
            if (update)
            {
                SumMoneyAndUpdate();
            }
        }
Ejemplo n.º 16
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string billnum = txtBillnum.Text;
            string date    = dtTime.Text;

            if (billnum.Length == 0)
            {
                MessageBox.Show(this, "流水号不能为空");
                return;
            }
            MySqlConnection conn = MysqlConnector.GetInstance();

            try
            {
                conn.Open();
                string       sqlstr = string.Format("select pur_id from tb_purchase where pur_billnum='{0}';", billnum);
                MySqlCommand comm   = new MySqlCommand(sqlstr, conn);
                object       re     = comm.ExecuteScalar();
                if (re != null)
                {
                    throw new PurBillnumRepeat("流水号重复");
                }
                string mysqlstr = "";
                foreach (ListViewItem item in listView1.Items)
                {
                    int goodsid = GetGoodsId(item.SubItems[2].Text, conn);
                    if (goodsid == 0)
                    {
                        throw new NoneGoodsNum(string.Format("商品编号:{0},不存在", item.SubItems[2].Text));
                    }
                    int goodsleft = GetGoodsInventory(item.SubItems[2].Text, conn);
                    mysqlstr += string.Format("insert into tb_purchase(pur_billnum,goods_id,pur_amount,admin_id,pur_date) value('{0}',{1},{2},{3},'{4}');",
                                              billnum, goodsid, item.SubItems[4].Text, GlobalVar.login.Id, date);
                    mysqlstr += string.Format("update tb_goodsinfo set goods_left={0} where goods_id='{1}';", goodsleft + Convert.ToInt32(item.SubItems[4].Text), goodsid);
                }

                MySqlCommand comm1 = new MySqlCommand(mysqlstr, conn);
                int          res   = comm1.ExecuteNonQuery();
                if (res != 0)
                {
                    MessageBox.Show(this, "提交成功");
                    listView1.Items.Clear();
                    txtBillnum.Text = "";
                    txtGoodsid.Text = "";
                    numAmount.Value = 0;
                    txtSum.Text     = "0";
                }
                else
                {
                    MessageBox.Show(this, "提交失败");
                }
            }
            catch (PurBillnumRepeat e1)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e1.Message));
            }
            catch (NoneGoodsNum e1)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e1.Message));
            }
            catch (Exception e1)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e1));
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 17
0
        private void btnChange_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show(this, "未选中任何项");
                return;
            }
            string name      = txtName.Text;
            string id        = txtId.Text;
            double inprice   = Convert.ToDouble(numInprice.Value);
            double price     = Convert.ToDouble(numPrice.Value);
            int    inventory = Convert.ToInt32(numInventory.Value);
            string kind      = txtKind.Text;
            string oldid     = listView1.SelectedItems[0].SubItems[2].Text;

            MySqlConnection conn = MysqlConnector.GetInstance();

            try
            {
                conn.Open();
                if (!id.Equals(oldid))
                {
                    string       sqlstr = string.Format("select * from tb_goodsinfo where goods_num='{0}';", id);
                    MySqlCommand comm   = new MySqlCommand(sqlstr, conn);
                    object       re     = comm.ExecuteScalar();
                    if (re != null)
                    {
                        throw new GoodsIDRepeatException("商品信息重复");
                    }
                }
                string mysqlstr = string.Format("update tb_goodsinfo set goods_name='{0}',goods_num='{1}',goods_inprice={2},goods_price={3},goods_left={4},goods_kind='{5}' where goods_num='{6}';",
                                                name, id, inprice, price, inventory, kind, oldid);
                MySqlCommand comm1 = new MySqlCommand(mysqlstr, conn);
                int          res   = comm1.ExecuteNonQuery();
                if (res == 1)
                {
                    listView1.SelectedItems[0].SubItems[1].Text = name;
                    listView1.SelectedItems[0].SubItems[2].Text = id;
                    listView1.SelectedItems[0].SubItems[3].Text = inprice.ToString();
                    listView1.SelectedItems[0].SubItems[4].Text = price.ToString();
                    listView1.SelectedItems[0].SubItems[5].Text = inventory.ToString();
                    listView1.SelectedItems[0].SubItems[6].Text = kind;
                    MessageBox.Show(this, "修改成功");
                }
                else
                {
                    MessageBox.Show(this, "修改失败");
                }
            }
            catch (GoodsIDRepeatException e1)
            {
                MessageBox.Show(this, e1.Message);
            }
            catch (Exception e1)
            {
                MessageBox.Show(this, string.Format("Exception: {0}", e1));
            }
            finally
            {
                conn.Close();
            }
        }