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

            command.Parameters.Add(new SqlParameter("ID_CuaHang", ob.ID_CUAHANG));
            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);
        }
        //ListWhere_sp
        public List <Ob_POS_DM_CuaHang> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_POS_DM_CuaHang> list = new List <Ob_POS_DM_CuaHang>();
            SqlCommand command            = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };

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

            while (reader.Read())
            {
                Ob_POS_DM_CuaHang ob = new Ob_POS_DM_CuaHang();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_CUAHANG = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MACUAHANG = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENCUAHANG = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.POS = Convert.ToInt32(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.ID_KHO = Convert.ToInt32(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.DIACHI = Convert.ToString(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.DIENTHOAI = Convert.ToString(reader[6]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
        //ListAll
        public List <Ob_POS_DM_CuaHang> _ListAll(SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_POS_DM_CuaHang> list = new List <Ob_POS_DM_CuaHang>();
            SqlCommand command            = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_CuaHang, MaCuaHang, TenCuaHang, POS, ID_Kho, DiaChi, DienThoai From POS_DM_CuaHang"
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_POS_DM_CuaHang ob = new Ob_POS_DM_CuaHang();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_CUAHANG = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MACUAHANG = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENCUAHANG = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.POS = Convert.ToInt32(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.ID_KHO = Convert.ToInt32(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.DIACHI = Convert.ToString(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.DIENTHOAI = Convert.ToString(reader[6]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
        //UpdateOb ob
        public bool _UpdateOb(Ob_POS_DM_CuaHang ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update POS_DM_CuaHang Set MaCuaHang=@MaCuaHang, TenCuaHang=@TenCuaHang, POS=@POS, ID_Kho=@ID_Kho, DiaChi=@DiaChi, DienThoai=@DienThoai Where ID_CuaHang=@ID_CuaHang"
            };

            command.Parameters.Add("ID_CuaHang", SqlDbType.Int).Value = ob.ID_CUAHANG;
            if (ob.MACUAHANG.Trim() == "")
            {
                command.Parameters.Add("MaCuaHang", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("MaCuaHang", SqlDbType.VarChar).Value = ob.MACUAHANG;
            }
            if (ob.TENCUAHANG.Trim() == "")
            {
                command.Parameters.Add("TenCuaHang", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("TenCuaHang", SqlDbType.NVarChar).Value = ob.TENCUAHANG;
            }
            command.Parameters.Add("POS", SqlDbType.Int).Value    = ob.POS;
            command.Parameters.Add("ID_Kho", SqlDbType.Int).Value = ob.ID_KHO;
            if (ob.DIACHI.Trim() == "")
            {
                command.Parameters.Add("DiaChi", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("DiaChi", SqlDbType.NVarChar).Value = ob.DIACHI;
            }
            if (ob.DIENTHOAI.Trim() == "")
            {
                command.Parameters.Add("DienThoai", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("DienThoai", SqlDbType.VarChar).Value = ob.DIENTHOAI;
            }
            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_POS_DM_CuaHang ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into POS_DM_CuaHang (MaCuaHang, TenCuaHang, POS, ID_Kho, DiaChi, DienThoai) Values(@MaCuaHang, @TenCuaHang, @POS, @ID_Kho, @DiaChi, @DienThoai)Select @@IDENTITY"
                };
                if (ob.MACUAHANG.Trim() == "")
                {
                    command.Parameters.Add("MaCuaHang", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("MaCuaHang", SqlDbType.VarChar).Value = ob.MACUAHANG;
                }
                if (ob.TENCUAHANG.Trim() == "")
                {
                    command.Parameters.Add("TenCuaHang", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("TenCuaHang", SqlDbType.NVarChar).Value = ob.TENCUAHANG;
                }
                command.Parameters.Add("POS", SqlDbType.Int).Value    = ob.POS;
                command.Parameters.Add("ID_Kho", SqlDbType.Int).Value = ob.ID_KHO;
                if (ob.DIACHI.Trim() == "")
                {
                    command.Parameters.Add("DiaChi", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("DiaChi", SqlDbType.NVarChar).Value = ob.DIACHI;
                }
                if (ob.DIENTHOAI.Trim() == "")
                {
                    command.Parameters.Add("DienThoai", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("DienThoai", SqlDbType.VarChar).Value = ob.DIENTHOAI;
                }
                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_POS_DM_CuaHang _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_POS_DM_CuaHang ob      = new Ob_POS_DM_CuaHang();
            SqlCommand        command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_CuaHang, MaCuaHang, TenCuaHang, POS, ID_Kho, DiaChi, DienThoai From POS_DM_CuaHang Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_CUAHANG = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MACUAHANG = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENCUAHANG = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.POS = Convert.ToInt32(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.ID_KHO = Convert.ToInt32(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.DIACHI = Convert.ToString(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.DIENTHOAI = Convert.ToString(reader[6]);
                }
            }
            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);
        }