protected string checkDB(TF_TB_FIELD fdObj, TF_TABLE tbObj) { if (string.IsNullOrEmpty(tbObj.TB_NAME)) { return(null); } string ret = ""; DataBaseTable dt1; DataBaseField df1; if (!DataBaseHelper.dbMain.TryGetValue(tbObj.TB_NAME, fdObj.FIELD_NAME, out dt1, out df1)) { ret = string.Format("<font color='red'>物理字段不存在</font><a href='FIELDEdit.aspx?KeyID={0}&tree=" + DateTime.Now.Millisecond + "'>新增</a>", fdObj.FIELD_ID); } string FORM_TB = WFOBJECT_BLL.GetWFTempTBName(tbObj); if (!string.IsNullOrEmpty(FORM_TB) && !DataBaseHelper.dbMain.TryGetValue(FORM_TB, fdObj.FIELD_NAME, out dt1, out df1)) { ret = string.Format("<font color='red'>流程表中,物理字段不存在</font><a href='FIELDEdit.aspx?KeyID={0}&tree=" + DateTime.Now.Millisecond + "'>新增</a>", fdObj.FIELD_ID); } return(ret); }
/// <summary> /// 操作物理表字段,插入或更新 /// </summary> public int InsertOrUpdateField(TF_TB_FIELD field, string oldbame, ref string errMsg) { try { if (string.IsNullOrEmpty(oldbame)) { oldbame = field.FIELD_NAME; } int tb_id = field.TB_ID; int FIELD_ID = field.FIELD_ID; if (FIELD_ID != 0)//修改的时候 { if (tb_id == 0) { errMsg = "物理数据库中新增字段失败!"; tb_id = Convert.ToInt32(BLLTable <TF_TB_FIELD> .Factory(conn).GetOneValue(TF_TB_FIELD.Attribute.FIELD_ID, field.FIELD_ID, TF_TB_FIELD.Attribute.TB_ID)); field.TB_ID = tb_id; } } TF_TABLE tbObj = null; if (tb_id != 0)//插入的时候 { errMsg = "物理数据库中编辑字段失败!"; tbObj = BLLTable <TF_TABLE> .Factory(conn).GetRowData(TF_TABLE.Attribute.TB_ID, tb_id); } string tbname = tbObj.TB_NAME; string colname = field.FIELD_NAME; string sqlcoltype = field.DB_TYPE;//decimal(10,0) string msg = null; //修改正式表字段名称或类型 DataBaseField f1 = null; DataBaseTable t1 = null; if (DataBase.Factory(conn).TryGetValue(tbname, oldbame.Trim(), out t1, out f1)) { DataBaseField newf1 = f1.Clone(); if (field.IS_NULL == 0) { newf1.IsAllowNull = true; } newf1.FieldName = field.FIELD_NAME; newf1.DataType = FieldDataType.FromString(t1.DataBase.DataBaseType, sqlcoltype, true); if (!newf1.Update(f1, true, ref msg)) { errMsg += msg; return(0); } } else//如果没有存在,则新增 { DataBaseField newf1 = new DataBaseField(); if (field.IS_NULL == 0) { newf1.IsAllowNull = true; } newf1.FieldName = field.FIELD_NAME; newf1.DataType = FieldDataType.FromString(t1.DataBase.DataBaseType, sqlcoltype, true); if (!t1.AddField(newf1, ref msg)) { errMsg += msg; return(0); } if (!DataBase.Factory(conn).TryGetValue(tbname, newf1.FieldName, out t1, out f1)) { errMsg += "未存在"; } } #region //流程对应流程的临时表对应的字段信息 tbname = WFOBJECT_BLL.GetWFTempTBName(tbObj); //tbObj.WF_TB_NAME; //修改正式表字段名称或类型 f1 = null; t1 = null; //CHG START 为空条件判断有误 jin-shenjian 2013/10/12 //if (!string.IsNullOrEmpty(tbname) && DataBase.Factory(conn).TryGetValue(tbname, oldbame, out t1, out f1)) if (!string.IsNullOrEmpty(tbname)) { if (DataBase.Factory(conn).TryGetValue(tbname, oldbame, out t1, out f1)) //CHG END 为空条件判断有误 jin-shenjian 2013/10/12 { DataBaseField newf1 = f1.Clone(); if (field.IS_NULL == 0) { newf1.IsAllowNull = true; } newf1.FieldName = field.FIELD_NAME; newf1.DataType = FieldDataType.FromString(t1.DataBase.DataBaseType, sqlcoltype, true); if (!newf1.Update(f1, true, ref msg)) { errMsg += msg; return(0); } } else//如果没有存在,则新增 { DataBaseField newf1 = new DataBaseField(); if (field.IS_NULL == 0) { newf1.IsAllowNull = true; } newf1.FieldName = field.FIELD_NAME; newf1.DataType = FieldDataType.FromString(t1.DataBase.DataBaseType, sqlcoltype, true); if (!t1.AddField(newf1, ref msg)) { errMsg += msg; return(0); } if (!DataBase.Factory(conn).TryGetValue(tbname, newf1.FieldName, out t1, out f1)) { errMsg += "未存在"; } } } #endregion return(1); } catch (Exception ex) { errMsg = ex.ToString(); return(0); } }