Exemplo n.º 1
0
        public override void SubmitDataTable(DataTable datatable, SqlStruct sqlStruct, SqlOperatorType sqlOperatorType)
        {
            if (sqlStruct.SqlString.Length != 0)
            {
                try
                {
                    this.Open();
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    SqlCommand     command = this.BuildSqlCommandByStructure(sqlStruct);
                    switch (sqlOperatorType)
                    {
                    case SqlOperatorType.Insert:
                        adapter.InsertCommand = command;
                        break;

                    case SqlOperatorType.Update:
                        adapter.UpdateCommand = command;
                        break;

                    case SqlOperatorType.Delete:
                        adapter.DeleteCommand = command;
                        break;
                    }
                    adapter.Update(datatable);
                    command.Dispose();
                    adapter.Dispose();
                }
                catch (Exception exception)
                {
                    exception.HelpLink = " 相关sql语句: " + sqlStruct.SqlString;
                    throw exception;
                }
            }
        }
Exemplo n.º 2
0
        public virtual EntityData SelectbyPrimaryKey(object keyvalues)
        {
            EntityData data2;

            try
            {
                EntityData entitydata = new EntityData(this.m_EntityName);
                SqlStruct  sqlStruct  = SqlManager.GetSqlStruct(this.m_EntityName, "Select");
                if (sqlStruct.SqlString.Length != 0)
                {
                    if (1 != sqlStruct.ParamsList.Length)
                    {
                        throw new ApplicationException("参数列表不匹配");
                    }
                    this.db.FillEntity(sqlStruct.SqlString, sqlStruct.ParamsList[0], keyvalues, entitydata, this.m_EntityName);
                }
                data2 = entitydata;
            }
            catch (Exception exception)
            {
                this.db.Close();
                throw exception;
            }
            return(data2);
        }
