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

            while (reader.Read())
            {
                Ob_DA_ChietKhau_Footer ob = new Ob_DA_ChietKhau_Footer();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.PLANCODE = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.INVNO = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.ID_CHIETKHAU = Convert.ToInt32(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.VALUETOTAL = Convert.ToDecimal(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.NOTE = Convert.ToString(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CDATE = Convert.ToDateTime(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.UDATE = Convert.ToDateTime(reader[7]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Exemple #2
0
        //DeleteOB
        public bool _DeleteOb(Ob_DA_ChietKhau_Footer ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From DA_ChietKhau_Footer Where ID=@ID"
            };

            command.Parameters.Add(new SqlParameter("ID", ob.ID));
            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);
        }
Exemple #3
0
        //ListWhere
        public List <Ob_DA_ChietKhau_Footer> _ListWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DA_ChietKhau_Footer> list = new List <Ob_DA_ChietKhau_Footer>();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID, PlanCode, InvNO, ID_ChietKhau, ValueTotal, Note, cDate, uDate From DA_ChietKhau_Footer Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_DA_ChietKhau_Footer ob = new Ob_DA_ChietKhau_Footer();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.PLANCODE = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.INVNO = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.ID_CHIETKHAU = Convert.ToInt32(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.VALUETOTAL = Convert.ToDecimal(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.NOTE = Convert.ToString(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CDATE = Convert.ToDateTime(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.UDATE = Convert.ToDateTime(reader[7]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Exemple #4
0
 public Ob_DA_ChietKhau_Footer(Ob_DA_ChietKhau_Footer newOb)
 {
     id           = newOb.ID;
     plancode     = newOb.PLANCODE;
     invno        = newOb.INVNO;
     id_chietkhau = newOb.ID_CHIETKHAU;
     valuetotal   = newOb.VALUETOTAL;
     note         = newOb.NOTE;
     cdate        = newOb.CDATE;
     udate        = newOb.UDATE;
 }
Exemple #5
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_DA_ChietKhau_Footer ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update DA_ChietKhau_Footer Set PlanCode=@PlanCode, InvNO=@InvNO, ID_ChietKhau=@ID_ChietKhau, ValueTotal=@ValueTotal, Note=@Note, cDate=@cDate, uDate=@uDate Where ID=@ID"
            };

            command.Parameters.Add("ID", SqlDbType.BigInt).Value = ob.ID;
            if (ob.PLANCODE.Trim() == "")
            {
                command.Parameters.Add("PlanCode", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("PlanCode", SqlDbType.NVarChar).Value = ob.PLANCODE;
            }
            if (ob.INVNO.Trim() == "")
            {
                command.Parameters.Add("InvNO", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("InvNO", SqlDbType.NVarChar).Value = ob.INVNO;
            }
            command.Parameters.Add("ID_ChietKhau", SqlDbType.Int).Value   = ob.ID_CHIETKHAU;
            command.Parameters.Add("ValueTotal", SqlDbType.Decimal).Value = ob.VALUETOTAL;
            if (ob.NOTE.Trim() == "")
            {
                command.Parameters.Add("Note", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("Note", SqlDbType.NVarChar).Value = ob.NOTE;
            }
            if (ob.CDATE == DateTime.MinValue)
            {
                command.Parameters.Add("cDate", SqlDbType.DateTime).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("cDate", SqlDbType.DateTime).Value = ob.CDATE;
            }
            if (ob.UDATE == DateTime.MinValue)
            {
                command.Parameters.Add("uDate", SqlDbType.DateTime).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("uDate", SqlDbType.DateTime).Value = ob.UDATE;
            }
            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);
        }
Exemple #6
0
        //InsertobGetId
        public int _InsertObGetId(Ob_DA_ChietKhau_Footer ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into DA_ChietKhau_Footer (PlanCode, InvNO, ID_ChietKhau, ValueTotal, Note, cDate, uDate) Values(@PlanCode, @InvNO, @ID_ChietKhau, @ValueTotal, @Note, @cDate, @uDate)Select @@IDENTITY"
                };
                if (ob.PLANCODE.Trim() == "")
                {
                    command.Parameters.Add("PlanCode", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("PlanCode", SqlDbType.NVarChar).Value = ob.PLANCODE;
                }
                if (ob.INVNO.Trim() == "")
                {
                    command.Parameters.Add("InvNO", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("InvNO", SqlDbType.NVarChar).Value = ob.INVNO;
                }
                command.Parameters.Add("ID_ChietKhau", SqlDbType.Int).Value   = ob.ID_CHIETKHAU;
                command.Parameters.Add("ValueTotal", SqlDbType.Decimal).Value = ob.VALUETOTAL;
                if (ob.NOTE.Trim() == "")
                {
                    command.Parameters.Add("Note", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("Note", SqlDbType.NVarChar).Value = ob.NOTE;
                }
                if (ob.CDATE == DateTime.MinValue)
                {
                    command.Parameters.Add("cDate", SqlDbType.DateTime).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("cDate", SqlDbType.DateTime).Value = ob.CDATE;
                }
                if (ob.UDATE == DateTime.MinValue)
                {
                    command.Parameters.Add("uDate", SqlDbType.DateTime).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("uDate", SqlDbType.DateTime).Value = ob.UDATE;
                }
                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);
        }