private void parmExecute(EHow how) { if (allowUpdates == false && how != EHow.DISPLAY) return; string where = "", c = "", query = ""; int row = -1; int field; DataTable data = null; int offset = pcTable.offsetFields; if (tablesDataGrid.CurrentRow != null) { where = "WHERE "; row = tablesDataGrid.CurrentRow.Index; data = tablesDataGrid.DataSource as DataTable; for (int k = 0; k < pcTable.noKeyFields; k++) { int okfield = k + pcTable.offsetKeyFields; field = pcKeyFields[okfield].index; string value = data.Rows[row][field].ToString(); TPCField pcField = pcFields[offset + field]; string ready = sqlReady(pcField, value); where += c + pcFields[offset + field].name + " = " + ready; c = " AND "; } } string oldUsId = ""; string oldTmStamp = ""; string newUsId = ""; string newTmStamp = ""; if (row != -1) { int no = pcTable.noFields; oldUsId = data.Rows[row][no].ToString(); oldTmStamp = DateTime.Parse(data.Rows[row][no + 1].ToString()).ToString("yyyyMMddhhmmss"); } List<EntryItem> edits = new List<EntryItem>(pcTable.noFields); ScaffoldForm form = scaffoldForm = new ScaffoldForm(this, how, edits); int comboWidth = form.ClientSize.Width - 132; int editWidth = comboWidth - 18; // The next 3 lines are indicative of why properties are at best second class. Size size = form.MinimumSize; size.Height = pcTable.noFields * 24 + 66; form.MinimumSize = size; Dictionary<int, ComboBox> combos = new Dictionary<int, ComboBox>(); for (field = 0; field < pcTable.noFields; field++) { EntryItem edit = new EntryItem(); edits.Add(edit); TPCField pcField = pcFields[field + offset]; edit.ofType = pcField.type; edit.isNull = pcField.isNull == 1; if (how != EHow.ADD && (how == EHow.DELETE || how == EHow.DISPLAY || isKey(pcTable, field)) || (how == EHow.ADD && pcField.type == DBHandler.PC_SEQUENCE)) edit.isReadOnly = true; if (pcField.uppercase == 1 || isKey(pcTable, field) == true) edit.uppercase = true; Label label = edit.label = new Label(); label.Text = pcField.name; label.Top = field * 24 + 4; label.Left = 4; form.CapturePanel.Controls.Add(label); if (showSetup.Checked == true) LogDebug = label.Text + " " + label.Top + " " + label.Left; string setupWork = pcField.name; string value = ""; if (how == EHow.ADD || (how == EHow.CHANGE && isKey(pcTable, field) == false)) { value = row != -1 ? data.Rows[row][field].ToString() : ""; if (clearAdd.Checked == true && how == EHow.ADD) value = ""; int link; int pair; if (setupLink(pcTable, field, out link, out pair)) { setupWork += " Is Link Field"; if (sizeIsOk(link) == true) { setupWork += " and is not too large"; if (pair == 0) { newDropDown(edit, pcTable.index, link, field * 24 + 4, 124, comboWidth, value); combos.Add(link, edit.combo); edit.pair = pair; form.CapturePanel.Controls.Add(edit.combo); if (showSetup.Checked == true) LogDebug = setupWork; } else { setupWork += " is extra link pair field"; edit.isReadOnly = true; edit.combo = combos[link]; edit.pair = pair; edit.combo.SelectedIndexChanged += new EventHandler(editComboSelectedIndexChanged); edit.Text(field * 24 + 4, 124, editWidth, maxLength(pcField), value); List<EntryItem> list = (List<EntryItem>)edit.combo.Tag; list.Add(edit); form.CapturePanel.Controls.Add(edit.text); } continue; } } else if (pcField.noEnums > 0) { setupWork += " Is Enum Field"; enumDropDown(edit, field + offset, field * 24 + 4, 124, comboWidth, value); form.CapturePanel.Controls.Add(edit.combo); if (showSetup.Checked == true) LogDebug = setupWork; continue; } } value = row != -1 ? data.Rows[row][field].ToString() : ""; if (clearAdd.Checked == true && how == EHow.ADD) value = ""; switch (pcField.type) { case DBHandler.PC_CHAR: case DBHandler.PC_USERSTAMP: { setupWork += " Is Text Field"; edit.Text(field * 24 + 4, 124, editWidth, maxLength(pcField), value); form.CapturePanel.Controls.Add(edit.text); } break; case DBHandler.PC_DATE: { setupWork += " Is Date Field"; edit.Date(field * 24 + 4, 124, comboWidth, value); form.CapturePanel.Controls.Add(edit.date); } break; case DBHandler.PC_DATETIME: case DBHandler.PC_TIMESTAMP: { setupWork += " Is Date Time Field"; edit.Date(field * 24 + 4, 124, comboWidth * 8 / 14, value); form.CapturePanel.Controls.Add(edit.date); edit.Time(field * 24 + 4, 124 + edit.date.Width + 4, comboWidth * 6 / 14 - 4, value); form.CapturePanel.Controls.Add(edit.time); } break; case DBHandler.PC_TIME: { setupWork += " Is Time Field"; edit.Time(field * 24 + 4, 124, comboWidth, value); form.CapturePanel.Controls.Add(edit.time); } break; case DBHandler.PC_BOOLEAN: { setupWork += " Is Boolean"; edit.Combo(field * 24 + 4, 124, comboWidth, value); form.CapturePanel.Controls.Add(edit.combo); } break; case DBHandler.PC_BYTE: { setupWork += " Is Byte"; edit.Text(field * 24 + 4, 124, editWidth, maxLength(pcField), value); form.CapturePanel.Controls.Add(edit.text); } break; case DBHandler.PC_SHORT: { setupWork += " Is Short"; edit.Text(field * 24 + 4, 124, editWidth, maxLength(pcField), value); form.CapturePanel.Controls.Add(edit.text); } break; case DBHandler.PC_DOUBLE: { edit.Text(field * 24 + 4, 124, editWidth, maxLength(pcField), value); form.CapturePanel.Controls.Add(edit.text); } break; case DBHandler.PC_SEQUENCE: case DBHandler.PC_INT: { edit.Text(field * 24 + 4, 124, editWidth, maxLength(pcField), value); form.CapturePanel.Controls.Add(edit.text); } break; case DBHandler.PC_LONG: { edit.Text(field * 24 + 4, 124, editWidth, maxLength(pcField), value); form.CapturePanel.Controls.Add(edit.text); } break; } if (showSetup.Checked == true) LogDebug = setupWork; } switch (how) { case EHow.ADD: form.Text = "Add Record for " + pcTable.name; form.isAdd = true; form.isChange = false; form.isDelete = false; form.isDisplay = false; break; case EHow.CHANGE: form.Text = "Change Record on " + pcTable.name; form.isAdd = false; form.isChange = true; form.isDelete = false; form.isDisplay = false; break; case EHow.DELETE: form.Text = "Delete Record in " + pcTable.name; form.isAdd = false; form.isChange = false; form.isDelete = true; form.isDisplay = false; break; case EHow.DISPLAY: form.Text = "Display Record of " + pcTable.name; form.isAdd = false; form.isChange = false; form.isDelete = false; form.isDisplay = true; break; } DialogResult rc = form.ShowDialog(); if (rc != DialogResult.OK || how == EHow.DISPLAY) return; List<string> cells = new List<string>(pcTable.noFields); for (field = 0; field < pcTable.noFields; field++) cells.Add(edits[field].Value); connect.BeginTransaction(); try { DBHandler db = new DBHandler(connect); string sysdate = DateTime.Now.ToString("yyyyMMddhhmmss"); switch (how) { case EHow.ADD: newUsId = userName; newTmStamp = sysdate; query = "INSERT INTO " + pcTable.name; query += " VALUES "; c = "( "; for (field = 0; field < pcTable.noFields; field++) { query += c + sqlReady(pcFields[offset + field], cells[field], true, pcTable.name); c = ", "; } query += ", '" + userName + "', Sysdate)"; break; case EHow.CHANGE: newUsId = userName; newTmStamp = sysdate; query = "UPDATE " + pcTable.name; query += " SET "; c = ""; for (field = 0; field < pcTable.noFields; field++) { if (isKey(pcTable, field) == true) continue; query += c + pcFields[offset + field].name + " = " + sqlReady(pcFields[offset + field], cells[field]); c = ", "; } query += ", " + db.UsId + " = '" + userName + "', " + db.TmStamp + " = Sysdate"; query += " " + where; break; case EHow.DELETE: query = "DELETE FROM " + pcTable.name; query += " " + where; break; } using (AutoCursor.DatabaseCall) { try { if (showSQL.Checked == true) LogDebug = query; db.Execute(query); if (BinTables.HasValidation() == true) { if (validateAuditPython(pcTable, how, edits, oldUsId, newUsId, oldTmStamp, newTmStamp) == false) { connect.FlagRollback(); return; } showTableGrid(); } } catch (Exception ex) { connect.FlagRollback(); showException(ex); } } } finally { connect.EndTransaction(); } }
private void enumDropDown(EntryItem edit, int field, int top, int left, int width, string text) { edit.Combo(top, left, width, text); for (int i = 0, offset = pcFields[field].offsetEnums; i < pcFields[field].noEnums; i++) { string[] values = new string[1]; string result = ""; if (edit.ofType == DBHandler.PC_CHAR) values[0] = pcEnums[i + offset].name; else { values[0] = pcEnums[i + offset].value.ToString(); result = values[0] + "="; } string[] descr = new string[1]; descr[0] = result+pcEnums[i + offset].name; edit.combo.Items.Add(new ListItem(values, descr, i)); } int no = getIndex(edit.combo, text); edit.combo.SelectedIndex = no; }
private void newDropDown(EntryItem edit, int fromTable, int link, int Top, int Left, int Width, string text) { using (AutoCursor.DatabaseCall) { try { edit.Combo(Top, Left, Width, text); DBHandler db = new DBHandler(connect); int tno = pcLinks[link].tableNo; TPCTable pcTable = pcTables[tno]; int noFields = pcTable.noFields; int offsetFields = pcTable.offsetFields; int noShowFields = pcTable.noShowFields; int offsetShowFields = pcTable.offsetShowFields; int noOrderFields = pcTable.noOrderFields; int noLinkPairs = pcLinks[link].noLinkPairs; int offsetOrderFields = pcTable.offsetOrderFields; if (noShowFields > 0) db.GetTable(pcTable.name, pcFields, offsetFields, noFields, pcShowFields, offsetShowFields, noShowFields); else db.GetTable(pcTable.name, pcFields, offsetFields, noFields, pcOrderFields, offsetOrderFields, noOrderFields); DataTable table = db.GetDataTable(); System.Data.DataRowCollection rows = table.Rows; for (int row = 0; row < rows.Count; row++) { string[] values = new string[noLinkPairs]; string[] descr = new string[noShowFields == 0 ? noLinkPairs : noShowFields]; for (int field = 0; field < noFields; field++) { int offset = pcLinks[link].offsetLinkPairs; int offset2 = pcTable.offsetShowFields; for (int pair = 0; pair < noLinkPairs; pair++) { if (field == pcLinkPairs[pair + offset].toNo) { values[pair] = rows[row][field].ToString(); if (noShowFields == 0) descr[pair] = values[pair]; } } for (int show = 0; show < noShowFields; show++) { if (field == pcShowFields[offset2 + show].index) descr[show] = rows[row][field].ToString(); } } edit.combo.Items.Add(new ListItem(values, descr, row)); } int no = getIndex(edit.combo, text); edit.combo.SelectedIndex = no; } catch (Exception ex) { showException(ex); } } }
public void OkButtonClick(object sender, EventArgs e) { DialogResult = System.Windows.Forms.DialogResult.None; Label label; foreach (Control control in capturePanel.Controls) { EntryItem edit = control.Tag as EntryItem; if (edit != null) { if (edit.Value.Length == 0 && edit.isNull == true) { continue; } if (edit.combo == null) { switch (edit.ofType) { case DBHandler.PC_BOOLEAN: if (inValidBoolean(edit.label.Text, edit.text) == true) { return; } break; case DBHandler.PC_BYTE: if (inValidInteger(edit.label.Text, edit.text, 3) == true) { return; } break; case DBHandler.PC_CHAR: if (inValidChar(edit.label.Text, edit.text) == true) { return; } break; case DBHandler.PC_DATE: if (inValidDate(edit.label.Text, edit.date) == true) { return; } break; case DBHandler.PC_DATETIME: if (inValidDateTime(edit.label.Text, edit.date, edit.time) == true) { return; } break; case DBHandler.PC_DOUBLE: if (inValidDouble(edit.label.Text, edit.text) == true) { return; } break; case DBHandler.PC_INT: if (inValidInteger(edit.label.Text, edit.text, 10) == true) { return; } break; case DBHandler.PC_LONG: if (inValidInteger(edit.label.Text, edit.text, 18) == true) { return; } break; case DBHandler.PC_SEQUENCE: if (inValidInteger(edit.label.Text, edit.text, 10) == true) { return; } break; case DBHandler.PC_SHORT: if (inValidInteger(edit.label.Text, edit.text, 5) == true) { return; } break; case DBHandler.PC_TIME: if (inValidTime(edit.label.Text, edit.time) == true) { return; } break; } } continue; } Label l = control as Label; if (l != null) { label = l; } } if (pcForm.validateTablePython(how, edits) == true) { DialogResult = System.Windows.Forms.DialogResult.OK; } }