예제 #1
0
        //ListAll
        public List <Ob_SP_HinhAnh> _ListAll_sp(string StoredName, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_SP_HinhAnh> list    = new List <Ob_SP_HinhAnh>();
            SqlCommand           command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_SP_HinhAnh ob = new Ob_SP_HinhAnh();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_HINHANH = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.ID_SANPHAM = Convert.ToInt32(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENHINH = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.HINH = (byte[])(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.CREATEDBY = Convert.ToString(reader[7]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
예제 #2
0
        //DeleteOB
        public bool _DeleteOb(Ob_SP_HinhAnh ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From SP_HinhAnh Where ID_HinhAnh=@ID_HinhAnh"
            };

            command.Parameters.Add(new SqlParameter("ID_HinhAnh", ob.ID_HINHANH));
            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
        //ListWhere
        public List <Ob_SP_HinhAnh> _ListWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_SP_HinhAnh> list    = new List <Ob_SP_HinhAnh>();
            SqlCommand           command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_HinhAnh, ID_SanPham, TenHinh, Hinh, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy From SP_HinhAnh Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_SP_HinhAnh ob = new Ob_SP_HinhAnh();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_HINHANH = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.ID_SANPHAM = Convert.ToInt32(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENHINH = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.HINH = (byte[])(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.CREATEDBY = Convert.ToString(reader[7]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
예제 #4
0
 public Ob_SP_HinhAnh(Ob_SP_HinhAnh newOb)
 {
     id_hinhanh   = newOb.ID_HINHANH;
     id_sanpham   = newOb.ID_SANPHAM;
     tenhinh      = newOb.TENHINH;
     hinh         = newOb.HINH;
     modifiedtime = newOb.MODIFIEDTIME;
     modifiedby   = newOb.MODIFIEDBY;
     createdtime  = newOb.CREATEDTIME;
     createdby    = newOb.CREATEDBY;
 }
예제 #5
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_SP_HinhAnh ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update SP_HinhAnh Set ID_SanPham=@ID_SanPham, TenHinh=@TenHinh, Hinh=@Hinh, ModifiedTime=@ModifiedTime, ModifiedBy=@ModifiedBy, CreatedTime=@CreatedTime, CreatedBy=@CreatedBy Where ID_HinhAnh=@ID_HinhAnh"
            };

            command.Parameters.Add("ID_HinhAnh", SqlDbType.Int).Value = ob.ID_HINHANH;
            command.Parameters.Add("ID_SanPham", SqlDbType.Int).Value = ob.ID_SANPHAM;
            if (ob.TENHINH.Trim() == "")
            {
                command.Parameters.Add("TenHinh", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("TenHinh", SqlDbType.NVarChar).Value = ob.TENHINH;
            }
            if (ob.HINH == null)
            {
                command.Parameters.Add("Hinh", SqlDbType.Image).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("Hinh", SqlDbType.Image).Value = ob.HINH;
            }
            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;
            }
            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;
            }
            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);
        }
예제 #6
0
        //InsertobGetId
        public int _InsertObGetId(Ob_SP_HinhAnh ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into SP_HinhAnh (ID_SanPham, TenHinh, Hinh, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy) Values(@ID_SanPham, @TenHinh, @Hinh, @ModifiedTime, @ModifiedBy, @CreatedTime, @CreatedBy)Select @@IDENTITY"
                };
                command.Parameters.Add("ID_SanPham", SqlDbType.Int).Value = ob.ID_SANPHAM;
                if (ob.TENHINH.Trim() == "")
                {
                    command.Parameters.Add("TenHinh", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("TenHinh", SqlDbType.NVarChar).Value = ob.TENHINH;
                }
                if (ob.HINH == null)
                {
                    command.Parameters.Add("Hinh", SqlDbType.Image).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("Hinh", SqlDbType.Image).Value = ob.HINH;
                }
                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;
                }
                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;
                }
                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);
        }