Esempio n. 1
0
 public void UpdateAtt(string EntityType, int TableKay, string attIdList)
 {
     try
     {
         attIdList = attIdList.TrimEnd(new char[] { ',' });
         using (BizDataContext context = new BizDataContext(true))
         {
             string str;
             int    num = this.GetTableMaxValue("T_Attachment", "TableVersion", 1, "", context) + 1;
             if (!string.IsNullOrEmpty(attIdList))
             {
                 str = string.Format("update t_attachment set OWNEROBJECTID='{0}',OWNERENTITYTYPE='{1}',TableVersion={3}\r\n            where ATTACHMENT_ID in ({2})", new object[] { TableKay, EntityType, attIdList, num });
                 context.ExecuteNonQuery(str, new DbParameter[0]);
                 str = string.Format("update t_attachment set state=9999,TableVersion={0} \r\n                                            where OWNEROBJECTID='{1}' and OWNERENTITYTYPE='{2}' and ATTACHMENT_ID not in ({3})", new object[] { num, TableKay, EntityType, attIdList });
                 context.ExecuteNonQuery(str, new DbParameter[0]);
             }
             else
             {
                 str = string.Format("update t_attachment set state=9999,TableVersion={0} \r\n                                            where OWNEROBJECTID='{1}' and OWNERENTITYTYPE='{2}' ", num, TableKay, EntityType);
                 context.ExecuteNonQuery(str, new DbParameter[0]);
             }
         }
     }
     catch
     {
     }
 }
 protected void btnChangeSystemLevelCode_Click(object sender, EventArgs e)
 {
     using (BizDataContext context = new BizDataContext())
     {
         StringBuilder sbSQL = new StringBuilder();
         //将父部门字段值调整过来并先处理好顶级部门的层级码
         sbSQL.AppendLine("update T_Department set SystemLevelCode = Convert(nvarchar(50),Department_ID)+'-' where Parent_ID is null");
         context.ExecuteNonQuery(sbSQL.ToString());
         var AllDepts    = context.FetchAll <T_Department>();
         var Depts       = AllDepts.Where(p => !(p.Parent_ID == null)).ToList();
         var DealedDepts = AllDepts.Where(p => p.Parent_ID == null).ToList();
         while (Depts.Count > 0)
         {
             for (int i = Depts.Count - 1; i >= 0; i--)
             {
                 var Child      = Depts[i];
                 var FindParent = DealedDepts.FirstOrDefault(p => p.Department_ID == Child.Parent_ID);
                 if (FindParent != null)
                 {
                     //当前未处理的这个是某个已处理的子部门,则处理当前这个,并把它从未处理中移走,加到已处理中。
                     Child.SystemLevelCode = FindParent.SystemLevelCode + Child.Department_ID + "-";
                     context.Update(Child);
                     Depts.Remove(Child);
                     DealedDepts.Add(Child);
                 }
             }
         }
     }
     this.AjaxAlert("调整成功!");
 }
 private static void ProcessError(SysWorkflowMessage msg, Exception ex, string connectionStringOrName)
 {
     if (string.IsNullOrWhiteSpace(connectionStringOrName))
     {
         connectionStringOrName = DataContext.BizConnectionStringDefault;
     }
     try
     {
         using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
         {
             using (BizDataContext context = new BizDataContext(connectionStringOrName, true))
             {
                 if (msg.State != SysWorkflowMessageStateEnum.Running)
                 {
                     throw new Exception(string.Format("消息ID:{0}的状态不为Running", msg.MessageId));
                 }
                 msg.State            = SysWorkflowMessageStateEnum.Error;
                 msg.LastErrorMessage = ex.Message;
                 string sql = string.Format("UPDATE SysWorkflowMessage SET STATE = {0}, LastErrorMessage = {1} WHERE MessageId = {2} AND (STATE = {3} or STATE = {4}) ", new object[] { context.AddPrefixToParameterName("NewState"), context.AddPrefixToParameterName("LastErrorMessage"), context.AddPrefixToParameterName("MessageId"), context.AddPrefixToParameterName("OldState1"), context.AddPrefixToParameterName("OldState2") });
                 if (context.ExecuteNonQuery(sql, new DbParameter[] { context.CreateParameterWithPrefix("NewState", Convert.ToInt32(SysWorkflowMessageStateEnum.Error), typeof(int)), context.CreateParameterWithPrefix("LastErrorMessage", ex.Message, typeof(string)), context.CreateParameterWithPrefix("MessageId", msg.MessageId, typeof(int)), context.CreateParameterWithPrefix("OldState1", Convert.ToInt32(SysWorkflowMessageStateEnum.Running), typeof(int)), context.CreateParameterWithPrefix("OldState2", Convert.ToInt32(SysWorkflowMessageStateEnum.Inited), typeof(int)) }) <= 0)
                 {
                     AppLogHelper.Information("将工作流消息更改为错误状态时更新行数为0: MessageId={0}", new object[] { msg.MessageId });
                 }
             }
             scope.Complete();
         }
         Console.WriteLine(ex.Message);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(exception, "将工作流消息更改为错误状态时失败: MessageId={0}", new object[] { msg.MessageId });
         Console.WriteLine(exception.Message);
     }
 }
