Пример #1
0
        public override void OnEdit()
        {
            try
            {
                DataGridViewRow curRow = dgView.CurrentRow;
                if (curRow == null)
                {
                    GM.ShowErrorMessageBox(this, "No row selected!");
                    return;
                }

                DataRowView rView = curRow.DataBoundItem as DataRowView;
                if (rView == null || rView.Row == null)
                {
                    return;
                }

                using (DlgUser dlg = new DlgUser())
                {
                    dlg.Data.Load(rView.Row);
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    dlg.Data.Save(rView.Row); // saving to database is envoked automatically, see. BaseView.tbl_RowChanged
                }
            }
            catch (Exception ex)
            {
                GM.ShowErrorMessageBox(this, "Error occured when editing user!", ex);
            }
        }
Пример #2
0
        public override void OnAdd()
        {
            try
            {
                using (DlgUser dlg = new DlgUser())
                {
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    DataTable tbl = bindDataSrc.DataSource as DataTable;
                    if (tbl == null)
                    {
                        return;
                    }

                    DataRow newRow = tbl.NewRow();
                    dlg.Data.Save(newRow);
                    tbl.Rows.Add(newRow);   // saving to database is envoked automatically, see. BaseView.tbl_RowChanged
                    if (!newRow.IsNull("user_id"))
                    {
                        prevSelID = Convert.ToInt32(newRow["user_id"]);
                        RestorePrevSelection();
                    }
                }
            }
            catch (Exception ex)
            {
                GM.ShowErrorMessageBox(this, "Error occured when adding user to database!", ex);
            }
        }