private void btnadd_Click(object sender, EventArgs e) { if (SetData()) { if (items.GetItems()) { items.ParameterizedEdit(); } else { items.ParameterizedAdd(); period.MaxName = "itemmaxid"; if (Convert.ToInt64(period.GetMaxid()) == Convert.ToInt64(items.itemid)) { long id = Convert.ToInt64(items.itemid); id++; period.Maxid = id; period.UpdateMaxid(); } } Clear(); } }
private void txtitem_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F2) { grdpopup.Focus(); } else if (e.KeyValue == 13) { this.items.itemid = txtitem.Text; this.items.Description = txtitem.Text; if (purchase) { DataTable dt = items.SearchProduct(); if (dt.Rows.Count == 0) { items.itemid = items.GetNextId(); this.items.Add(); if (items.itemid != "") { period.MaxName = "itemmaxid"; if (Convert.ToInt64(period.GetMaxid()) == Convert.ToInt64(items.itemid)) { long id = Convert.ToInt64(items.itemid); id++; period.Maxid = id; period.UpdateMaxid(); } } dt = items.SearchProduct(); grdpopup.DataSource = dt; } // grdpopup.DataSource = dt; } else { DataTable dt = items.SearchItems(); if (dt.Rows.Count == 0) { items.itemid = items.GetNextId(); this.items.Add(); if (items.itemid != "") { period.MaxName = "itemmaxid"; if (Convert.ToInt64(period.GetMaxid()) == Convert.ToInt64(items.itemid)) { long id = Convert.ToInt64(items.itemid); id++; period.Maxid = id; period.UpdateMaxid(); } } dt = items.SearchItems(); grdpopup.DataSource = dt; } } // grdpopup.Focus(); if (grdpopup.Rows.Count != 0) { int rowindex = grdpopup.CurrentCell.RowIndex; itemid = Convert.ToString(grdpopup.Rows[rowindex].Cells[0].Value); desc = Convert.ToString(grdpopup.Rows[rowindex].Cells[1].Value); this.Close(); } } else if (e.KeyCode == Keys.Down) { if (grdpopup.Rows.Count == 0) { return; } int curindex = grdpopup.CurrentCell.RowIndex; if (curindex == grdpopup.Rows.Count - 1) { return; } grdpopup.Rows[curindex].Selected = false; grdpopup.Rows[curindex + 1].Selected = true; grdpopup.CurrentCell = grdpopup.Rows[curindex + 1].Cells[1]; e.Handled = true; } else if (e.KeyCode == Keys.Up) { if (grdpopup.Rows.Count == 0) { return; } int upindex = grdpopup.CurrentCell.RowIndex; if (upindex == 0) { return; } grdpopup.Rows[upindex].Selected = false; grdpopup.CurrentCell = grdpopup.Rows[upindex - 1].Cells[1]; grdpopup.Rows[upindex - 1].Selected = true; e.Handled = true; } }