Exemplo n.º 1
0
        public override void OnEdit()
        {
            base.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 (DlgProduct dlg = new DlgProduct())
                {
                    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 product!", ex);
            }
        }
Exemplo n.º 2
0
        public override void OnAdd()
        {
            try
            {
                using (DlgProduct dlg = new DlgProduct())
                {
                    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("prod_id"))
                    {
                        prevSelID = Convert.ToInt32(newRow["prod_id"]);
                        RestorePrevSelection();
                    }
                }
            }
            catch (Exception ex)
            {
                GM.ShowErrorMessageBox(this, "Error occured when adding product to database!", ex);
            }
        }