Esempio n. 4
0
 public virtual string OnWorkItemCreating(T_WorkItemBase wiBase, SysWorkItem wi)
 {
     if (WebConfigAppSettings.UseSSOModel)
     {
         using (BizDataContext context = new BizDataContext(WebConfigAppSettings.HomeBizDBConnString, true))
         {
             wiBase.WorkItemBase_Id = context.GetNextIdentity_Int(false);
             context.Insert(wiBase);
             DbParameter parameter = context.CreateParameter();
             parameter.ParameterName = context.AddPrefixToParameterName("OwnerBiz");
             parameter.Value         = WebConfigAppSettings.ApplicationName;
             string sql = string.Format("update T_WorkItemBase set OwnerBiz = {0}", parameter.ParameterName);
             context.ExecuteNonQuery(sql, new DbParameter[] { parameter });
             return(wiBase.WorkItemBase_Id.ToString());
         }
     }
     return(null);
 }
Esempio n. 5
0
        private void InternalPublish_ForSqlServer()
        {
            var existTableDict = _db.ExecuteDataTable("select TABLE_NAME,COLUMN_NAME from information_schema.columns").Rows.Cast <DataRow>()
                                 .Select(p => new
            {
                TableName  = Convert.ToString(p["TABLE_NAME"]).ToLower(),
                ColumnName = Convert.ToString(p["COLUMN_NAME"]).ToLower(),
            }).GroupBy(p => p.TableName).ToDictionary(p => p.Key, p => p.Select(x => x.ColumnName).ToList());

            StringBuilder sbSQL = new StringBuilder();

            sbSQL.AppendLine("--------------------------创建或更新表");
            if (existTableDict.ContainsKey(_entity.EntityName.ToLower()))//表已经存在,添加字段
            {
                var existColumnList = existTableDict[_entity.EntityName.ToLower()];
                foreach (SysField _field in _fieldList)
                {
                    if (existColumnList.IndexOf(_field.FieldName.ToLower()) < 0) //字段不存在
                    {
                        switch (_field.DataType)
                        {
                        case (int)FormFieldDataType.Int: sbSQL.AppendFormat(" ALTER TABLE [{0}] ADD [{1}] int ", _entity.EntityName, _field.FieldName); break;

                        case (int)FormFieldDataType.DateTime: sbSQL.AppendFormat(" ALTER TABLE [{0}] ADD [{1}] datetime ", _entity.EntityName, _field.FieldName); break;

                        case (int)FormFieldDataType.File: sbSQL.AppendFormat(" ALTER TABLE [{0}] ADD [{1}] int ", _entity.EntityName, _field.FieldName); break;

                        case (int)FormFieldDataType.Number: sbSQL.AppendFormat(" ALTER TABLE [{0}] ADD [{1}] decimal(38,10) ", _entity.EntityName, _field.FieldName); break;

                        case (int)FormFieldDataType.String: sbSQL.AppendFormat(" ALTER TABLE [{0}] ADD [{1}] nvarchar(256) ", _entity.EntityName, _field.FieldName); break;

                        case (int)FormFieldDataType.Text: sbSQL.AppendFormat(" ALTER TABLE [{0}] ADD [{1}] ntext ", _entity.EntityName, _field.FieldName); break;

                        default: throw new Exception(string.Format("表单字段类型不支持{0}", _field.DataType));
                        }
                    }
                }
            }
            else //表不存在
            {
                sbSQL.AppendFormat("CREATE TABLE [dbo].[{0}]( ", _entity.EntityName);
                string keyName = null;
                foreach (SysField _field in _fieldList)
                {
                    switch (_field.DataType)
                    {
                    case (int)DataTypeEnum.pkey: keyName = _field.FieldName; sbSQL.AppendFormat(" [{0}] [int] NOT NULL, ", _field.FieldName); break;

                    case (int)FormFieldDataType.Int: sbSQL.AppendFormat(" [{0}] [int] NULL, ", _field.FieldName); break;

                    case (int)FormFieldDataType.DateTime: sbSQL.AppendFormat(" [{0}] [datetime] NULL, ", _field.FieldName); break;

                    case (int)FormFieldDataType.File: sbSQL.AppendFormat(" [{0}] [int] NULL, ", _field.FieldName); break;

                    case (int)FormFieldDataType.Number: sbSQL.AppendFormat(" [{0}] [decimal](38, 10) NULL, ", _field.FieldName); break;

                    case (int)FormFieldDataType.String: sbSQL.AppendFormat(" [{0}] [nvarchar](256) NULL, ", _field.FieldName); break;

                    case (int)FormFieldDataType.Text: sbSQL.AppendFormat(" [{0}] [ntext] NULL, ", _field.FieldName); break;

                    default: throw new Exception(string.Format("表单字段类型不支持{0}", _field.DataType));
                    }
                }
                sbSQL.AppendFormat(@" CONSTRAINT [PK_{0}] PRIMARY KEY CLUSTERED 
                                (
	                                [{1}] ASC
                                )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
                                ) ON [PRIMARY]", _entity.EntityName, keyName);
            }
            _db.ExecuteNonQuery(sbSQL.ToString());
        }