private static List <MD_InputModel_SaveTable> GetWriteDesTableOfInputModel(MD_InputModel _model) { List <MD_InputModel_SaveTable> _ret = new List <MD_InputModel_SaveTable>(); using (SqlConnection cn = SqlHelper.OpenConnection()) { SqlCommand _cmd = new SqlCommand(SQL_GetWriteDesTableOfInputModel, cn); _cmd.Parameters.Add("@IVID", _model.ID); SqlDataReader _dr = _cmd.ExecuteReader(); while (_dr.Read()) { MD_InputModel_SaveTable _tb = new MD_InputModel_SaveTable( _dr.IsDBNull(0) ? "" : _dr.GetDecimal(0).ToString(), _dr.IsDBNull(1) ? "" : _dr.GetString(1), _dr.IsDBNull(2) ? "" : _dr.GetString(2), _dr.IsDBNull(3) ? true : (_dr.GetDecimal(3) > 0), _model.ID, _dr.IsDBNull(4) ? 0 : Convert.ToInt32(_dr.GetDecimal(4)), _dr.IsDBNull(5) ? "" : _dr.GetString(5) ); GetInputModelSaveTableColumn(_tb); _ret.Add(_tb); } _dr.Close(); } return(_ret); }
private void ShowInputModelWriteTableDefine(MD_InputModel_SaveTable _saveTable) { UC_WriteTable _uc = new UC_WriteTable(_saveTable); _uc.Dock = DockStyle.Fill; this.splitContainerControl1.Panel2.Controls.Add(_uc); CurrentControl = _uc as IMenuControl; }
private void ReInit(MD_InputModel_SaveTable _newTable) { this.SaveTable.TableTitle = _newTable.TableTitle; this.SaveTable.DisplayOrder = _newTable.DisplayOrder; this.SaveTable.IsLock = _newTable.IsLock; this.SaveTable.Columns = _newTable.Columns; this.SaveTable.SaveMode = _newTable.SaveMode; InitForm(); }
public bool SaveInputModelSaveTable(MD_InputModel_SaveTable NewTable) { try { OraMetaDataFactroy _of = new OraMetaDataFactroy(); return(_of.SaveInputModelSaveTable(NewTable)); } catch (Exception ex) { throw new FaultException(ex.Message); } }
private MD_InputModel_SaveTable GetInputData() { MD_InputModel_SaveTable _ret = new MD_InputModel_SaveTable(); _ret.ID = this.SaveTable.ID; _ret.InputModelID = this.SaveTable.InputModelID; _ret.TableName = this.SaveTable.TableName; _ret.TableTitle = this.te_DisplayName.EditValue.ToString(); _ret.IsLock = (bool)this.te_Lock.EditValue; _ret.SaveMode = this.te_SaveMode.EditValue.ToString(); _ret.DisplayOrder = Convert.ToInt32(this.te_Order.EditValue.ToString()); _ret.Columns = this.gridControl1.DataSource as List <MD_InputModel_SaveTableColumn>; return(_ret); }
private void bt_DelSaveTable_ItemClick(object sender, ItemClickEventArgs e) { object _selectedObj = FocusedItem; if (_selectedObj is MD_InputModel_SaveTable) { MD_InputModel_SaveTable _table = _selectedObj as MD_InputModel_SaveTable; if (XtraMessageBox.Show(string.Format("确定要删除写入表{0}吗?", _table.TableName), "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (DAConfig.DataAccess.DelInputModelSavedTable(_table.ID)) { //MD_InputModel _model = DAConfig.QueryDataAccess.GetInputModelByID(_table.InputModelID); this.treeList1.Nodes.Remove(this.treeList1.FocusedNode); } } } }
public static bool SaveInputModelSaveTable(MD_InputModel_SaveTable _newTable) { using (SqlConnection cn = SqlHelper.OpenConnection()) { SqlTransaction _txn = cn.BeginTransaction(); try { SqlCommand _upCmd = new SqlCommand(SQL_SaveInputModelSaveTable, cn); _upCmd.Parameters.Add("@TABLETITLE", _newTable.TableTitle); _upCmd.Parameters.Add("@DISPLAYORDER", Convert.ToDecimal(_newTable.DisplayOrder)); _upCmd.Parameters.Add("@ISLOCK", _newTable.IsLock ? (decimal)1 : (decimal)0); _upCmd.Parameters.Add("@SAVEMODE", _newTable.SaveMode); _upCmd.Parameters.Add("@ID", decimal.Parse(_newTable.ID)); _upCmd.ExecuteNonQuery(); SqlCommand _cmd = new SqlCommand("delete from MD_INPUTTABLECOLUMN where IVT_ID=@ID", cn); _cmd.Parameters.Add("@ID", decimal.Parse(_newTable.ID)); _cmd.ExecuteNonQuery(); foreach (MD_InputModel_SaveTableColumn _col in _newTable.Columns) { SqlCommand _insCmd = new SqlCommand(SQL_SaveInputModelSaveTable_ins, cn); _insCmd.Parameters.Add("@ID", decimal.Parse(_col.ID)); _insCmd.Parameters.Add("@IVT_ID", decimal.Parse(_newTable.ID)); _insCmd.Parameters.Add("@DESCOL", _col.DesColumn); _insCmd.Parameters.Add("@SRCCOL", _col.SrcColumn); _insCmd.Parameters.Add("@METHOD", _col.Method); _insCmd.Parameters.Add("@DESDES", _col.Descript); _insCmd.ExecuteNonQuery(); } _txn.Commit(); return(true); } catch (Exception e) { _txn.Rollback(); return(false); } } }
public void DoSave() { string _msg = ""; if (CheckValid(ref _msg)) { MD_InputModel_SaveTable _newTable = GetInputData(); if (DAConfig.DataAccess.SaveInputModelSaveTable(_newTable)) { ReInit(_newTable); } else { XtraMessageBox.Show("保存失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { XtraMessageBox.Show(_msg, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void WriteGridChildData(MD_InputModel_Child _child, object ChildData, SqlConnection cn) { DataTable _srcData = ChildData as DataTable; if (_srcData == null) { return; } DataTable _newData = _srcData.GetChanges(DataRowState.Added); DataTable _modifyData = _srcData.GetChanges(DataRowState.Modified); DataTable _delData = _srcData.GetChanges(DataRowState.Deleted); if (_newData != null || _modifyData != null) { foreach (MD_InputModel_SaveTable _table in _child.ChildModel.WriteTableNames) { string _sql = string.Format("select * from {0} ", _table.TableName); SqlDataAdapter adapter = new SqlDataAdapter(_sql, cn); SqlCommandBuilder builder = new SqlCommandBuilder(adapter); if (_newData != null && _newData.Rows.Count > 0) { SqlHelper.UpdateData(cn, _sql, _newData.GetChanges()); } if (_modifyData != null && _modifyData.Rows.Count > 0) { SqlHelper.UpdateData(cn, _sql, _modifyData.GetChanges()); } } } if (_delData != null && _delData.Rows.Count > 0) { for (int i = _child.ChildModel.WriteTableNames.Count; i > 0; i--) { MD_InputModel_SaveTable _table = _child.ChildModel.WriteTableNames[i - 1]; string _sql = string.Format("select * from {0} ", _table.TableName); SqlHelper.UpdateData(cn, _sql, _delData.GetChanges()); } } }
private static void GetInputModelSaveTableColumn(MD_InputModel_SaveTable _tb) { using (SqlConnection cn = SqlHelper.OpenConnection()) { SqlCommand _cmd = new SqlCommand(SQL_GetInputModelSaveTableColumn, cn); _cmd.Parameters.Add("@TID", decimal.Parse(_tb.ID)); SqlDataReader _dr = _cmd.ExecuteReader(); if (_tb.Columns == null) { _tb.Columns = new List <MD_InputModel_SaveTableColumn>(); } while (_dr.Read()) { MD_InputModel_SaveTableColumn _col = new MD_InputModel_SaveTableColumn( _dr.IsDBNull(0) ? "" : _dr.GetDecimal(0).ToString(), _dr.IsDBNull(1) ? "" : _dr.GetString(1), _dr.IsDBNull(2) ? "" : _dr.GetString(2), _dr.IsDBNull(3) ? "" : _dr.GetString(3), _dr.IsDBNull(4) ? "" : _dr.GetString(4) ); _tb.Columns.Add(_col); } _dr.Close(); } }
public bool SaveInputModelSaveTable(MD_InputModel_SaveTable _newTable) { return(MetaDataFactroy.SaveInputModelSaveTable(_newTable)); }
public UC_WriteTable(MD_InputModel_SaveTable _table) { InitializeComponent(); SaveTable = _table; InitForm(); }
private void WriteNewTableData(MD_InputModel_SaveTable _table, MD_InputEntity _entity, SqlConnection cn) { StringBuilder _vStr = new StringBuilder(); _vStr.Append(" values ( "); StringBuilder _sb = new StringBuilder(); _sb.Append("insert into "); _sb.Append(_table.TableName); _sb.Append(" ( "); string _fg = ""; foreach (MD_InputModel_SaveTableColumn _col in _table.Columns) { if (_col.SrcColumn == "" && _col.Method == "") { //如果写入源字段和算法都为空,则此字段不写入 continue; } _sb.Append(string.Format("{0}{1}", _fg, _col.DesColumn)); if (_col.SrcColumn == "") { // 如果写入源字段为空,则仅使用算法写入本字段内容 _vStr.Append(_fg); _vStr.Append(ConvertVar(_col.Method, _entity)); } else { //如果写入源字段不为空 if (_col.Method == "") { //如果算法为空,则写入源字段内容 _vStr.Append(string.Format("{0}:{1}", _fg, _col.DesColumn)); } else { //算法不为空,将算法做为写入算法,参数照样代入 _vStr.Append(_fg); _vStr.Append(string.Format(_col.Method, ConvertVar(_col.Method, _entity))); } } _fg = ","; } _sb.Append(" ) "); _sb.Append(_vStr.ToString()); _sb.Append(" ) "); List <SqlParameter> _plist = new List <SqlParameter>(); foreach (MD_InputModel_SaveTableColumn _col in _table.Columns) { string _cname = _col.SrcColumn; if (_cname != "") { string _data = _entity.InputData.ContainsKey(_cname) ? _entity.InputData[_cname] : null; _plist.Add(new SqlParameter(string.Format(":{0}", _col.DesColumn), _data)); } } SqlParameter[] _params = _plist.ToArray(); SqlHelper.ExecuteNonQuery(cn, CommandType.Text, _sb.ToString(), _params); }
private void UpdateTableData(MD_InputModel_SaveTable _table, MD_InputEntity _entity, SqlConnection cn) { List <string> _mainKeyList = MetaDataFactory.GetDBPrimayKeyList(_table.TableName); StringBuilder _sb = new StringBuilder(); _sb.Append("update "); _sb.Append(_table.TableName); _sb.Append(" set "); string _fg = ""; //制作更新字段SQL语句 int _UpdateFieldCount = 0; foreach (MD_InputModel_SaveTableColumn _col in _table.Columns) { if (_col.SrcColumn == "" && _col.Method == "") { //如果写入源字段和算法都为空,则此字段不写入 continue; } if (!_mainKeyList.Contains(_col.DesColumn)) { _UpdateFieldCount++; _sb.Append(_fg); _fg = " , "; _sb.Append(_col.DesColumn); if (_col.SrcColumn == "") { _sb.Append("="); _sb.Append(ConvertVar(_col.Method, _entity)); } else { if (_col.Method == "") { _sb.Append("=:"); _sb.Append(_col.DesColumn); } else { _sb.Append("="); _sb.Append(string.Format(_col.Method, ConvertVar(_col.Method, _entity))); } } } } if (_UpdateFieldCount < 1) { //无更新字段,直接返回true; return; } _sb.Append(" where "); _fg = ""; //制作主键字段条件语句 foreach (string _key in _mainKeyList) { _sb.Append(_fg); _sb.Append(_key); _sb.Append(" =:"); _sb.Append(_key); _fg = " and "; } SqlCommand _cmd = new SqlCommand(_sb.ToString(), cn); //添加更新字段参数 foreach (MD_InputModel_SaveTableColumn _col in _table.Columns) { string _cname = _col.SrcColumn; if (_cname != "") { string _data = _entity.InputData.ContainsKey(_cname) ? _entity.InputData[_cname] : null; if (!_mainKeyList.Contains(_col.DesColumn)) { _cmd.Parameters.Add(string.Format(":{0}", _col.DesColumn), _data); } } } //添加主键字段参数 foreach (string _key in _mainKeyList) { MD_InputModel_SaveTableColumn _kcol = GetColumnByDesName(_key, _table.Columns); if (_kcol != null) { string _data = _entity.InputData.ContainsKey(_kcol.SrcColumn) ? _entity.InputData[_kcol.SrcColumn] : null; _cmd.Parameters.Add(string.Format(":{0}", _key), _data); } } _cmd.ExecuteNonQuery(); }