Exemplo n.º 3
0
 public override void InsertEntity(EntityData entitydata)
 {
     try
     {
         this.CheckData(entitydata);
         string    className = entitydata.MainTableName;
         SqlStruct sqlStruct = SqlManager.GetSqlStruct(className, "Insert");
         if (sqlStruct.SqlString.Length != 0)
         {
             base.db.SubmitDataTable(entitydata.Tables[className], sqlStruct, SqlOperatorType.Insert);
         }
         foreach (DataRelation relation in entitydata.Relations)
         {
             if (className == relation.ParentTable.TableName)
             {
                 string    tableName = relation.ChildTable.TableName;
                 SqlStruct struct3   = SqlManager.GetSqlStruct(tableName, "Insert");
                 if (struct3.SqlString.Length != 0)
                 {
                     base.db.SubmitDataTable(entitydata.Tables[tableName], struct3, SqlOperatorType.Insert);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
Exemplo n.º 4
0
        public static SqlStruct GetSqlStruct(string className, string tableName, string sqlStringName)
        {
            SqlStruct struct3;

            try
            {
                XmlDocument xmlDoc  = XmlDefineFileManage.GetXmlDoc(className);
                SqlStruct   struct2 = new SqlStruct();
                XmlNode     node2   = xmlDoc.DocumentElement.SelectSingleNode("Table[Name='" + tableName + "']");
                if (node2 == null)
                {
                    throw new ApplicationException("没有找到表: " + tableName);
                }
                XmlNode node3 = node2.SelectSingleNode("Sql[Name='" + sqlStringName + "']");
                if (node3 == null)
                {
                    throw new ApplicationException("没有找到定义的字符串:  " + tableName + "---" + sqlStringName);
                }
                struct2.SqlString   = node3.SelectSingleNode("String").InnerText;
                struct2.CommandType = node3.SelectSingleNode("CommandType").InnerText;
                XmlNodeList list  = node3.SelectNodes("Param");
                int         count = list.Count;
                struct2.ParamsList    = new string[count];
                struct2.ColumnsList   = new string[count];
                struct2.SqlDbTypeList = new string[count];
                if (count != 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        struct2.ParamsList[i]    = list[i].SelectSingleNode("Name").InnerText;
                        struct2.ColumnsList[i]   = list[i].SelectSingleNode("Column").InnerText;
                        struct2.SqlDbTypeList[i] = list[i].SelectSingleNode("SqlDbType").InnerText;
                    }
                }
                XmlNodeList list2 = node3.SelectNodes("Order");
                int         num3  = list2.Count;
                struct2.OrderNameList = new string[num3];
                struct2.OrderSortList = new string[num3];
                for (int j = 0; j < num3; j++)
                {
                    struct2.OrderNameList[j] = list2[j].SelectSingleNode("Name").InnerText;
                    struct2.OrderSortList[j] = list2[j].SelectSingleNode("Sort").InnerText;
                }
                struct3 = struct2;
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return(struct3);
        }
Exemplo n.º 5
0
 public virtual void DeleteEntity(EntityData entitydata)
 {
     try
     {
         this.CheckData(entitydata);
         SqlStruct sqlStruct = SqlManager.GetSqlStruct(this.m_EntityName, "Delete");
         if (sqlStruct.SqlString.Length != 0)
         {
             this.db.SubmitDataTable(entitydata.Tables[this.m_EntityName], sqlStruct, SqlOperatorType.Delete);
         }
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
Exemplo n.º 6
0
        public override EntityData SelectbyPrimaryKey(object[] keyvalues)
        {
            EntityData data2;

            try
            {
                EntityData entitydata = new EntityData(base.m_EntityName);
                string     className  = entitydata.MainTableName;
                foreach (DataRelation relation in entitydata.Relations)
                {
                    if (className == relation.ChildTable.TableName)
                    {
                        string    tableName = relation.ParentTable.TableName;
                        SqlStruct sqlStruct = SqlManager.GetSqlStruct(tableName, "Select");
                        if (sqlStruct.SqlString.Length != 0)
                        {
                            base.db.FillEntity(sqlStruct.SqlString, sqlStruct.ParamsList, keyvalues, entitydata, tableName);
                        }
                    }
                }
                SqlStruct struct3 = SqlManager.GetSqlStruct(className, "Select");
                if (struct3.SqlString.Length != 0)
                {
                    base.db.FillEntity(struct3.SqlString, struct3.ParamsList, keyvalues, entitydata, base.m_EntityName);
                }
                foreach (DataRelation relation2 in entitydata.Relations)
                {
                    if (className == relation2.ParentTable.TableName)
                    {
                        string    text3   = relation2.ChildTable.TableName;
                        SqlStruct struct4 = SqlManager.GetSqlStruct(text3, "Select");
                        if (struct4.SqlString.Length != 0)
                        {
                            base.db.FillEntity(struct4.SqlString, struct4.ParamsList, keyvalues, entitydata, text3);
                        }
                    }
                }
                data2 = entitydata;
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return(data2);
        }
Exemplo n.º 7
0
        public override EntityData SelectAll()
        {
            EntityData data2;

            try
            {
                EntityData entitydata = new EntityData(base.m_EntityName);
                foreach (DataRelation relation in entitydata.Relations)
                {
                    if (entitydata.Tables[base.m_EntityName].TableName == relation.ChildTable.TableName)
                    {
                        string    tableName = relation.ParentTable.TableName;
                        SqlStruct struct2   = SqlManager.GetSqlStruct(base.m_EntityName, tableName, "SelectAll");
                        if (struct2.SqlString.Length != 0)
                        {
                            base.db.FillEntity(struct2.GetSqlStringWithOrder(), (string[])null, (object[])null, entitydata, tableName);
                        }
                    }
                }
                SqlStruct sqlStruct = SqlManager.GetSqlStruct(base.m_EntityName, "SelectAll");
                if (sqlStruct.SqlString.Length != 0)
                {
                    base.db.FillEntity(sqlStruct.GetSqlStringWithOrder(), (string[])null, (object[])null, entitydata, base.m_EntityName);
                }
                foreach (DataRelation relation2 in entitydata.Relations)
                {
                    if (entitydata.Tables[base.m_EntityName].TableName == relation2.ParentTable.TableName)
                    {
                        string    text2   = relation2.ChildTable.TableName;
                        SqlStruct struct4 = SqlManager.GetSqlStruct(base.m_EntityName, text2, "SelectAll");
                        if (struct4.SqlString.Length != 0)
                        {
                            base.db.FillEntity(struct4.GetSqlStringWithOrder(), (string[])null, (object[])null, entitydata, text2);
                        }
                    }
                }
                data2 = entitydata;
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return(data2);
        }
Exemplo n.º 8
0
        public virtual EntityData SelectAll()
        {
            EntityData data2;

            try
            {
                //初始化this.m_EntityName表的表结构
                EntityData entitydata = new EntityData(this.m_EntityName);
                SqlStruct  sqlStruct  = SqlManager.GetSqlStruct(this.m_EntityName, "SelectAll");
                if (sqlStruct.SqlString.Length != 0)
                {
                    this.db.FillEntity(sqlStruct.GetSqlStringWithOrder(), (string[])null, (object[])null, entitydata, this.m_EntityName);
                }
                data2 = entitydata;
            }
            catch (Exception exception)
            {
                this.db.Close();
                throw exception;
            }
            return(data2);
        }
Exemplo n.º 9
0
        private SqlCommand BuildSqlCommandByStructure(SqlStruct sqlStruct)
        {
            SqlCommand command2;

            if (sqlStruct.SqlString.Length == 0)
            {
                return(null);
            }
            try
            {
                SqlDbType  varChar = SqlDbType.VarChar;
                SqlCommand command = this.BuildSqlCommand(sqlStruct.SqlString);
                if (sqlStruct.CommandType == "Text")
                {
                    command.CommandType = CommandType.Text;
                }
                else if (sqlStruct.CommandType == "StoredProcedure")
                {
                    command.CommandType = CommandType.StoredProcedure;
                }
                else if (sqlStruct.CommandType == "TableDirect")
                {
                    command.CommandType = CommandType.TableDirect;
                }
                int length = sqlStruct.ParamsList.Length;
                for (int i = 0; i < length; i++)
                {
                    SqlParameter parameter = new SqlParameter(sqlStruct.ParamsList[i], (SqlDbType)Enum.Parse(varChar.GetType(), sqlStruct.SqlDbTypeList[i]));
                    parameter.SourceColumn = sqlStruct.ColumnsList[i];
                    command.Parameters.Add(parameter);
                }
                command2 = command;
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return(command2);
        }
Exemplo n.º 10
0
 public override void SubmitAllData(DataTable datatable, SqlStruct sqlInsertStruct, SqlStruct sqlUpdateStruct, SqlStruct sqlDeleteStruct)
 {
     try
     {
         this.Open();
         SqlDataAdapter adapter = new SqlDataAdapter();
         if (sqlInsertStruct.SqlString.Length != 0)
         {
             adapter.InsertCommand = this.BuildSqlCommandByStructure(sqlInsertStruct);
         }
         if (sqlUpdateStruct.SqlString.Length != 0)
         {
             adapter.UpdateCommand = this.BuildSqlCommandByStructure(sqlUpdateStruct);
         }
         if (sqlDeleteStruct.SqlString.Length != 0)
         {
             adapter.DeleteCommand = this.BuildSqlCommandByStructure(sqlDeleteStruct);
         }
         adapter.Update(datatable);
         if (adapter.InsertCommand != null)
         {
             adapter.InsertCommand.Dispose();
         }
         if (adapter.UpdateCommand != null)
         {
             adapter.UpdateCommand.Dispose();
         }
         if (adapter.DeleteCommand != null)
         {
             adapter.DeleteCommand.Dispose();
         }
         adapter.Dispose();
     }
     catch (Exception exception)
     {
         exception.HelpLink = " 相关sql语句: /n插入语句: " + sqlInsertStruct.SqlString + "/n更新语句: " + sqlUpdateStruct.SqlString + "/n删除语句: " + sqlDeleteStruct.SqlString + "/n";
         throw exception;
     }
 }
Exemplo n.º 11
0
 public override void ExecSql(DataRow datarow, SqlStruct sqlstruct)
 {
     if (sqlstruct.SqlString.Length != 0)
     {
         try
         {
             this.Open();
             SqlCommand command = this.BuildSqlCommand(sqlstruct.SqlString);
             if (sqlstruct.ParamsList.Length != sqlstruct.ParamsList.Length)
             {
                 throw new ApplicationException("参数和参数值不匹配");
             }
             int length = sqlstruct.ParamsList.Length;
             if (length != 0)
             {
                 for (int i = 0; i < length; i++)
                 {
                     try
                     {
                         command.Parameters.Add(sqlstruct.ParamsList[i], datarow[sqlstruct.ColumnsList[i]]);
                     }
                     catch
                     {
                         throw new ApplicationException("数据结构和数据行不匹配");
                     }
                 }
             }
             command.ExecuteNonQuery();
             command.Dispose();
         }
         catch (Exception exception)
         {
             exception.HelpLink = " 相关sql语句: " + sqlstruct.SqlString;
             throw exception;
         }
     }
 }
Exemplo n.º 12
0
 public abstract void SubmitDataTable(DataTable datatable, SqlStruct sqlStruct, SqlOperatorType sqlOperatorType);
Exemplo n.º 13
0
 public abstract void SubmitAllData(DataTable datatable, SqlStruct sqlInsertStruct, SqlStruct sqlUpdateStruct, SqlStruct sqlDeleteStruct);
Exemplo n.º 14
0
 public abstract void ExecSql(DataRow datarow, SqlStruct sqlstruct);