Ejemplo n.º 1
0
 public Ob_DM_Mau(Ob_DM_Mau newOb)
 {
     id_mau       = newOb.ID_MAU;
     mamau        = newOb.MAMAU;
     mamauen      = newOb.MAMAUEN;
     tenmau       = newOb.TENMAU;
     tentienganh  = newOb.TENTIENGANH;
     modifiedtime = newOb.MODIFIEDTIME;
     modifiedby   = newOb.MODIFIEDBY;
     createdtime  = newOb.CREATEDTIME;
     createdby    = newOb.CREATEDBY;
 }
Ejemplo n.º 2
0
        //ListAll
        public List <Ob_DM_Mau> _ListAll_sp(string StoredName, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DM_Mau> list    = new List <Ob_DM_Mau>();
            SqlCommand       command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_DM_Mau ob = new Ob_DM_Mau();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_MAU = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MAMAU = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.MAMAUEN = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.TENMAU = Convert.ToString(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.TENTIENGANH = Convert.ToString(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);
        }
Ejemplo n.º 3
0
        //InsertobGetId
        public int _InsertObGetId(Ob_DM_Mau ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into DM_Mau (MaMau, MaMauEN, TenMau, TenTiengAnh, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy) Values(@MaMau, @MaMauEN, @TenMau, @TenTiengAnh, @ModifiedTime, @ModifiedBy, @CreatedTime, @CreatedBy)Select @@IDENTITY"
                };
                if (ob.MAMAU.Trim() == "")
                {
                    command.Parameters.Add("MaMau", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("MaMau", SqlDbType.VarChar).Value = ob.MAMAU;
                }
                if (ob.MAMAUEN.Trim() == "")
                {
                    command.Parameters.Add("MaMauEN", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("MaMauEN", SqlDbType.VarChar).Value = ob.MAMAUEN;
                }
                if (ob.TENMAU.Trim() == "")
                {
                    command.Parameters.Add("TenMau", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("TenMau", SqlDbType.NVarChar).Value = ob.TENMAU;
                }
                if (ob.TENTIENGANH.Trim() == "")
                {
                    command.Parameters.Add("TenTiengAnh", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("TenTiengAnh", SqlDbType.VarChar).Value = ob.TENTIENGANH;
                }
                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);
        }
Ejemplo n.º 4
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_DM_Mau ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update DM_Mau Set MaMau=@MaMau, MaMauEN=@MaMauEN, TenMau=@TenMau, TenTiengAnh=@TenTiengAnh, ModifiedTime=@ModifiedTime, ModifiedBy=@ModifiedBy, CreatedTime=@CreatedTime, CreatedBy=@CreatedBy Where ID_Mau=@ID_Mau"
            };

            command.Parameters.Add("ID_Mau", SqlDbType.Int).Value = ob.ID_MAU;
            if (ob.MAMAU.Trim() == "")
            {
                command.Parameters.Add("MaMau", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("MaMau", SqlDbType.VarChar).Value = ob.MAMAU;
            }
            if (ob.MAMAUEN.Trim() == "")
            {
                command.Parameters.Add("MaMauEN", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("MaMauEN", SqlDbType.VarChar).Value = ob.MAMAUEN;
            }
            if (ob.TENMAU.Trim() == "")
            {
                command.Parameters.Add("TenMau", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("TenMau", SqlDbType.NVarChar).Value = ob.TENMAU;
            }
            if (ob.TENTIENGANH.Trim() == "")
            {
                command.Parameters.Add("TenTiengAnh", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("TenTiengAnh", SqlDbType.VarChar).Value = ob.TENTIENGANH;
            }
            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);
        }
Ejemplo n.º 5
0
        //GetObWhere
        public Ob_DM_Mau _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_DM_Mau  ob      = new Ob_DM_Mau();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_Mau, MaMau, MaMauEN, TenMau, TenTiengAnh, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy From DM_Mau Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_MAU = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MAMAU = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.MAMAUEN = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.TENMAU = Convert.ToString(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.TENTIENGANH = Convert.ToString(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);
        }