//DeleteOB
        public bool _DeleteOb(Ob_SP_BangGia ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From SP_BangGia Where ID_BangGia=@ID_BangGia"
            };

            command.Parameters.Add(new SqlParameter("ID_BangGia", ob.ID_BANGGIA));
            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);
        }
 public Ob_SP_BangGia(Ob_SP_BangGia newOb)
 {
     id_banggia   = newOb.ID_BANGGIA;
     id_barcode   = newOb.ID_BARCODE;
     ngaybatdau   = newOb.NGAYBATDAU;
     dongia       = newOb.DONGIA;
     giamgia      = newOb.GIAMGIA;
     createdtime  = newOb.CREATEDTIME;
     createdby    = newOb.CREATEDBY;
     modifiedtime = newOb.MODIFIEDTIME;
     modifiedby   = newOb.MODIFIEDBY;
 }
        //ListAll
        public List <Ob_SP_BangGia> _ListAll_sp(string StoredName, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_SP_BangGia> list    = new List <Ob_SP_BangGia>();
            SqlCommand           command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_SP_BangGia ob = new Ob_SP_BangGia();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_BANGGIA = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.ID_BARCODE = Convert.ToInt32(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.NGAYBATDAU = Convert.ToDateTime(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.DONGIA = Convert.ToDouble(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.GIAMGIA = Convert.ToBoolean(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CREATEDBY = Convert.ToString(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[7]);
                }
                if (reader[8] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[8]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
        //UpdateOb ob
        public bool _UpdateOb(Ob_SP_BangGia ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update SP_BangGia Set ID_Barcode=@ID_Barcode, NgayBatDau=@NgayBatDau, DonGia=@DonGia, GiamGia=@GiamGia, CreatedTime=@CreatedTime, CreatedBy=@CreatedBy, ModifiedTime=@ModifiedTime, ModifiedBy=@ModifiedBy Where ID_BangGia=@ID_BangGia and ID_Barcode=@ID_Barcode and NgayBatDau=@NgayBatDau"
            };

            command.Parameters.Add("ID_BangGia", SqlDbType.Int).Value = ob.ID_BANGGIA;
            command.Parameters.Add("ID_Barcode", SqlDbType.Int).Value = ob.ID_BARCODE;
            if (ob.NGAYBATDAU == DateTime.MinValue)
            {
                command.Parameters.Add("NgayBatDau", SqlDbType.DateTime).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("NgayBatDau", SqlDbType.DateTime).Value = ob.NGAYBATDAU;
            }
            command.Parameters.Add("DonGia", SqlDbType.Money).Value = ob.DONGIA;
            command.Parameters.Add("GiamGia", SqlDbType.Bit).Value  = ob.GIAMGIA;
            if (ob.CREATEDTIME == DateTime.MinValue)
            {
                command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = ob.CREATEDTIME;
            }
            if (ob.CREATEDBY.Trim() == "")
            {
                command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = ob.CREATEDBY;
            }
            if (ob.MODIFIEDTIME == DateTime.MinValue)
            {
                command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = ob.MODIFIEDTIME;
            }
            if (ob.MODIFIEDBY.Trim() == "")
            {
                command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = ob.MODIFIEDBY;
            }
            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Không thể cập nhật dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                command.Dispose();
                command = null;
                conn.Close();
                return(false);
            }
            if (command.ExecuteNonQuery() == 0)
            {
                MessageBox.Show("Không thể cập nhật dữ liệu. \r\n", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                command.Dispose();
                command = null;
                conn.Close();
                return(false);
            }
            command.Dispose();
            command = null;
            conn.Close();
            return(true);
        }
        //InsertobGetId
        public int _InsertObGetId(Ob_SP_BangGia ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into SP_BangGia (ID_BangGia, ID_Barcode, NgayBatDau, DonGia, GiamGia, CreatedTime, CreatedBy, ModifiedTime, ModifiedBy) Values(@ID_BangGia, @ID_Barcode, @NgayBatDau, @DonGia, @GiamGia, @CreatedTime, @CreatedBy, @ModifiedTime, @ModifiedBy)Select @@IDENTITY"
                };
                command.Parameters.Add("ID_BangGia", SqlDbType.Int).Value = ob.ID_BANGGIA;
                command.Parameters.Add("ID_Barcode", SqlDbType.Int).Value = ob.ID_BARCODE;
                if (ob.NGAYBATDAU == DateTime.MinValue)
                {
                    command.Parameters.Add("NgayBatDau", SqlDbType.DateTime).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("NgayBatDau", SqlDbType.DateTime).Value = ob.NGAYBATDAU;
                }
                command.Parameters.Add("DonGia", SqlDbType.Money).Value = ob.DONGIA;
                command.Parameters.Add("GiamGia", SqlDbType.Bit).Value  = ob.GIAMGIA;
                if (ob.CREATEDTIME == DateTime.MinValue)
                {
                    command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = ob.CREATEDTIME;
                }
                if (ob.CREATEDBY.Trim() == "")
                {
                    command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = ob.CREATEDBY;
                }
                if (ob.MODIFIEDTIME == DateTime.MinValue)
                {
                    command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = ob.MODIFIEDTIME;
                }
                if (ob.MODIFIEDBY.Trim() == "")
                {
                    command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = ob.MODIFIEDBY;
                }
                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);
        }
        //GetObWhere
        public Ob_SP_BangGia _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_SP_BangGia ob      = new Ob_SP_BangGia();
            SqlCommand    command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_BangGia, ID_Barcode, NgayBatDau, DonGia, GiamGia, CreatedTime, CreatedBy, ModifiedTime, ModifiedBy From SP_BangGia Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_BANGGIA = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.ID_BARCODE = Convert.ToInt32(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.NGAYBATDAU = Convert.ToDateTime(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.DONGIA = Convert.ToDouble(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.GIAMGIA = Convert.ToBoolean(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CREATEDBY = Convert.ToString(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[7]);
                }
                if (reader[8] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[8]);
                }
            }
            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);
        }