private void AddUniqForm_Load(object sender, EventArgs e) { string[] selectedField = new string[0]; if (SelectedRow != null) { this.textBox1.Text = SelectedRow.Cells["colUniqName"].Value.ToString(); string fields = SelectedRow.Cells["colFields"].Value.ToString(); selectedField = fields.Split(Spec); } foreach (DataGridViewRow row in ParentFields.Rows) { string fieldName = row.Cells["colName"].Value + string.Empty; if (UDTTable.IsDefaultField(fieldName)) { continue; } int index = this.dgFields.Rows.Add(); DataGridViewRow r = this.dgFields.Rows[index]; r.Cells[colFieldName.Name].Value = fieldName; r.Cells[colCheck.Name].Value = selectedField.Contains(fieldName); } }
private void TableEditor_Load(object sender, EventArgs e) { txtName.Text = TableNodeHandler.Table.Name; _tableContent = new XmlHelper(TableNodeHandler.Table.GetContent()); dgFields.Rows.Clear(); foreach (XmlElement field in _tableContent.GetElements("Field")) { int index = dgFields.Rows.Add(); DataGridViewRow row = dgFields.Rows[index]; row.Cells[colName.Name].Value = field.GetAttribute("Name"); row.Cells[colDataType.Name].Value = field.GetAttribute("DataType"); row.Cells[colIndexed.Name].Value = field.GetAttribute("Indexed"); row.Cells[colAllowNull.Name].Value = field.GetAttribute("AllowNull"); row.Cells[colDefault.Name].Value = field.GetAttribute("Default"); row.Tag = field; if (UDTTable.IsDefaultField(field)) { row.ReadOnly = true; } } foreach (XmlElement uniq in _tableContent.GetElements("Unique")) { XmlHelper uniqHelper = new XmlHelper(uniq); string uniqFields = ""; foreach (XmlElement field in uniqHelper.GetElements("FieldName")) { uniqFields += "+" + field.InnerText; } if (!string.IsNullOrWhiteSpace(uniqFields)) { uniqFields = uniqFields.Substring(1); } int index = dgUniq.Rows.Add(uniq.Name); DataGridViewRow row = dgUniq.Rows[index]; row.Cells[colUniqName.Name].Value = uniq.GetAttribute("Name"); row.Cells[colFields.Name].Value = uniqFields; } foreach (XmlElement fk in _tableContent.GetElements("ForeignKey")) { this.AddForeignKey(fk); } this.TableNodeHandler.Table.Renamed += new EventHandler(Table_Renamed); _initialized = true; }
private void dgData_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { DataGridViewRow row = dgData.Rows[e.RowIndex]; if (row.IsNewRow) { return; } bool error = false; foreach (DataGridViewColumn column in dgData.Columns) { DataGridViewCell cell = dgData.Rows[e.RowIndex].Cells[column.Index]; string currentValue = cell.Value + string.Empty; //TODO valid cell value cell.ErrorText = string.Empty; XmlElement colElement = column.Tag as XmlElement; string fieldName = colElement.GetAttribute("Field"); XmlElement xml = _source.GetElement("Field[@Name='" + fieldName + "']"); if (xml == null) { continue; } if (UDTTable.IsDefaultField(fieldName)) { continue; } try { UDTTable.ValidFieldValue(xml, currentValue); } catch (Exception ex) { cell.ErrorText = ex.Message; error = true; } } if (error) { e.Cancel = true; } }
private void dgFields_RowEnter(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = dgFields.Rows[e.RowIndex]; string fieldname = row.Cells[colName.Name].Value + string.Empty; if (string.IsNullOrWhiteSpace(fieldname)) { btnRemoveField.Enabled = false; return; } if (UDTTable.IsDefaultField(fieldname)) { btnRemoveField.Enabled = false; return; } btnRemoveField.Enabled = true; }
private void btnRemoveField_Click(object sender, EventArgs e) { if (dgFields.SelectedRows.Count == 0) { return; } DataGridViewRow row = dgFields.SelectedRows[0]; string fieldName = row.Cells[colName.Name].Value + string.Empty; if (UDTTable.IsDefaultField(fieldName)) { MessageBox.Show("系統預設欄位不可刪除", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } dgFields.Rows.Remove(dgFields.SelectedRows[0]); CheckDataChanged(true); }
private List <DataGridViewCell> GetChangedCells(DataGridViewRow row) { List <DataGridViewCell> cells = new List <DataGridViewCell>(); foreach (DataGridViewCell cell in row.Cells) { string fieldName = this.GetCellFieldName(cell); if (UDTTable.IsDefaultField(fieldName)) { continue; } string oriValue = cell.Tag as string; string curValue = cell.Value + string.Empty; if (oriValue == curValue) { continue; } cells.Add(cell); } return(cells); }
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { dgData.Rows.Clear(); dgData.Columns.Clear(); XmlHelper rsp = e.Result as XmlHelper; string uidColumnName = string.Empty; string lastUpdateColName = string.Empty; foreach (XmlElement col in rsp.GetElements("Metadata/Column")) { string fieldName = col.GetAttribute("Field"); string type = col.GetAttribute("Type"); if (fieldName == "uid" && !string.IsNullOrWhiteSpace(uidColumnName)) { continue; } if (fieldName == "last_update" && !string.IsNullOrWhiteSpace(lastUpdateColName)) { continue; } string fieldName2 = fieldName + "\n" + type; string columnName = "col" + col.GetAttribute("Index"); int index = dgData.Columns.Add(columnName, fieldName2); DataGridViewColumn column = dgData.Columns[index]; column.Tag = col; if (fieldName == "uid") { uidColumnName = columnName; } if (fieldName == "last_update") { lastUpdateColName = columnName; } if (UDTTable.IsDefaultField(fieldName)) { column.ReadOnly = true; } } foreach (XmlElement record in rsp.GetElements("Record")) { int rowIndex = dgData.Rows.Add(); DataGridViewRow row = dgData.Rows[rowIndex]; row.HeaderCell.Value = rowIndex; XmlHelper h = new XmlHelper(record); foreach (XmlElement col in h.GetElements("Column")) { string columnName = "col" + col.GetAttribute("Index"); string value = col.InnerText; if (!dgData.Columns.Contains(columnName)) { continue; } DataGridViewCell cell = row.Cells[columnName]; cell.Value = value; cell.Tag = value; if (columnName == uidColumnName) { row.Tag = value; } } } }