private void btnSave_Click(object sender, EventArgs e) { try { string Name = txtCatName.Text; string Description = txtCatDescription.Text; byte[] imagebt = null; int CategoryId = SelectedCategoryId; Image image = pictureBox1.Image; if (image != null) { using (MemoryStream memoryStream = new MemoryStream()) { image.Save(memoryStream, ImageFormat.Jpeg); imagebt = memoryStream.ToArray(); } } _objCat.UpdateCategory(Name, Description, imagebt, GlobalVariables.glbUserId, SelectedCategoryId); } catch (Exception) { throw; } MessageBox.Show("Updated", "Status", MessageBoxButtons.OK); UpdateCategory currentFrm = new UpdateCategory(); this.Hide(); }
//private void setGridStyle() //{ // try // { // DataGridViewColumn column = dataGridView1.Columns[0]; // column.Width = 80; // DataGridViewColumn column1 = dataGridView1.Columns[1]; // column1.Width = 290; // DataGridViewColumn column2 = dataGridView1.Columns[2]; // column2.Width = 400; // DataGridViewColumn column3 = dataGridView1.Columns[3]; // column3.Width = 150; // DataGridViewColumn column4 = dataGridView1.Columns[4]; // column4.Width = 125; // dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Orange; // dataGridView1.Columns[0].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; // dataGridView1.Columns[1].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; // dataGridView1.Columns[2].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; // dataGridView1.Columns[3].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; // dataGridView1.Columns[4].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; // dataGridView1.Columns[0].HeaderCell.Style.Font = new Font("Palatino Linotype", 10); // dataGridView1.Columns[1].HeaderCell.Style.Font = new Font("Palatino Linotype", 10); // dataGridView1.Columns[2].HeaderCell.Style.Font = new Font("Palatino Linotype", 10); // dataGridView1.Columns[3].HeaderCell.Style.Font = new Font("Palatino Linotype", 10); // dataGridView1.Columns[4].HeaderCell.Style.Font = new Font("Palatino Linotype", 10); // this.dataGridView1.Rows.Add(1, 2, 3, 4, 5); // } // catch (Exception ex) // { // _errorLogs.LogErrors("Category", "setGridStyle", ex.Message); // } //} //EDIT CLICK private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { SelectedCategoryId = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()); //MessageBox.Show(SelectedCategoryId + "Id clicked"); try { if (e.ColumnIndex == 0) { //edit the item try { using (UpdateCategory updateCategory = new UpdateCategory()) { updateCategory.MdiParent = this.MdiParent; updateCategory.ShowDialog(); //MessageBox.Show("The Category is Updated successfully", "Alert", MessageBoxButtons.OK); //updateCategory.Hide(); } } catch (Exception) { throw; } } //colindex = 1 else if (e.ColumnIndex == 1) { DialogResult dialouge = MessageBox.Show("Are You Sure you want to DELETE !", "ALERT", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (dialouge == DialogResult.Yes) { //Delete the item this returns us the ststus if the item is deleted or no IF the status returned is 0 that means the category is deleted else there are other products that belong to the category int deletedStatus = _objCat.DeleteCategoryById(SelectedCategoryId, GlobalVariables.glbUserId); if (deletedStatus > 0) { MessageBox.Show("The Category os not deleted Please check there are some other Products that belong to the category", "Alert", MessageBoxButtons.OK); } else if (deletedStatus == 0) { MessageBox.Show("The Category is deleted successfully", "Alert", MessageBoxButtons.OK); } } else if (dialouge == DialogResult.No) { } } } catch (Exception) { throw; } loadData(); }