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

            command.Parameters.Add(new SqlParameter("ID_NhomSize", ob.ID_NHOMSIZE));
            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);
        }
Esempio n. 2
0
 public Ob_DM_NhomSize_H(Ob_DM_NhomSize_H newOb)
 {
     id_nhomsize  = newOb.ID_NHOMSIZE;
     manhomsize   = newOb.MANHOMSIZE;
     sizemin      = newOb.SIZEMIN;
     sizemax      = newOb.SIZEMAX;
     idx          = newOb.IDX;
     modifiedtime = newOb.MODIFIEDTIME;
     modifiedby   = newOb.MODIFIEDBY;
     createdtime  = newOb.CREATEDTIME;
     createdby    = newOb.CREATEDBY;
 }
        //ListAll
        public List <Ob_DM_NhomSize_H> _ListAll_sp(string StoredName, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DM_NhomSize_H> list = new List <Ob_DM_NhomSize_H>();
            SqlCommand command           = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_DM_NhomSize_H ob = new Ob_DM_NhomSize_H();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_NHOMSIZE = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MANHOMSIZE = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.SIZEMIN = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.SIZEMAX = Convert.ToString(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.IDX = Convert.ToInt32(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[7]);
                }
                if (reader[8] != DBNull.Value)
                {
                    ob.CREATEDBY = 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_DM_NhomSize_H ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update DM_NhomSize_H Set MaNhomSize=@MaNhomSize, SizeMin=@SizeMin, SizeMax=@SizeMax, idx=@idx, ModifiedTime=@ModifiedTime, ModifiedBy=@ModifiedBy, CreatedTime=@CreatedTime, CreatedBy=@CreatedBy Where ID_NhomSize=@ID_NhomSize"
            };

            command.Parameters.Add("ID_NhomSize", SqlDbType.Int).Value = ob.ID_NHOMSIZE;
            if (ob.MANHOMSIZE.Trim() == "")
            {
                command.Parameters.Add("MaNhomSize", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("MaNhomSize", SqlDbType.VarChar).Value = ob.MANHOMSIZE;
            }
            if (ob.SIZEMIN.Trim() == "")
            {
                command.Parameters.Add("SizeMin", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("SizeMin", SqlDbType.VarChar).Value = ob.SIZEMIN;
            }
            if (ob.SIZEMAX.Trim() == "")
            {
                command.Parameters.Add("SizeMax", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("SizeMax", SqlDbType.VarChar).Value = ob.SIZEMAX;
            }
            command.Parameters.Add("idx", SqlDbType.Int).Value = ob.IDX;
            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);
        }
        //InsertobGetId
        public int _InsertObGetId(Ob_DM_NhomSize_H ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into DM_NhomSize_H (MaNhomSize, SizeMin, SizeMax, idx, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy) Values(@MaNhomSize, @SizeMin, @SizeMax, @idx, @ModifiedTime, @ModifiedBy, @CreatedTime, @CreatedBy)Select @@IDENTITY"
                };
                if (ob.MANHOMSIZE.Trim() == "")
                {
                    command.Parameters.Add("MaNhomSize", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("MaNhomSize", SqlDbType.VarChar).Value = ob.MANHOMSIZE;
                }
                if (ob.SIZEMIN.Trim() == "")
                {
                    command.Parameters.Add("SizeMin", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("SizeMin", SqlDbType.VarChar).Value = ob.SIZEMIN;
                }
                if (ob.SIZEMAX.Trim() == "")
                {
                    command.Parameters.Add("SizeMax", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("SizeMax", SqlDbType.VarChar).Value = ob.SIZEMAX;
                }
                command.Parameters.Add("idx", SqlDbType.Int).Value = ob.IDX;
                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);
        }
        //GetObWhere
        public Ob_DM_NhomSize_H _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_DM_NhomSize_H ob      = new Ob_DM_NhomSize_H();
            SqlCommand       command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_NhomSize, MaNhomSize, SizeMin, SizeMax, idx, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy From DM_NhomSize_H Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_NHOMSIZE = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MANHOMSIZE = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.SIZEMIN = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.SIZEMAX = Convert.ToString(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.IDX = Convert.ToInt32(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[7]);
                }
                if (reader[8] != DBNull.Value)
                {
                    ob.CREATEDBY = 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);
        }