Beispiel #1
0
        /// <summary>
        /// 批量插入记录
        /// </summary>
        /// <param name="h"></param>
        /// <returns></returns>
        public bool Insert <T>(List <T> listT)
        {
            try
            {
                if (listT == null || listT.Count == 0)
                {
                    return(false);
                }

                List <string>     listSql   = new List <string>();
                string            sql       = "select {0} from {1}";
                IDbParameters     param     = AdoTemplate.CreateDbParameters();
                Type              type      = typeof(T);
                PropertyInfo[]    propertys = type.GetProperties();
                TableMapAttribute attribute = TableMapAttribute.GetInstance(type);
                string            tableName = attribute.TableName;
                string            cols      = "";
                foreach (PropertyInfo pi in propertys)
                {
                    string name = pi.Name;
                    if (cols != "")
                    {
                        cols += ",";
                    }
                    cols += name;
                }
                sql = string.Format(sql, cols, tableName);
                return(AdoTemplate.DataTableUpdateWithCommandBuilder(ObjectHelper.CopyToDataTable <T>(listT.ToArray()), CommandType.Text, sql, null, tableName) > 0);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #2
0
        public object GetViewBindingObject()
        {
            object obj = this.BindingObject;

            if (obj == null)
            {
                return(null);
            }

            TableMapAttribute     tableAttribute = DomainObjectUtility.GetTableMapAttribute(obj);
            Hashtable             hs             = DomainObjectUtility.GetAttributeMemberInfos(obj);
            IDictionaryEnumerator myEnumerator   = hs.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                string controlText = null;
                controlText = this.Page.Request.Form["txt" + ((FieldMapAttribute)myEnumerator.Key).FieldName];
                if (controlText != null)
                {
                    MemberInfo info1 = (MemberInfo)myEnumerator.Value;
                    Type       type1 = (info1 is FieldInfo) ? ((FieldInfo)info1).FieldType : ((PropertyInfo)info1).PropertyType;
                    DomainObjectUtility.SetValue(obj, info1, controlText, null);
                }
            }
            return(obj);
        }
        protected KeyInfo GetParentKey(Type parentType, DataRelationMapAttribute relationMap, int schemeId, object[] attrs)
        {
            TableMapAttribute tableId = Array.Find(attrs, a =>
                                                   a is TableMapAttribute) as TableMapAttribute ?? new TableMapAttribute((int[])null);

            KeyInfo ki = new KeyInfo();

            ki.Name       = relationMap.MappingName;
            ki.RefTable   = new RefInfo(tableId.TableIx, tableId.TableName);
            ki.ChildType  = relationMap.ItemType;
            ki.ParentType = parentType;

            foreach (object att in attrs)
            {
                DataRelationColumnMapAttribute relColumnMap = att as DataRelationColumnMapAttribute;
                if (relColumnMap == null || relColumnMap.SchemeId != schemeId)
                {
                    continue;
                }

                ki.ParentColumns.Add(relColumnMap.ParentColumn);
                ki.ChildColumns.Add(relColumnMap.ChildColumn);
            }

            return(ki);
        }
Beispiel #4
0
        private object[] ConvertArrayListToObjectArray(DataTable table)
        {
            TableMapAttribute tableAttribute = DomainObjectUtility.GetTableMapAttribute(GetImportType());

            string[] PKs = tableAttribute.GetKeyFields();
            if (PKs != null)
            {
                for (int i = 0; i < PKs.Length; i++)
                {
                    for (int j = 0; j < table.Rows.Count; j++)
                    {
                        if (string.Compare(PKs[i], "PLANDATE", true) == 0)
                        {
                            string planDate = table.Rows[j][PKs[i]].ToString().ToUpper();
                            if (planDate.Length > 8)
                            {
                                table.Rows[j][PKs[i]] = FormatHelper.TODateInt(table.Rows[j][PKs[i]].ToString().ToUpper());
                            }
                        }
                        else
                        {
                            table.Rows[j][PKs[i]] = table.Rows[j][PKs[i]].ToString().ToUpper();
                        }
                    }
                }

                for (int i = 0; i < table.Columns.Count; i++)
                {
                    for (int j = 0; j < table.Rows.Count; j++)
                    {
                        if (table.Columns[i].ColumnName == "PLANSTARTTIME")
                        {
                            string planStartTime = table.Rows[j][i].ToString().ToUpper();
                            if (planStartTime.Length > 6)
                            {
                                table.Rows[j][i] = FormatHelper.TOTimeInt(Convert.ToDateTime(table.Rows[j][i].ToString()).ToString("HH:mm:ss"));
                            }
                        }
                        else
                        {
                            table.Rows[j][i] = table.Rows[j][i].ToString().ToUpper();
                        }
                    }
                }
            }

            object[] objs = new object[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                object obj = GetImportType();

                obj = DomainObjectUtility.FillDomainObject(obj, table.Rows[i]);

                this.GetImportObjectType(ref obj, _ImportType);
                objs.SetValue(obj, i);
            }

            return(objs);
        }
 public DataFactoryBase(IDataFactory dataFactory, TableMapAttribute tableAttr)
 {
     _dataFactory = dataFactory;
     _tableAttr   = tableAttr;
     if (dataFactory != null)
     {
         Database = dataFactory.Database;
     }
 }
Beispiel #6
0
        public void RenderBindingObject(HtmlTextWriter output)
        {
            if (this.BindingObject == null)
            {
                return;
            }
            TableMapAttribute     tableAttribute = DomainObjectUtility.GetTableMapAttribute(this.BindingObject);
            Hashtable             hs             = DomainObjectUtility.GetAttributeMemberInfos(this.BindingObject);
            IDictionaryEnumerator myEnumerator   = hs.GetEnumerator();
            int cols  = 0;
            int perTd = 100 / (this.Columns * 2);

            while (myEnumerator.MoveNext())
            {
                if ((cols % this.Columns) == 0)
                {
                    if (cols != 0)
                    {
                        output.RenderEndTag();
                    }
                    output.RenderBeginTag(HtmlTextWriterTag.Tr);
                }

                output.AddStyleAttribute(HtmlTextWriterStyle.Width, perTd.ToString() + "%");
                output.AddAttribute(HtmlTextWriterAttribute.Align, "right");
                output.RenderBeginTag(HtmlTextWriterTag.Td);

                System.Web.UI.WebControls.Label lbl = new System.Web.UI.WebControls.Label();
                lbl.ID   = "lbl" + ((FieldMapAttribute)myEnumerator.Key).FieldName;
                lbl.Text = ((MemberInfo)myEnumerator.Value).Name;
                lbl.RenderControl(output);
                output.RenderEndTag();

                output.AddStyleAttribute(HtmlTextWriterStyle.Width, perTd.ToString() + "%");
                output.AddAttribute(HtmlTextWriterAttribute.Align, "left");
                output.RenderBeginTag(HtmlTextWriterTag.Td);

                Type type1 = ((MemberInfo)myEnumerator.Value is FieldInfo) ? ((FieldInfo)myEnumerator.Value).FieldType : ((PropertyInfo)myEnumerator.Value).PropertyType;

                System.Web.UI.WebControls.TextBox txtBox = new System.Web.UI.WebControls.TextBox();
                txtBox.ID = "txt" + ((FieldMapAttribute)myEnumerator.Key).FieldName;
                //txtBox.Text		= DomainObjectUtility.XMLEncodeValue(((FieldMapAttribute)myEnumerator.Key).DataType, type1, DomainObjectUtility.GetValue(this.BindingObject , ((MemberInfo)myEnumerator.Value), null));
                txtBox.RenderControl(output);
                output.RenderEndTag();
                cols = cols + 1;
            }

            if (((cols - 1) % this.Columns) != 0)
            {
                if (cols > 0)
                {
                    output.RenderEndTag();
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// 更新记录
 /// </summary>
 /// <param name="h"></param>
 /// <returns></returns>
 public bool Update <T>(T t)
 {
     try
     {
         if (t != null)
         {
             string            sql        = "update {0} set {1} where {2};";
             string            sqlUpdate  = "";
             string            sqlWhere   = "";
             IDbParameters     param      = AdoTemplate.CreateDbParameters();
             Type              type       = typeof(T);
             PropertyInfo[]    propertys  = type.GetProperties();
             TableMapAttribute attribute  = TableMapAttribute.GetInstance(type);
             string            tableName  = attribute.TableName;
             string            primaryKey = ((TableMapAttribute)attribute).primaryKey;
             foreach (PropertyInfo pi in propertys)
             {
                 string name  = pi.Name;
                 object value = type.GetProperty(name).GetValue(t, null);
                 //为null则不更新
                 if (value == null || name.ToLower() == "createtime" || name.ToLower() == "createby")
                 {
                     continue;
                 }
                 //主键(作为更新条件)
                 if (name == primaryKey)
                 {
                     sqlWhere = string.Format("{0}=?{0}", name);
                 }
                 else
                 {
                     if (sqlUpdate != "")
                     {
                         sqlUpdate += ",";
                     }
                     sqlUpdate += string.Format("{0}=?{0}", name);
                 }
                 param.AddWithValue(name, value);
             }
             sql = string.Format(sql, tableName, sqlUpdate, sqlWhere);
             return(AdoTemplate.ExecuteNonQuery(CommandType.Text, sql.ToString(), param) > 0);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #8
0
        public string GetTableName()
        {
            string returnValue = string.Empty;

            TableMapAttribute tableMap = DomainObjectUtility.GetTableMapAttribute(_DomainObjectType);

            if (tableMap != null)
            {
                returnValue = tableMap.TableName;
            }

            return(returnValue);
        }
        protected override RefInfo GetRefInfo(ExtractInfo extractInfo)
        {
            object[] attrs = extractInfo.TargetType.GetCustomAttributes(typeof(TableMapAttribute), true);

            if (attrs == null || attrs.Length <= 0)
            {
                return(null);
            }

            TableMapAttribute tm = attrs[0] as TableMapAttribute;

            return(new RefInfo(tm.TableIx, tm.TableName));
        }
Beispiel #10
0
 /// <summary>
 /// 删除记录(逻辑删除,表里必须有IsDelete字段)
 /// </summary>
 public bool DeleteLogical <T>(string columnName, object value)
 {
     try
     {
         TableMapAttribute attribute = TableMapAttribute.GetInstance(typeof(T));
         string            tableName = attribute.TableName;
         IDbParameters     param     = AdoTemplate.CreateDbParameters();
         string            sql       = string.Format("update {0} set IsDelete=1 where {1}=@{1}", tableName, columnName);
         param.AddWithValue(columnName, value);
         return(AdoTemplate.ExecuteNonQuery(CommandType.Text, sql, param) > 0);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #11
0
        public void RenderBindingObjects(HtmlTextWriter output)
        {
            if (this.BindingObjects == null)
            {
                return;
            }
            object[] objects = (object[])this.BindingObjects;
            if (objects.Length < 1)
            {
                return;
            }

            TableMapAttribute     tableAttribute = DomainObjectUtility.GetTableMapAttribute(objects[0]);
            Hashtable             hs             = DomainObjectUtility.GetAttributeMemberInfos(objects[0]);
            IDictionaryEnumerator myEnumerator   = hs.GetEnumerator();

            output.RenderBeginTag(HtmlTextWriterTag.Tr);
            int perTd = 100 / hs.Count;

            while (myEnumerator.MoveNext())
            {
                output.AddStyleAttribute(HtmlTextWriterStyle.Width, perTd.ToString() + "%");
                output.AddAttribute(HtmlTextWriterAttribute.Align, "right");
                output.RenderBeginTag(HtmlTextWriterTag.Td);
                output.Write(((MemberInfo)myEnumerator.Value).Name);
                output.RenderEndTag();
            }
            output.RenderEndTag();

            for (int j = 0; j < objects.Length; j++)
            {
                IDictionaryEnumerator myEnumerator2 = hs.GetEnumerator();
                output.RenderBeginTag(HtmlTextWriterTag.Tr);
                while (myEnumerator2.MoveNext())
                {
                    Type type1 = ((MemberInfo)myEnumerator2.Value is FieldInfo) ? ((FieldInfo)myEnumerator2.Value).FieldType : ((PropertyInfo)myEnumerator2.Value).PropertyType;
                    output.AddStyleAttribute(HtmlTextWriterStyle.Width, perTd.ToString() + "%");
                    output.AddAttribute(HtmlTextWriterAttribute.Align, "right");
                    output.RenderBeginTag(HtmlTextWriterTag.Td);
                    //output.Write(DomainObjectUtility.XMLEncodeValue(((FieldMapAttribute)myEnumerator2.Key).DataType, type1, DomainObjectUtility.GetValue(objects[j] , ((MemberInfo)myEnumerator2.Value), null)));
                    output.RenderEndTag();
                }
                output.RenderEndTag();
            }
        }
Beispiel #12
0
 /// <summary>
 /// 删除记录
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="hs"></param>
 /// <returns></returns>
 public bool Delete <T>(Hashtable hs)
 {
     try
     {
         TableMapAttribute attribute = TableMapAttribute.GetInstance(typeof(T));
         string            tableName = attribute.TableName;
         StringBuilder     sql       = new StringBuilder(string.Format("delete from {0} where 1=1 ", tableName));
         IDbParameters     param     = AdoTemplate.CreateDbParameters();
         foreach (string key in hs.Keys)
         {
             sql.AppendFormat(" and {0}=?{0}", key);
             param.AddWithValue(key, hs[key]);
         }
         return(AdoTemplate.ExecuteNonQuery(CommandType.Text, sql.ToString(), param) > 0);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
 public SqlExecuteFactoryBase(IDataFactory dataFactory, TableMapAttribute tableAttr)
     : base(dataFactory, tableAttr)
 {
 }
 public DeleteExecuteFactory(IDataFactory dataFactory, TableMapAttribute tableAttr)
     : base(dataFactory, tableAttr)
 {
 }
Beispiel #15
0
 // protected const string SQLSPLITE = "${sqlsplite}";
 public SqlTransformFactory(IDataFactory dataFactory, TableMapAttribute tableAttr, object parameter)
     : base(dataFactory, tableAttr)
 {
     _parameter = parameter;
 }
        // private long _curId;

        public InsertTransformFactory(IDataFactory dataFactory, TableMapAttribute tableAttr, object parameter)
            : base(dataFactory, tableAttr, parameter)
        {
        }
        /// <summary>
        /// 默认类型
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private object[] ConvertArrayListToObjectArray(DataTable table, string importtypedt)
        {
            TableMapAttribute tableAttribute =
                DomainObjectUtility.GetTableMapAttribute(GetImportType(importtypedt));

            string[] PKs     = tableAttribute.GetKeyFields();
            string[] Columns = new string[PKs.Length + 1];
            if (string.Compare(importtypedt, "IndirectManCount", true) == 0)
            {
                for (int i = 0; i < Columns.Length; i++)
                {
                    if (i == Columns.Length - 1)
                    {
                        Columns[i] = "Duration";
                    }
                    else
                    {
                        Columns[i] = PKs[i];
                    }
                }
                if (Columns != null)
                {
                    for (int i = 0; i < Columns.Length; i++)
                    {
                        for (int j = 0; j < table.Rows.Count; j++)
                        {
                            if (string.Compare(Columns[i], "ShiftDate", true) == 0)
                            {
                                string planDate = table.Rows[j][Columns[i]].ToString().ToUpper();
                                if (planDate.Length > 7)
                                {
                                    table.Rows[j][Columns[i]] = FormatHelper.TODateInt(Convert.ToDateTime(table.Rows[j][Columns[i]].ToString()).ToString("yyyy-MM-dd"));
                                }
                            }
                            else if (string.Compare(Columns[i], "Duration", true) == 0)
                            {
                                table.Rows[j][Columns[i]] = (Decimal.Parse(table.Rows[j][Columns[i]].ToString()) * 3600).ToString("0");
                            }
                            else
                            {
                                table.Rows[j][Columns[i]] = table.Rows[j][Columns[i]].ToString().ToUpper();
                            }
                        }
                    }
                }
            }

            if (string.Compare(importtypedt, "Line2Crew", true) == 0)
            {
                for (int i = 0; i < PKs.Length; i++)
                {
                    for (int j = 0; j < table.Rows.Count; j++)
                    {
                        if (string.Compare(PKs[i], "ShiftDate", true) == 0)
                        {
                            string planDate = table.Rows[j][PKs[i]].ToString().ToUpper();
                            if (planDate.Length > 7)
                            {
                                table.Rows[j][PKs[i]] = FormatHelper.TODateInt(Convert.ToDateTime(table.Rows[j][PKs[i]].ToString()).ToString("yyyy-MM-dd"));
                            }
                        }
                        else
                        {
                            table.Rows[j][PKs[i]] = table.Rows[j][PKs[i]].ToString().ToUpper();
                        }
                    }
                }
            }

            object[] objs = new object[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                object obj = GetImportType(importtypedt);

                obj = DomainObjectUtility.FillDomainObject(obj, table.Rows[i]);

                this.GetImportObjectType(ref obj, importtypedt);
                objs.SetValue(obj, i);
            }

            return(objs);
        }
 public DataToObjectFactory(IDataFactory dataFactory, TableMapAttribute tableAttr)
     : base(dataFactory, tableAttr)
 {
 }
 public InsertExecuteFactory(IDataFactory dataFactory, TableMapAttribute tableAttr)
     : base(dataFactory, tableAttr)
 {
 }