コード例 #1
0
        //InsertobGetId
        public int _InsertObGetId(Ob_DH_SPMua ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into DH_SPMua (ID_SanPham, ID_NhomGiaoHang) Values(@ID_SanPham, @ID_NhomGiaoHang)Select @@IDENTITY"
                };
                command.Parameters.Add("ID_SanPham", SqlDbType.Int).Value      = ob.ID_SANPHAM;
                command.Parameters.Add("ID_NhomGiaoHang", SqlDbType.Int).Value = ob.ID_NHOMGIAOHANG;
                try
                {
                    num = Convert.ToInt32(command.ExecuteScalar());
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Không thể thêm dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    command.Dispose();
                    command = null;
                    conn.Close();
                    return(num);
                }
                command.Dispose();
                command = null;
                conn.Close();
            }
            return(num);
        }
コード例 #2
0
        //DeleteOB
        public bool _DeleteOb(Ob_DH_SPMua ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From DH_SPMua Where ID_SanPham=@ID_SanPham"
            };

            command.Parameters.Add(new SqlParameter("ID_SanPham", ob.ID_SANPHAM));
            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Không thể xóa dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                command.Dispose();
                command = null;
                conn.Close();
                return(false);
            }
            command.Dispose();
            command = null;
            conn.Close();
            return(true);
        }
コード例 #3
0
        //Insert ob
        public bool _InsertOb(Ob_DH_SPMua ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Insert Into DH_SPMua (ID_SanPham, ID_NhomGiaoHang) Values(@ID_SanPham, @ID_NhomGiaoHang)"
            };

            command.Parameters.Add("ID_SanPham", SqlDbType.Int).Value      = ob.ID_SANPHAM;
            command.Parameters.Add("ID_NhomGiaoHang", SqlDbType.Int).Value = ob.ID_NHOMGIAOHANG;
            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Không thể thêm dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                command.Dispose();
                command = null;
                conn.Close();
                return(false);
            }
            command.Dispose();
            command = null;
            conn.Close();
            return(true);
        }
コード例 #4
0
        //GetObWhere
        public Ob_DH_SPMua _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_DH_SPMua ob      = new Ob_DH_SPMua();
            SqlCommand  command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_SanPham, ID_NhomGiaoHang From DH_SPMua Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_SANPHAM = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.ID_NHOMGIAOHANG = Convert.ToInt32(reader[1]);
                }
            }
            if (num == 0)
            {
                command.Dispose();
                command = null;
                reader.Dispose();
                reader = null;
                conn.Close();
                return(null);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(ob);
        }
コード例 #5
0
        //ListWhere_sp
        public List <Ob_DH_SPMua> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DH_SPMua> list    = new List <Ob_DH_SPMua>();
            SqlCommand         command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };

            command.Parameters.AddRange(ArrayParameter);
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_DH_SPMua ob = new Ob_DH_SPMua();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_SANPHAM = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.ID_NHOMGIAOHANG = Convert.ToInt32(reader[1]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
コード例 #6
0
        //ListAll
        public List <Ob_DH_SPMua> _ListAll(SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DH_SPMua> list    = new List <Ob_DH_SPMua>();
            SqlCommand         command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_SanPham, ID_NhomGiaoHang From DH_SPMua"
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_DH_SPMua ob = new Ob_DH_SPMua();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_SANPHAM = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.ID_NHOMGIAOHANG = Convert.ToInt32(reader[1]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
コード例 #7
0
ファイル: Ob_DH_SPMua.cs プロジェクト: hichita1324/Obj_Bitas
 public Ob_DH_SPMua(Ob_DH_SPMua newOb)
 {
     id_sanpham      = newOb.ID_SANPHAM;
     id_nhomgiaohang = newOb.ID_NHOMGIAOHANG;
 }