Exemple #1
0
        /// <summary>
        /// Hàm thêm mới khách hàng
        /// </summary>
        /// <param name="customer"> Đối tượng khách hàng được thêm mới </param>
        /// <returns> Giá trị trả về là số lượng các dòng bị tác động bởi câu lệnh
        /// thường thì giá trị sẽ là 1 cho câu lệnh Insert
        /// nếu 0 là thêm mới thất bại </returns>
        public int InsertCustomer(dtoCustomer customer)
        {
            int count = 0;

            try
            {
                string       sql           = "INSERT [dbo].[Customer] ([CustomerFullName], [CustomerBirthday], [CustomerAddress], [CustomerPhoneNumber], [CustomerEmail], [Gender]) VALUES (@Name, @BirthDay, @Address, @PhoneNumber, @Email, @Gender)";
                SqlParameter parameterName = new SqlParameter("@Name", SqlDbType.NVarChar);
                parameterName.Value = customer.FullName;
                SqlParameter parameterBirthDay = new SqlParameter("@BirthDay", SqlDbType.DateTime);
                parameterBirthDay.Value = customer.BirthDay;
                SqlParameter parameterAddress = new SqlParameter("@Address", SqlDbType.NVarChar);
                parameterAddress.Value = customer.Address;
                SqlParameter parameterPhoneNumber = new SqlParameter("@PhoneNumber", SqlDbType.Char);
                parameterPhoneNumber.Value = customer.PhoneNumber;
                SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar);
                parameterEmail.Value = customer.Email;
                SqlParameter parameterGender = new SqlParameter("@Gender", SqlDbType.NVarChar);
                parameterGender.Value = customer.Gender;
                count = InsertUpdateDeleteData(sql, new[] { parameterName, parameterBirthDay, parameterAddress, parameterPhoneNumber, parameterEmail, parameterGender });
            }
            finally
            {
                CloseConnection();
            }
            return(count);
        }
Exemple #2
0
        /// <summary>
        /// Hàm cập nhập khách hàng theo mã khách hàng
        /// </summary>
        /// <param name="customer"> đối tượng khách hàng được cập nhập </param>
        /// <returns> Giá trị trả về là số lượng các dòng bị tác động bởi câu lệnh
        /// vì mã khách hàng là khóa chính, nên số lượng các dòng bị tác động thường sẽ là 1
        /// nếu 0 là cập nhập thất bại </returns>
        public int UpdateCustomerFromID(dtoCustomer customer)
        {
            int count = 0;

            try
            {
                string       sql           = "UPDATE [dbo].[Customer] SET [CustomerFullName] = @Name, [CustomerBirthDay] = @BirthDay, [CustomerAddress] = @Address, [CustomerPhoneNumber] = @PhoneNumber, [CustomerEmail] = @Email WHERE [CustomerID] = @CustomerID";
                SqlParameter parameterName = new SqlParameter("@Name", SqlDbType.NVarChar);
                parameterName.Value = customer.FullName;
                SqlParameter parameterBirthDay = new SqlParameter("@BirthDay", SqlDbType.DateTime);
                parameterBirthDay.Value = customer.BirthDay;
                SqlParameter parameterAddress = new SqlParameter("@Address", SqlDbType.NVarChar);
                parameterAddress.Value = customer.Address;
                SqlParameter parameterPhoneNumber = new SqlParameter("@PhoneNumber", SqlDbType.NVarChar);
                parameterPhoneNumber.Value = customer.PhoneNumber;
                SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar);
                parameterEmail.Value = customer.Email;
                SqlParameter parameterID = new SqlParameter("@CustomerID", SqlDbType.Int);
                parameterID.Value = customer.CustomerID;
                count             = InsertUpdateDeleteData(sql, new[] { parameterName, parameterBirthDay, parameterAddress, parameterPhoneNumber, parameterEmail, parameterID });
            }
            finally
            {
                CloseConnection();
            }
            return(count);
        }
Exemple #3
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtFullName.Text == "" || txtAddress.Text == "" || txtBirthDay.Text == "" || txtEmail.Text == "" || txtGender.Text == "" || txtPhoneNumber.Text == "")
         {
             throw new Exception("Vui lòng nhập đầy đủ thông tin!");
         }
         else
         {
             dtoCustomer dtoCustomer = new dtoCustomer();
             dtoCustomer.FullName    = txtFullName.Text;
             dtoCustomer.Address     = txtAddress.Text;
             dtoCustomer.BirthDay    = Convert.ToDateTime(txtBirthDay.Text);
             dtoCustomer.Email       = txtEmail.Text;
             dtoCustomer.Gender      = txtGender.Text;
             dtoCustomer.PhoneNumber = txtPhoneNumber.Text;
             int count = balCustomer.Insert(dtoCustomer);
             txtFullName.Text    = "";
             txtAddress.Text     = "";
             txtBirthDay.Text    = "";
             txtEmail.Text       = "";
             txtGender.Text      = "";
             txtPhoneNumber.Text = "";
             BindingData();
             string mess = "Thông tin khách hàng đã được thêm thành công!" + "\nSố hàng đã được thêm: " + count.ToString();
             XtraMessageBox.Show(mess, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        public int Insert(dtoCustomer dtoCustomer)
        {
            dalCustomer dalCustomer = new dalCustomer();
            int         count       = dalCustomer.InsertCustomer(dtoCustomer);

            return(count);
        }
        public int Update(dtoCustomer dtoCustomer)
        {
            dalCustomer Customer = new dalCustomer();
            int         count    = Customer.UpdateCustomerFromID(dtoCustomer);

            return(count);
        }
Exemple #6
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         dtoCustomer dtoCustomer = new dtoCustomer();
         dtoCustomer = dgvViewCustomer.GetFocusedRow() as dtoCustomer;
         if (dtoCustomer.FullName == "" || dtoCustomer.Gender == "" || dtoCustomer.BirthDay.ToString() == "" || dtoCustomer.PhoneNumber == "" || dtoCustomer.Address == "" || dtoCustomer.Email == "")
         {
             throw new Exception("Vui lòng không để trống thông tin!");
         }
         else
         {
             int count = balCustomer.Update(dtoCustomer);
             XtraMessageBox.Show("Cập nhập thông tin khách hàng thành công! \nSố hàng đã được cập nhập: " + count.ToString(), "Succesful", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public List <dtoCustomer> GetCustomers()
        {
            dalCustomer        dalCustomer = new dalCustomer();
            List <dtoCustomer> listEmp     = new List <dtoCustomer>();
            DataTable          Customers   = dalCustomer.GetCustomers();

            for (int i = 0; i < Customers.Rows.Count; i++)
            {
                dtoCustomer Customer = new dtoCustomer();
                DataRow     row      = Customers.Rows[i];
                Customer.CustomerID  = Convert.ToInt32(row[0]);
                Customer.FullName    = row[1].ToString();
                Customer.Gender      = row[2].ToString();
                Customer.PhoneNumber = row[3].ToString();
                Customer.Email       = row[4].ToString();
                Customer.BirthDay    = Convert.ToDateTime(row[5]);
                Customer.Address     = row[6].ToString();
                listEmp.Add(Customer);
            }
            return(listEmp);
        }