Exemplo n.º 1
0
        public List <Goods> FindAllGoods()
        {
            List <Goods>    list   = new List <Goods>();
            string          sql    = "select * from goods g,seller s where g.s_id = s.id ";
            MySqlConnection conn   = GetConnection.getConnection();
            MySqlCommand    comd   = new MySqlCommand(sql, conn);
            MySqlDataReader reader = comd.ExecuteReader();

            while (reader.Read())
            {
                Goods g = new Goods();
                g       = new Goods();
                g.id    = reader.GetInt32(0);
                g.name  = reader.GetString(1);
                g.price = reader.GetDouble(2);

                Seller s = new Seller();
                s.id     = reader.GetInt32(4);
                s.name   = reader.GetString(5);
                g.seller = s;

                list.Add(g);
            }
            return(list);
        }
Exemplo n.º 2
0
        public void Save(OrderForm form)
        {
            //先插入大订单的,得到id 然后在对小订单表进行插入操作
            //1.
            int             c_id    = form.customer.id;
            double          s_money = form.s_money;
            string          o_date  = form.o_date;
            MySqlConnection conn    = GetConnection.getConnection();
            string          sql     = string.Format("insert into orderform(c_id,s_money,o_date) values({0},{1},{2}) ;select @@identity;", c_id, s_money, o_date);
            MySqlCommand    cmd     = new MySqlCommand(sql, conn);
            object          o       = cmd.ExecuteScalar();//拿到当前插入的id

            Console.WriteLine(o + "--------");
            List <OrderLine> list = form.lines;
        }
Exemplo n.º 3
0
        public void AddGood(Goods g, int s_id)
        {
            string          sql  = string.Format("insert into goods(name,price,s_id) values('{0}',{1},{2})", g.name, g.price, s_id);
            MySqlConnection conn = GetConnection.getConnection();
            MySqlCommand    comd = new MySqlCommand(sql, conn);

            if (comd.ExecuteNonQuery() > 0)
            {
                Console.WriteLine("插入成功");
            }
            else
            {
                Console.WriteLine("插入失败");
            }
            conn.Close();
        }
Exemplo n.º 4
0
        public void SaveCustomer(Customer c)
        {
            string          sql  = string.Format("insert into customer(name,psw,address,telphone) values('{0}','{1}','{2}','{3}')", c.name, c.psw, c.address, c.telphone);
            MySqlConnection conn = GetConnection.getConnection();
            MySqlCommand    comd = new MySqlCommand(sql, conn);

            if (comd.ExecuteNonQuery() > 0)
            {
                Console.WriteLine("插入成功");
            }
            else
            {
                Console.WriteLine("插入失败");
            }
            conn.Close();
        }
Exemplo n.º 5
0
        public Seller FindSellerByName(string name)
        {
            Seller          seller = null;
            string          sql    = "select * from seller where name = '" + name + "'";
            MySqlConnection conn   = GetConnection.getConnection();
            MySqlCommand    comd   = new MySqlCommand(sql, conn);
            MySqlDataReader reader = comd.ExecuteReader();

            while (reader.Read())
            {
                seller      = new Seller();
                seller.id   = reader.GetInt32(0);
                seller.name = reader.GetString(1);
                seller.psw  = reader.GetString(2);
            }
            return(seller);
        }
Exemplo n.º 6
0
        public Goods FindGoodByName(string name)
        {
            Goods           g      = null;
            string          sql    = "select * from goods where name ='" + name + "'";
            MySqlConnection conn   = GetConnection.getConnection();
            MySqlCommand    comd   = new MySqlCommand(sql, conn);
            MySqlDataReader reader = comd.ExecuteReader();

            while (reader.Read())
            {
                g       = new Goods();
                g.id    = reader.GetInt32(0);
                g.name  = reader.GetString(1);
                g.price = reader.GetDouble(2);
            }
            conn.Close();
            return(g);
        }
Exemplo n.º 7
0
        public List <Goods> FindGoodsBySellerId(int id)
        {
            List <Goods>    list   = new List <Goods>();
            string          sql    = "select * from goods where s_id = " + id;
            MySqlConnection conn   = GetConnection.getConnection();
            MySqlCommand    comd   = new MySqlCommand(sql, conn);
            MySqlDataReader reader = comd.ExecuteReader();

            while (reader.Read())
            {
                Goods g = new Goods();
                g       = new Goods();
                g.id    = reader.GetInt32(0);
                g.name  = reader.GetString(1);
                g.price = reader.GetDouble(2);
                list.Add(g);
            }
            return(list);
        }
Exemplo n.º 8
0
        public Customer FindCustomerByName(string name)
        {
            Customer        c      = null;
            string          sql    = "select * from customer where name = '" + name + "'";
            MySqlConnection conn   = GetConnection.getConnection();
            MySqlCommand    comd   = new MySqlCommand(sql, conn);
            MySqlDataReader reader = comd.ExecuteReader();

            while (reader.Read())
            {
                c          = new Customer();
                c.id       = reader.GetInt32(0);
                c.name     = reader.GetString(1);
                c.psw      = reader.GetString(2);
                c.telphone = reader.GetString(3);
                c.address  = reader.GetString(4);
            }
            conn.Close();
            return(c);
        }