public void add(object T) { Item item = (Item)T; int uomID = uomRepository.getID(item.unitOfMeasure); int statusID = statusRepository.getID(item.status); sqlcmd = new SqlCommand("INSERT INTO Item (Name, ShortName, Alias, Description, Quantity, UOMID, Price, Extension, StatusID, Active) VALUES (@Name, @ShortName, @Alias, @Description, @Quantity, @UOMID, @StatusID, @Active)", Misc.getConn()); sqlcmd.Parameters.AddWithValue("@Name", item.name); sqlcmd.Parameters.AddWithValue("@ShortName", item.shortName); sqlcmd.Parameters.AddWithValue("@Alias", item.alias); sqlcmd.Parameters.AddWithValue("@Description", item.description); sqlcmd.Parameters.AddWithValue("@Quantity", item.quantity); sqlcmd.Parameters.AddWithValue("@UOMID", uomID); sqlcmd.Parameters.AddWithValue("@StatusID", statusID); sqlcmd.Parameters.AddWithValue("@Active", item.active); Misc.connOpen(); sqlcmd.ExecuteNonQuery(); sqlcmd.Dispose(); }
private void controlNavigator1_ButtonClick(object sender, NavigatorButtonClickEventArgs e) { // try { if (e.Button.Tag.ToString() == "Add") { toolStripStatusLabel1.Text = "Adding..."; if (tableLayoutPanel1.RowStyles[2].Height == 1) { tableLayoutPanel1.RowStyles[2].Height = 148; } actionState = "a"; setControlState(true); emptyControls(); txtStatus.Focus(); BtnAdd.Enabled = false; BtnEdit.Enabled = false; BtnSave.Enabled = true; BtnCancel.Enabled = true; BtnSwitch.Enabled = false; BtnRefresh.Enabled = false; controlNavigator1.Buttons.First.Enabled = false; controlNavigator1.Buttons.Next.Enabled = false; controlNavigator1.Buttons.Prev.Enabled = false; controlNavigator1.Buttons.Last.Enabled = false; searchControl1.Enabled = false; gridControl1.Enabled = false; } else if (e.Button.Tag.ToString() == "Edit") { statusID = repository.getID(txtStatus.Text); if (tableLayoutPanel1.RowStyles[2].Height == 1) { tableLayoutPanel1.RowStyles[2].Height = 148; } actionState = "e"; setControlState(true); txtStatus.Focus(); BtnAdd.Enabled = false; BtnEdit.Enabled = false; BtnSave.Enabled = true; BtnCancel.Enabled = true; BtnSwitch.Enabled = false; BtnRefresh.Enabled = false; controlNavigator1.Buttons.First.Enabled = false; controlNavigator1.Buttons.Next.Enabled = false; controlNavigator1.Buttons.Prev.Enabled = false; controlNavigator1.Buttons.Last.Enabled = false; searchControl1.Enabled = false; gridControl1.Enabled = false; } else if (e.Button.Tag.ToString() == "Save") { if (actionState == "e") { toolStripStatusLabel1.Text = "Editing..."; Status status = new Status { name = txtStatus.Text, shortName = txtShortName.Text, description = txtDescription.Text, active = cbActive.Checked }; repository.update(statusID, status); } else if (actionState == "a") { toolStripStatusLabel1.Text = "Saving..."; if (!verifyInput()) { return; } Status status = new Status { name = txtStatus.Text, shortName = txtShortName.Text, description = txtDescription.Text, active = cbActive.Checked }; repository.add(status); } actionState = "a"; gridControl1.DataSource = repository.loadData(); setControlState(false); BtnSave.Enabled = false; BtnEdit.Enabled = true; BtnAdd.Enabled = true; BtnCancel.Enabled = false; BtnSwitch.Enabled = true; BtnRefresh.Enabled = true; controlNavigator1.Buttons.First.Enabled = true; controlNavigator1.Buttons.Next.Enabled = true; controlNavigator1.Buttons.Prev.Enabled = true; controlNavigator1.Buttons.Last.Enabled = true; searchControl1.Enabled = true; gridControl1.Enabled = true; toolStripStatusLabel1.Text = "Saved"; } else if (e.Button.Tag.ToString() == "Cancel") { setControlState(false); actionState = "a"; BtnAdd.Enabled = true; BtnEdit.Enabled = true; BtnSave.Enabled = false; BtnCancel.Enabled = false; BtnSwitch.Enabled = true; BtnRefresh.Enabled = true; controlNavigator1.Buttons.First.Enabled = true; controlNavigator1.Buttons.Next.Enabled = true; controlNavigator1.Buttons.Prev.Enabled = true; controlNavigator1.Buttons.Last.Enabled = true; searchControl1.Enabled = true; gridControl1.Enabled = true; toolStripStatusLabel1.Text = "Done"; } else if (e.Button.Tag.ToString() == "Refresh") { toolStripStatusLabel1.Text = "Refreshing..."; gridControl1.DataSource = repository.loadData(); toolStripStatusLabel1.Text = "Done"; } else if (e.Button.Tag.ToString() == "Switch") { if (tableLayoutPanel1.RowStyles[2].Height == 148) { tableLayoutPanel1.RowStyles[2].Height = 1; } else { tableLayoutPanel1.RowStyles[2].Height = 148; } } //} catch { //} }