Ejemplo n.º 1
0
        public void GetSegmentFromSql(MethodInformation method, Type dataType, ref string insertFields, ref string insertParas, ref string updateSets, ref string procParas)
        {
            string dbTag         = DJTools.GetParaTagByDbDialect(DataAdapter.dbDialect);
            string insertFields1 = "";
            string insertParas1  = "";
            string updateSets1   = "";
            string procParas1    = "";

            bool mbool = false;

            string[]   _fields    = method.fields;
            FieldsType fieldsType = method.fieldsType;

            _fields = null == _fields ? new string[] { } : _fields;

            Action <string, string, string> action = (fn1, fn2, fn_lower) =>
            {
                mbool = true;
                foreach (string e in _fields)
                {
                    if (e.ToLower().Equals(fn_lower))
                    {
                        mbool = false;
                        break;
                    }
                }

                if (FieldsType.Contain == fieldsType && 0 < _fields.Length)
                {
                    mbool = !mbool;
                }

                if (mbool)
                {
                    fn2            = string.IsNullOrEmpty(fn2) ? fn1 : fn2;
                    insertFields1 += "," + fn2;
                    insertParas1  += "," + dbTag + fn1;
                    updateSets1   += "," + fn2 + "=" + dbTag + fn1;
                    procParas1    += "," + procParaSign + fn2 + "=" + dbTag + fn1;
                }
            };

            string fn   = "";
            string fn_2 = "";

            if (typeof(DataEntity <DataElement>) == dataType || typeof(List <DataEntity <DataElement> >) == dataType)
            {
                object paraVal = null;
                if (typeof(List <DataEntity <DataElement> >) == dataType)
                {
                    List <DataEntity <DataElement> > dataElements1 = (List <DataEntity <DataElement> >)method.paraList[0].ParaValue;
                    if (0 < dataElements1.Count)
                    {
                        paraVal = dataElements1[0];
                    }
                }
                else
                {
                    if (null != method.paraList[0].ParaValue)
                    {
                        paraVal = (DataEntity <DataElement>)method.paraList[0].ParaValue;
                    }
                }

                if (null == paraVal)
                {
                    paraVal = new DataEntity <DataElement>();
                }
                DataEntity <DataElement> dataElements = (DataEntity <DataElement>)paraVal;
                foreach (DataElement item in dataElements)
                {
                    if (!string.IsNullOrEmpty(item.fieldNameOfSourceTable))
                    {
                        continue;
                    }
                    fn = item.name.ToLower();
                    action(item.name, fn_2, fn);
                }
            }
            else if (null != dataType.GetInterface("IDictionary"))
            {
                //
            }
            else
            {
                Type t = dataType;
                if (typeof(Collections.IEnumerable) == dataType.GetInterface("IEnumerable"))
                {
                    Type[] types = dataType.GetGenericArguments();
                    if (null != dataType.GetInterface("IList"))
                    {
                        t = types[0];
                    }
                    else if (dataType.IsArray)
                    {
                        t = dataType.GetElementType();
                    }
                }
                PropertyInfo[] piArr = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                foreach (PropertyInfo item in piArr)
                {
                    fn_2 = FieldMapping.GetFieldMapping(item);
                    fn   = item.Name.ToLower();
                    action(item.Name, fn_2, fn);
                }
            }

            if (!string.IsNullOrEmpty(insertFields1))
            {
                insertFields1 = insertFields1.Substring(1);
                insertParas1  = insertParas1.Substring(1);
                updateSets1   = updateSets1.Substring(1);
                procParas1    = procParas1.Substring(1);
            }

            insertFields = insertFields1;
            insertParas  = insertParas1;
            updateSets   = updateSets1;
            procParas    = procParas1;
        }