Esempio n. 1
0
        private void dgvCategory_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow selectedRow = dgvCategory.Rows[e.RowIndex];
            int             id          = int.Parse(selectedRow.Cells["ID"].Value.ToString());
            string          description = selectedRow.Cells["Description"].Value.ToString();

            cateDTO = new Car_CategoryDTO
            {
                ID          = id,
                Description = description
            };
        }
Esempio n. 2
0
        public void Update(Car_CategoryDTO cateDTO)
        {
            string        SQL = "UPDATE Car_Categories SET Description = @Description WHERE ID = @ID";
            SqlConnection cnn = DBUtils.GetConnection();
            SqlCommand    cmd = new SqlCommand(SQL, cnn);

            cmd.Parameters.AddWithValue("@Description", cateDTO.Description);
            cmd.Parameters.AddWithValue("@ID", cateDTO.ID);
            try
            {
                cnn.Open();
                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cnn.Close();
            }
        }
Esempio n. 3
0
        public List <Car_CategoryDTO> GetListCategory()
        {
            List <Car_CategoryDTO> list = null;
            string        SQL           = "SELECT ID, Description FROM Car_Categories";
            SqlConnection cnn           = DBUtils.GetConnection();
            SqlCommand    cmd           = new SqlCommand(SQL, cnn);

            try
            {
                if (cnn.State == ConnectionState.Closed)
                {
                    cnn.Open();
                    SqlDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    if (rd.HasRows)
                    {
                        while (rd.Read())
                        {
                            if (list == null)
                            {
                                list = new List <Car_CategoryDTO>();
                            }
                            Car_CategoryDTO cateDTO = new Car_CategoryDTO
                            {
                                ID          = rd.GetInt32(0),
                                Description = rd.GetString(1)
                            };

                            list.Add(cateDTO);
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            return(list);
        }
Esempio n. 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtDescription.Text))
            {
                MessageBox.Show("Description can't be blank.");
                return;
            }
            if (txtDescription.Text.Length > 100)
            {
                MessageBox.Show("Description must be <= 100 chars.");
                return;
            }
            Car_CategoryDTO updateDTO = new Car_CategoryDTO
            {
                ID          = this.cateDTO.ID,
                Description = txtDescription.Text
            };

            cateDAO.Update(updateDTO);
            MessageBox.Show("Update category successfully.");
            this.DialogResult = DialogResult.OK;
            this.Dispose();
        }
Esempio n. 5
0
 public frmEditCategory(Car_CategoryDTO dto)
 {
     this.cateDTO = dto;
     InitializeComponent();
 }