示例#1
0
        private void btedit_Click(object sender, EventArgs e)
        {
            if (gvcategories.SelectedRows.Count == 0)
            {
                MessageBox.Show("Tidak ada kategori yang akan diubah");
            }
            else
            {
                var selectedRowId = (int)gvcategories.SelectedRows[0].Cells["id"].Value;
                var cats          = ListCategories.FirstOrDefault(x => x.catid == selectedRowId);

                if (selectedRowId == 1)
                {
                    MessageBox.Show("Anda tidak dibenarkan mengubah kategori Lain-Lain");
                }
                else if (cats != null)
                {
                    var form = new ManageCategories();
                    form.userdata     = userdata;
                    form.Editmode     = true;
                    form.CategoryData = cats;
                    form.ShowDialog();
                    LoadData();

                    foreach (DataGridViewRow row in gvcategories.Rows)
                    {
                        if (((int)row.Cells["id"].Value) == selectedRowId)
                        {
                            gvcategories.Rows[row.Index].Selected = true;
                            break;
                        }
                    }
                }
            }
        }
示例#2
0
        private void btadd_Click(object sender, EventArgs e)
        {
            int oritotalrow = gvcategories.Rows.Count;

            var form = new ManageCategories();

            form.userdata = userdata;
            form.ShowDialog();
            LoadData();

            int newtotalrow = gvcategories.Rows.Count;

            if (oritotalrow != newtotalrow)
            {
                var newCats = new CategoryColumns();
                newCats = categoryRepository.GetByAny(1);
                int newId = newCats.catid;

                foreach (DataGridViewRow row in gvcategories.Rows)
                {
                    if (((int)row.Cells["id"].Value) == newId)
                    {
                        gvcategories.Rows[row.Index].Selected = true;
                        break;
                    }
                }
            }
        }