public TreeNode PrepareNode(JField field) { var fieldNode = new TreeNode(field.FieldName); fieldNode.Tag = field.FieldName; if (field.ValueType == JFieldType.DateTime) { fieldNode.ImageIndex = fieldNode.SelectedImageIndex = 4; } else if (field.ValueType == JFieldType.Numeric) { fieldNode.ImageIndex = fieldNode.SelectedImageIndex = 5; } else { fieldNode.ImageIndex = fieldNode.SelectedImageIndex = 1; } if (!field.Visible) { if (!field.AllowNull) { fieldNode.ForeColor = Color.Red; } else { fieldNode.ForeColor = Color.OrangeRed; } } return fieldNode; }
private void BtnSave_Click(object sender, EventArgs e) { DBColumn dbColumn = new DBColumn() { ColumnName = txtColumnName.Text, AllowNull = checkBoxAllowNull.Checked, DbType = JFieldType.String, }; int length = 0; if (!string.IsNullOrEmpty(txtLength.Text)) { int.TryParse(txtLength.Text, out length); dbColumn.Length = length; } if (!string.IsNullOrEmpty(comboBoxSQLDBType.Text)) { JFieldType dbType; if (Enum.TryParse<JFieldType>(comboBoxSQLDBType.Text, out dbType)) { dbColumn.DbType = dbType; } } JField field = new JField(dbColumn); if (AddFieldDelegate != null) { AddFieldDelegate(field); } this.Close(); }
public JTable(DBTable dbTable, string connStr) : this() { this.TableName = dbTable.TableName; this.Fields = new List <JField>(); foreach (var item in dbTable.Columns) { JField field = new JField(item); this.Fields.Add(field); } if (dbTable.PrimaryKey != null) { this.Fields.Add(new JField(dbTable.PrimaryKey)); } foreach (var fk in dbTable.ForeignKeys) { this.Fields.Add(new JField(fk)); } this.ConnStr = connStr; }
public void Process(string connStr = "") { if (string.IsNullOrEmpty(connStr)) { connStr = this.ConnStr; } using (OleDbConnection conn = new OleDbConnection(connStr)) { JTable table = this; StringBuilder builder = new StringBuilder(); if (!string.IsNullOrEmpty(table.BeforeSQL)) { builder.Append(Constants.SQLParagraphStartFlag).AppendLine(); builder.Append(table.BeforeSQL).AppendLine(); builder.Append(Constants.SQLParagraphEndFlag).AppendLine(); } List <ColumnDataCache> caches = new List <ColumnDataCache>(); table.Fields.ForEach(op => { string tableName = op.FirstOperand.ReferenceTableName; string columnName = op.FirstOperand.ReferenceColumnName; if (op.FirstOperand.ValueCategroy == JValueCategroy.FromTable && !HaveParameter(op.FirstOperand.RefFilter) && caches.Count(row => row.Table == TableName && row.Column == columnName) < 1) { List <object> datas = CommonDAL.GetValues(conn, tableName, columnName, op.FirstOperand.RefFilter); caches.Add(new ColumnDataCache() { Table = tableName, Column = columnName, Datas = datas }); } if (op.SecondOperand != null) { string tableName1 = op.FirstOperand.ReferenceTableName; string columnName1 = op.FirstOperand.ReferenceColumnName; if (op.SecondOperand.ValueCategroy == JValueCategroy.FromTable && !HaveParameter(op.SecondOperand.RefFilter) && caches.Count(row => row.Table == tableName1 && row.Column == columnName1) < 1) { List <object> datas = CommonDAL.GetValues(conn, tableName1, columnName1, op.FirstOperand.RefFilter); caches.Add(new ColumnDataCache() { Table = tableName1, Column = columnName1, Datas = datas }); } } }); for (int i = 0; i < table.DataCount; i++) { #region 生成每一条数据 string format = "insert into {0}({1}) values({2});"; StringBuilder fieldNameBuilder = new StringBuilder(); StringBuilder fieldValueBuilder = new StringBuilder(); Dictionary <string, object> fieldValuesOfCurrentRow = new Dictionary <string, object>(); JField[] fields = table.Fields.Where(row => row.Visible == true).OrderBy(row => row.Order).ToArray(); for (int f = 0; f < fields.Count(); f++) { JField field = fields[f]; try { fieldNameBuilder.AppendFormat("{0},", field.FieldName); object value1 = field.FirstOperand.GetValue(conn, fieldValuesOfCurrentRow, caches); object value2 = field.SecondOperand == null ? null : field.SecondOperand.GetValue(conn, fieldValuesOfCurrentRow, caches); object value = value1; if (field.Operator != null && field.SecondOperand != null && field.SecondOperand.ValueType == JFieldType.Numeric) { switch (field.FirstOperand.ValueType) { case JFieldType.DateTime: DateTime dtValue1 = DateTime.Parse(value1.ToJString(DateTime.Now.ToString())); double dtParameter = double.Parse(value2.ToJString("0")); switch (field.Operator) { case "+": value = dtValue1.AddDays(dtParameter); break; case "-": value = dtValue1.AddDays(-dtParameter); break; case "*": throw new FieldValueTypeNotSupportOperatorException(field.FieldName, field.ValueType, "*"); case "/": throw new FieldValueTypeNotSupportOperatorException(field.FieldName, field.ValueType, "/"); case "%": throw new FieldValueTypeNotSupportOperatorException(field.FieldName, field.ValueType, "%"); } break; case JFieldType.Numeric: double numericParameter1 = double.Parse(value1.ToJString("0")); double numericParameter2 = double.Parse(value2.ToJString("0")); switch (field.Operator) { case "+": value = numericParameter1 + numericParameter2; break; case "-": value = numericParameter1 - numericParameter2; break; case "*": value = numericParameter1 * numericParameter2; break; case "/": value = numericParameter1 / numericParameter2; break; case "%": value = (int)numericParameter1 % (int)numericParameter2; break; } break; case JFieldType.String: string strValue1 = value1.ToJString(""); string strValue2 = value2.ToJString(""); switch (field.Operator) { case "+": value = strValue1 + strValue2; break; case "-": throw new FieldValueTypeNotSupportOperatorException(field.FieldName, field.ValueType, "-"); case "*": throw new FieldValueTypeNotSupportOperatorException(field.FieldName, field.ValueType, "*"); case "/": throw new FieldValueTypeNotSupportOperatorException(field.FieldName, field.ValueType, "/"); case "%": throw new FieldValueTypeNotSupportOperatorException(field.FieldName, field.ValueType, "%"); } break; } } fieldValueBuilder.AppendFormat( GetFileValueFormat(field.ValueType) , field.ValueType == JFieldType.DateTime ? DateTime.Parse(value.ToString()).ToString("yyyy-MM-dd HH:mm:ss") : value ); fieldValuesOfCurrentRow.Add(field.FieldName, value); } catch (Exception ex) { throw new Exception(string.Format("Data:{0}-{1},Filed:{2} ErrorMessage:{3} ", field.ValueType.ToString(), field.FirstOperand.ValueCategroy.ToString(), field.FieldName, ex.ToString())); } } #endregion builder.AppendFormat(format, table.TableName, fieldNameBuilder.ToString(0, fieldNameBuilder.Length - 1), fieldValueBuilder.ToString(0, fieldValueBuilder.Length - 1)).AppendLine(); if (builder.Length > Constants.SqlBufferSize && SqlProcess != null) { SqlProcess(builder, this); builder.Clear(); } } if (!string.IsNullOrEmpty(table.AfterSQL)) { builder.Append(Constants.SQLParagraphStartFlag).AppendLine(); builder.Append(table.AfterSQL).AppendLine(); builder.Append(Constants.SQLParagraphEndFlag).AppendLine(); } if (builder.Length > 0 && SqlProcess != null) { SqlProcess(builder, this); builder.Clear(); } } }
private void BindFieldInfo(JField field) { if (field == null) { return; } lbFieldName.Text = field.FieldName; cBoxValueType.Text = field.ValueType.ToJString(); cBoxVisible.Text = field.Visible.ToJString("True"); cBoxOperator.Text = field.Operator; operandCtrl1.LoadJOperateNum(field.FirstOperand, field.FieldName); operandCtrl2.LoadJOperateNum(field.SecondOperand, field.FieldName); }
public JTable(DBTable dbTable, string connStr) : this() { this.TableName = dbTable.TableName; this.Fields = new List<JField>(); foreach (var item in dbTable.Columns) { JField field = new JField(item); this.Fields.Add(field); } if (dbTable.PrimaryKey != null) this.Fields.Add(new JField(dbTable.PrimaryKey)); foreach (var fk in dbTable.ForeignKeys) { this.Fields.Add(new JField(fk)); } this.ConnStr = connStr; }