Esempio n. 1
0
 public MyResponseBase()
 {
     searchType = 0;
     Item = new SoftProjectAreaEntity();
     Items = new List<SoftProjectAreaEntity>();
     RespAttachInfo = new RespAttachInfo();
     PageQueryBase = new PageQueryBase();
     Querys = new Querys();
 }
 /// <summary>
 /// 构造函数
 /// </summary>
 public SoftProjectAreaEntityDomain()
 {
     //排序
     RAInfo = new RespAttachInfo();
     //分页信息
     PageQueryBase = new PageQueryBase();
     //查询条件信息
     _Querys = new Querys();
     //单个实体初始化
     this.Item = new SoftProjectAreaEntity();
     //实体集合初始化
     this.Items = new List<SoftProjectAreaEntity>();
 }
        /// <summary>
        /// 新:查询条件位置:由参数确定
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="Querys"></param>
        /// <param name="ModularOrFunCode"></param>
        /// <returns></returns>
        public static MvcHtmlString QueryHtml(this HtmlHelper helper, Querys Querys, string ModularOrFunCode, SoftProjectAreaEntity data)// MyResponseBase model)// Querys Querys)
        {
            //var ModularOrFunCode = "";
            //var Querys = model.Querys;
            StringBuilder sbQuery = new StringBuilder();
            //基础类
            var conts = helper.ViewContext.Controller as BaseController;
            var modulars = conts.Design_ModularOrFun;// ProjectCache.Design_ModularOrFuns.Where(p => p.ModularOrFunCode == ModularOrFunCode && p.ActionMethod == conts.ActionName).FirstOrDefault();

            var QueryFields = QueryFormEleTypes(modulars);

            #region 快速、高级查询

            var fastQueryFields = QueryFields.Where(p => p.QueryPos == 1).ToList();
            var advQueryFields = QueryFields.Where(p => p.QueryPos == 2).ToList();
            if (QueryFields.Count == 0)
                return new MvcHtmlString(sbQuery.ToString());

            sbQuery.AppendLine("<div class='fastWhere'>");
            for (int i = 0; i < fastQueryFields.Count(); i++)
            {
                var item = fastQueryFields[i];
                var strDrop = "";
                if (item.FormEleType == 4)
                {
                    strDrop = QueryHtmlDropDownList(helper, Querys, data, item, strDrop);
                }
                else if (item.FormEleType == 128)
                {
                    strDrop = QueryHtmlDropTree(Querys, data, item, strDrop);
                }
                else if (item.FormEleType == 8192)//下拉复选框(位)
                {
                    #region 下拉复选框
                    var val = Querys.GetValue(item.name + "___bitand");//位与

                    if (ProjectCache.IsExistyCategory(item.name))
                    {
                        //NameCn	"状态"	string
                        //var str = HtmlHelpers.DropDownList(helper, item.name + "___bitand", ProjectCache.GetByCategory(item.name),          "DValue", "DText", val, "", "==" + item.NameCn + "==");
                        var str = HtmlHelpers.DropDownListMultiSelect(helper, item.name + "___bitand", ProjectCache.GetByCategory(item.name), "DValue", "DText", val, "");

                        //sbHtml.AppendLine(str.ToString());
                        strDrop = str.ToString();
                    }
                    #endregion
                }

                //56:整数   106:小数    167:字符串   61:日期
                #region 快速查询
                if (strDrop.Length > 0)
                {
                    sbQuery.AppendLine(strDrop);
                }
                else
                {
                    if (item.FormEleType == 8)
                    {
                        var val = Querys.GetValue(item.name + "___equal");
                        sbQuery.AppendLine("<input type='hidden' class='form-control' id='" + item.name + "___equal' name='" + item.name + "___equal'  placeholder='" + item.NameCn + "' "
                            + " data-datatype='int' value='" + val + "' />");
                        continue;
                    }
                    #region 文本框绘制
                    var classcss = "";
                    var datatype = "int";
                    if (item.xtype == 106)
                    {
                        datatype = "decimal";
                    }
                    else if (item.xtype == 167)
                    {
                        datatype = "string";
                    }
                    if (item.xtype == 61)
                    {
                        datatype = "date";
                        classcss = "datepicker";
                    }

                    if (item.QueryType == 1)
                    {
                        var val = Querys.GetValue(item.name + "___like");
                        sbQuery.AppendLine("<input type='text' class='form-control " + classcss + "' id='" + item.name + "___like' name='" + item.name + "___like'  placeholder='" + item.NameCn + "' "
                            + " data-datatype='" + datatype + "' value='" + val + "' />");
                    }
                    else if (item.QueryType == 2)
                    {
                        var val = Querys.GetValue(item.name + "___equal");
                        sbQuery.AppendLine("<input type='text' class='form-control " + classcss + "' id='" + item.name + "___equal' name='" + item.name + "___equal'  placeholder='" + item.NameCn + "' "
                            + " data-datatype='" + datatype + "' value='" + val + "' />");
                    }
                    else if (item.QueryType == 3 || item.QueryType == null)
                    {
                        var val1 = Querys.GetValue(item.name + "___greaterequal");
                        var val2 = Querys.GetValue(item.name + "___lessequal");
                        sbQuery.AppendLine("<input type='text' class=' form-control " + classcss + "' id='" + item.name + "___greaterequal' name='" + item.name + "___greaterequal'  placeholder='起始" + item.NameCn + "' data-datatype='" + datatype + "' data-fieldnamecn='起始" + item.NameCn + "' value='" + val1 + "' />");
                        sbQuery.AppendLine("<input type='text' class=' form-control " + classcss + "' id='" + item.name + "___lessequal' name='" + item.name + "___lessequal'  placeholder='结束" + item.NameCn + "' data-datatype='" + datatype + "' data-fieldnamecn='结束" + item.NameCn + "' value='" + val2 + "' />");
                    }
                    #endregion
                }
                #endregion

            #endregion
            }
            var hiddcount = fastQueryFields.Where(p => p.FormEleType == 8).Count();
            if (hiddcount < fastQueryFields.Count())
            {
                sbQuery.AppendLine(string.Format("<button class='btn btn-primary btn-FwSearch' data-searchmethod='{0}' data-url='{1}' data-targetdom='{2}'><span class='glyphicon glyphicon-search'></span>查询</button>", modulars.SearchMethod, modulars.ActionPath, ".targetdom"));
                if (advQueryFields.Count > 0)
                {
                    sbQuery.AppendLine("<button class='btn btn-primary btn-AdvSearch' id='advSearch' data-module='advSearchArea' data-parents='SearchArea' >");
                    sbQuery.AppendLine("<span class='glyphicon glyphicon-search'></span>高级查询</button>");
                }
            }
            sbQuery.AppendLine("</div>");

        #endregion

            #region 高级查询

            if (advQueryFields.Count > 0)
            {
                sbQuery.AppendLine("<div style=\"width: 700px; display: none; background-color: rgb(255, 255, 255); box-shadow: 3px 1px 24px rgb(136, 136, 136); padding: 10px; z-index: 9999;position:'absolute'; right: 30px;\"");
                sbQuery.AppendLine("    class='SearchAreaDetail' id='advSearchArea' >");
                sbQuery.AppendLine("    <a style='top: 5px; right: 10px; position: absolute; cursor: pointer;' id='module_close'><i class='glyphicon glyphicon-remove'></i></a>");
                sbQuery.AppendLine("    <div class='moreWhere'>");
                sbQuery.AppendLine("        <ul style='margin-bottom: 0px; margin-top: 10px; list-style: outside none none;' class='container-fluid'>");

                for (var i = 0; i < advQueryFields.Count; i++)
                {
                    var item = advQueryFields[i];
                    var strDrop = "";
                    if (item.FormEleType == 4)
                    {
                        strDrop = QueryHtmlDropDownList(helper, Querys, data, item, strDrop);
                    }
                    else if (item.FormEleType == 128)
                    {
                        strDrop = QueryHtmlDropTree(Querys, data, item, strDrop);
                    }
                    else if (item.FormEleType == 8192)//下拉复选框(位)
                    {
                        #region 下拉复选框
                        var val = Querys.GetValue(item.name + "___bitand");//位与
                        if (ProjectCache.IsExistyCategory(item.name))
                        {
                            //NameCn	"状态"	string
                            //var str = HtmlHelpers.DropDownList(helper, item.name + "___bitand", ProjectCache.GetByCategory(item.name),          "DValue", "DText", val, "", "==" + item.NameCn + "==");
                            var str = HtmlHelpers.DropDownListMultiSelect(helper, item.name + "___bitand", ProjectCache.GetByCategory(item.name), "DValue", "DText", val, "");

                            //sbHtml.AppendLine(str.ToString());
                            strDrop = str.ToString();
                        }
                        #endregion
                    }
                    //56:整数   106:小数    167:字符串   61:日期
                    #region 查询条件
                    if (strDrop.Length > 0)
                    {
                        sbQuery.AppendLine("<li class='col-sm-4 text-left'>");
                        sbQuery.AppendLine(strDrop);
                        sbQuery.AppendLine("</li>");
                    }
                    #region 绘制文本框
                    var classcss = "";
                    var datatype = "int";
                    if (item.xtype == 106)
                    {
                        datatype = "decimal";
                    }
                    else if (item.xtype == 167)
                    {
                        datatype = "string";
                    }
                    if (item.xtype == 61)
                    {
                        datatype = "date";
                        classcss = "datepicker";
                    }

                    if (item.QueryType == 1)
                    {
                        var val = Querys.GetValue(item.name + "___like");
                        sbQuery.AppendLine("<li class='col-sm-4 text-left'>");
                        sbQuery.AppendLine("<input type='text' class='form-control " + classcss + "' id='" + item.name + "___like' name='" + item.name + "___like'  placeholder='" + item.NameCn + "' "
                            + " data-datatype='" + datatype + "' value='" + val + "' />");
                        sbQuery.AppendLine("</li>");
                    }
                    else if (item.QueryType == 2)
                    {
                        var val = Querys.GetValue(item.name + "___equal");
                        sbQuery.AppendLine("<li class='col-sm-4 text-left'>");
                        sbQuery.AppendLine("<input type='text' class='form-control " + classcss + "' id='" + item.name + "___like' name='" + item.name + "___like'  placeholder='" + item.NameCn + "' "
                            + " data-datatype='" + datatype + "' value='" + val + "' />");
                        sbQuery.AppendLine("</li>");
                    }
                    else if (item.QueryType == 3)
                    {
                        var val1 = Querys.GetValue(item.name + "___greaterequal");
                        var val2 = Querys.GetValue(item.name + "___lessequal");
                        sbQuery.AppendLine("<li class='col-sm-4 text-left'>");
                        sbQuery.AppendLine("<input type='text' class=' form-control " + classcss + "' id='" + item.name + "___greaterequal' name='" + item.name + "___greaterequal'  placeholder='起始" + item.NameCn + "' data-datatype='" + datatype + "' data-fieldnamecn='起始" + item.NameCn + "' value='" + val1 + "' />");
                        sbQuery.AppendLine("</li>");
                        sbQuery.AppendLine("<li class='col-sm-4 text-left'>");
                        sbQuery.AppendLine("<input type='text' class=' form-control " + classcss + "' id='" + item.name + "___lessequal' name='" + item.name + "___lessequal'  placeholder='结束" + item.NameCn + "' data-datatype='" + datatype + "' data-fieldnamecn='结束" + item.NameCn + "' value='" + val2 + "' />");
                        sbQuery.AppendLine("</li>");
                    }
                    #endregion
                    #endregion
                }

                sbQuery.AppendLine("<li class='col-sm-4 text-right pull-right'>");
                sbQuery.AppendLine(string.Format("<button class='btn btn-primary pull-righ btn-FwSearch'  data-searchmethod='{0}' data-url='{1}' data-targetdom='{2}'><span class='glyphicon glyphicon-search'></span>查询</button>", modulars.SearchMethod, modulars.ActionPath, ".targetdom"));
                //sbQuery.AppendLine(string.Format("<button class='btn btn-primary           btn-FwSearch'  data-searchmethod='{0}' data-url='{1}' data-targetdom='{2}'><span class='glyphicon glyphicon-search'></span>查询</button>", modulars.SearchMethod, modulars.ActionPath, ".targetdom"));
                sbQuery.AppendLine("</li>");
                sbQuery.AppendLine("   </ul>");
                sbQuery.AppendLine("  </div>");
                sbQuery.AppendLine("  </div>");
            }
            #endregion

            #region 自定义查询条件

            //if (Design_Modular.bCustWhere == 1)
            //{
            //    sbQuery.AppendLine("<div style='width: 100%;'>");
            //    sbQuery.AppendLine("   <table class='table table-bordered table-hover table-striped custWhere' id='tabsearch' style='width: 100%;'>");
            //    sbQuery.AppendLine("       <thead>");
            //    sbQuery.AppendLine("           <tr>");
            //    sbQuery.AppendLine("               <th style='width: 80px;'>操作</th>");
            //    sbQuery.AppendLine("               <th style='width: 50px;'>与/或</th>");
            //    sbQuery.AppendLine("               <th style='width: 100px;'>字段</th>");
            //    sbQuery.AppendLine("               <th style='width: 50px;'>运算符</th>");
            //    sbQuery.AppendLine("               <th style='width: 100px;'>值</th>");
            //    sbQuery.AppendLine("           </tr>");
            //    sbQuery.AppendLine("       </thead>");
            //    sbQuery.AppendLine("       <tbody>");
            //    if (Querys.Count == 0)
            //    {
            //        Querys.Add(new Query { });
            //    }
            //    for (var i = 0; i < Querys.Count; i++)
            //    {
            //        var query = Querys[i];
            //        sbQuery.AppendLine("               <tr>");
            //        sbQuery.AppendLine("                   <td class='align-left valign-middle '>");
            //        sbQuery.AppendLine("                       <a href='javascript:void(0);' class='btn btn-primary btn-xs btn-FwCopy'>复</a>");
            //        sbQuery.AppendLine("                       <a href='javascript:void(0);' class='btn btn-primary btn-xs btn-FwDeleteNotHint' style='display: none;'>删</a>");
            //        sbQuery.AppendLine("                   </td>");
            //        sbQuery.AppendLine("                   <td>");
            //        var strdrop = HtmlHelpers.DropDownList(helper, "Querys[{0}].AndOr", ProjectCache.AndOrs, "Value", "Text", query.Oper, "", "=与/或=", "form-control", "style='width:80px;'");
            //        sbQuery.AppendLine(strdrop.ToString());
            //        sbQuery.AppendLine("                   </td>");
            //        sbQuery.AppendLine("                   <td>");
            //        //strdrop=HtmlHelpers.DropDownList(helper,"Querys[{0}].FieldName", FieldNames, "Value", "Text",query.FieldName, "", "=字段=","form-control queryfieldname", " data-datatype='date' data-bdic='1'");
            //        //    sbQuery.AppendLine(strdrop.ToString());
            //        sbQuery.AppendLine("                   </td>");
            //        sbQuery.AppendLine("                   <td>");
            //        strdrop = HtmlHelpers.DropDownList(helper, "Querys[{0}].Oper", ProjectCache.QueryOpers, "Value", "Text", query.Oper, "", "=运算符=", "form-control", "style='width:90px;'");
            //        sbQuery.AppendLine(strdrop.ToString());
            //        sbQuery.AppendLine("                   </td>");
            //        sbQuery.AppendLine("                   <td class='targetdom align-left'>");
            //        sbQuery.AppendLine("                       <input type='text' style='width:100px;' class='form-control' name='Querys[{0}].Value' value='" + @query.Value + "' />");
            //        sbQuery.AppendLine("                   </td>");
            //        sbQuery.AppendLine("               </tr>");

            //    }
            //    sbQuery.AppendLine("       </tbody>");
            //    sbQuery.AppendLine("   </table>");
            //    sbQuery.AppendLine("</div>");
            //    sbQuery.AppendLine("<div class='margin-top-5'>");
            //    sbQuery.AppendLine("    <button class='btn btn-primary pull-righ btn-FwSearch'><span class='glyphicon glyphicon-search'></span>查询</button>");
            //    sbQuery.AppendLine("</div>");
            //}
            #endregion

            MvcHtmlString mstr = new MvcHtmlString(sbQuery.ToString());
            return mstr;
        }
        /// <summary>
        /// 查询条件--下拉树:2015-7-5
        /// </summary>
        /// <param name="Querys"></param>
        /// <param name="item"></param>
        /// <param name="strDrop"></param>
        /// <returns></returns>
        private static string QueryHtmlDropTree(Querys Querys,SoftProjectAreaEntity data, SoftProjectAreaEntity item, string strDrop)
        {
            var field = item;
            var val = Querys.GetValue(item.name + "___equal");

            if (ProjectCache.QueryHtmlDropTrees.ContainsKey(item.name))
            {
                strDrop = ProjectCache.QueryHtmlDropTrees[item.name](val, item.NameCn, data);
            }
            #region 原代码
            //if (field.name == "ParentOrganizationID" || field.name == "Pre_OrganizationID")
            //{
            //    #region 组织机构
            //    List<SoftProjectAreaEntity> Items = ProjectCache.Pre_Organizations;
            //    var tt = new SelectTreeList(Items, "0", "OrganizationName", "Pre_OrganizationID", "ParentOrganizationID", "Pre_OrganizationID", val, true, "");
            //    if (field.name == "ParentOrganizationID")
            //    {
            //        var str = HtmlHelpers.DropDownForTree(null, "ParentOrganizationID___equal", tt, "==组织机构==");
            //        //sbHtml.AppendLine(str.ToString());
            //        strDrop = str.ToString();
            //    }
            //    else
            //    {
            //        var str = HtmlHelpers.DropDownForTree(null, "Pre_OrganizationID___equal", tt, "==组织机构==");
            //        strDrop = str.ToString();
            //    }
            //    #endregion
            //}
            //else if (field.name == "ParentPreDoc_CategoryID" || field.name == "PreDoc_CategoryID")
            //{
            //    #region 公司文档类别
            //    List<SoftProjectAreaEntity> Items = ProjectCache.PreDoc_Categorys;
            //    var tt = new SelectTreeList(Items, "0", "PreDocCategoryName", "PreDoc_CategoryID", "ParentPreDoc_CategoryID", "PreDoc_CategoryID", val, true, "");
            //    if (field.name == "ParentPreDoc_CategoryID")
            //    {
            //        var str = HtmlHelpers.DropDownForTree(null, "ParentPreDoc_CategoryID___equal", tt, "==文档类别==");
            //        //sbHtml.AppendLine(str.ToString());
            //        strDrop = str.ToString();
            //    }
            //    else
            //    {
            //        var str = HtmlHelpers.DropDownForTree(null, "PreDoc_CategoryID___equal", tt, "==文档类别==");
            //        //sbHtml.AppendLine(str.ToString());
            //        strDrop = str.ToString();
            //    }
            //    #endregion
            //}
            //else if (field.name == "ParentCompDoc_CategoryID" || field.name == "CompDoc_CategoryID")
            //{
            //    #region 企业文档类别
            //    List<SoftProjectAreaEntity> Items = ProjectCache.CompDoc_Categorys;
            //    var tt = new SelectTreeList(Items, "0", "DocCategoryName", "CompDoc_CategoryID", "ParentCompDoc_CategoryID", "CompDoc_CategoryID", val, true, "");
            //    if (field.name == "ParentCompDoc_CategoryID")
            //    {
            //        var str = HtmlHelpers.DropDownForTree(null, "ParentCompDoc_CategoryID___equal", tt, "==文档类别==");
            //        strDrop = str.ToString();
            //    }
            //    else
            //    {
            //        var str = HtmlHelpers.DropDownForTree(null, "CompDoc_CategoryID___equal", tt, "==文档类别==");
            //        strDrop = str.ToString();
            //    }
            //    #endregion
            //}

            #endregion
            return strDrop;
        }
        /// <summary>
        /// 查询的下拉列表框:1015-7-5
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="Querys"></param>
        /// <param name="item"></param>
        /// <param name="strDrop"></param>
        /// <returns></returns>
        private static string QueryHtmlDropDownList(HtmlHelper helper, Querys Querys,SoftProjectAreaEntity data, SoftProjectAreaEntity item, string strDrop)
        {
            #region 下拉列表框
            var val = Querys.GetValue(item.name + "___equal");

            var Dicts = item.name;
            if (!string.IsNullOrEmpty(item.Dicts))
            {
                Dicts = item.Dicts;
            }

            if (ProjectCache.IsExistyCategory(Dicts))
            {
                var str = HtmlHelpers.DropDownList(helper, item.name + "___equal", ProjectCache.GetByCategory(Dicts), "DValue", "DText", val, "", "==" + item.NameCn + "==");
                strDrop = str.ToString();
            }
            else
            {
                if (ProjectCache.QueryHtmlDropDownLists.ContainsKey(item.name))
                {
                    strDrop = ProjectCache.QueryHtmlDropDownLists[item.name](val, item.NameCn, data);
                }
            }
            //else if (item.name == "Pre_RoleID")
            //{
            //    var Pre_Roles = ProjectCache.Pre_Roles;
            //    var str = HtmlHelpers.DropDownList(helper, item.name + "___equal", Pre_Roles, "Pre_RoleID", "RoleName", val, "", "==" + item.NameCn + "==");

            //    //var str = HtmlHelpers.DropDownList(helper, "Item." + Item.name, Pre_Roles, "Pre_RoleID", "RoleName", val, "");
            //    //sbHtml.AppendLine(str.ToString());
            //    strDrop = str.ToString();
            //}
            //else if (item.name == "Comp_RoleID")
            //{
            //    var Pre_Roles = ProjectCache.Comp_Roles;
            //    var str = HtmlHelpers.DropDownList(helper, item.name + "___equal", Pre_Roles, "Comp_RoleID", "CompRoleName", val, "", "==" + item.NameCn + "==");

            //    //var str = HtmlHelpers.DropDownList(helper, "Item." + Item.name, Pre_Roles, "Pre_RoleID", "RoleName", val, "");
            //    //sbHtml.AppendLine(str.ToString());
            //    strDrop = str.ToString();
            //}

            #endregion
            return strDrop;
        }
Esempio n. 6
0
        public CodeToDataBaseMergeCollection GetDatabase_Diff(Type tableType, CodeToDataBaseMergeCollection str = null, List <Type> createdTables = null)
        {
            str           = str ?? new CodeToDataBaseMergeCollection(_repository);
            tableType     = tableType.GetActualType();
            createdTables = createdTables ?? new List <Type>();
            if (createdTables.Any(x => x == tableType) || tableType.GetPrimaryKey() == null)
            {
                return(str);
            }

            if (CodeToDataBaseMergeCollection.ExecutedData.ContainsKey(tableType.FullName + _repository.DataBaseTypes.ToString()))
            {
                return(str);
            }

            createdTables.Add(tableType);
            var table               = ObjectColumns(tableType);
            var tableName           = tableType.TableName();
            var props               = DeepCloner.GetFastDeepClonerProperties(tableType).Where(x => !x.ContainAttribute <ExcludeFromAbstract>());
            var codeToDataBaseMerge = new CodeToDataBaseMerge()
            {
                Object_Type = tableType
            };
            var isPrimaryKey = "";

            if (!IsValidName(tableName))
            {
                throw new EntityException(tableName + " is not a valid Name for the current provider " + _repository.DataBaseTypes);
            }


            if (!table.Rows.Any())
            {
                codeToDataBaseMerge.Sql = new StringBuilder("CREATE TABLE " + (_repository.DataBaseTypes == DataBaseTypes.Mssql ? "[dbo]." : "") + _repository.DataBaseTypes.GetValidSqlName(tableName) + "(");
                foreach (var prop in props.Where(x => (x.GetDbTypeByType(_repository.DataBaseTypes) != null || !x.IsInternalType) && !x.ContainAttribute <ExcludeFromAbstract>()).GroupBy(x => x.Name).Select(x => x.First())
                         .OrderBy(x => x.ContainAttribute <PrimaryKey>() ? null : x.Name))
                {
                    if (!prop.IsInternalType)
                    {
                        if (!str.Any(x => x.Object_Type == prop.PropertyType.GetActualType()) && createdTables.All(x => x != prop.PropertyType.GetActualType()))
                        {
                            GetDatabase_Diff(prop.PropertyType, str, createdTables);
                        }
                        continue;
                    }

                    isPrimaryKey = prop.ContainAttribute <PrimaryKey>() ? prop.GetPropertyName() : isPrimaryKey;
                    var foreignKey = prop.GetCustomAttribute <ForeignKey>();
                    var dbType     = prop.GetDbTypeByType(_repository.DataBaseTypes);
                    var propName   = string.Format("[{0}]", prop.GetPropertyName());
                    codeToDataBaseMerge.Sql.Append(propName + " ");
                    if (!IsValidName(prop.GetPropertyName()))
                    {
                        throw new Exception(tableName + " is not a valid Name for the current provider " + _repository.DataBaseTypes);
                    }



                    if (!prop.ContainAttribute <PrimaryKey>() || _repository.DataBaseTypes == DataBaseTypes.Mssql)
                    {
                        codeToDataBaseMerge.Sql.Append(dbType + " ");
                    }


                    if (foreignKey != null && createdTables.All(x => x != foreignKey.Type))
                    {
                        GetDatabase_Diff(foreignKey.Type, str, createdTables);
                    }

                    if (prop.ContainAttribute <PrimaryKey>())
                    {
                        if (prop.PropertyType.IsNumeric() && prop.GetCustomAttribute <PrimaryKey>().AutoGenerate)
                        {
                            codeToDataBaseMerge.Sql.Append(_repository.DataBaseTypes == DataBaseTypes.Mssql ? "IDENTITY(1,1) NOT NULL," : (_repository.DataBaseTypes == DataBaseTypes.Sqllight ? " Integer PRIMARY KEY AUTOINCREMENT," : " BIGSERIAL PRIMARY KEY,"));
                        }
                        else
                        {
                            codeToDataBaseMerge.Sql.Append(_repository.DataBaseTypes == DataBaseTypes.Mssql ? "NOT NULL," : " " + dbType + "  PRIMARY KEY,");
                        }
                        continue;
                    }

                    if (foreignKey != null)
                    {
                        var key = propName + "-" + tableName;
                        if (!str.Keys.ContainsKey(key))
                        {
                            str.Keys.Add(key, new Tuple <string, ForeignKey>(tableName, foreignKey));
                        }
                    }

                    codeToDataBaseMerge.Sql.Append((Nullable.GetUnderlyingType(prop.PropertyType) != null || prop.PropertyType == typeof(string)) && !prop.ContainAttribute <NotNullable>() ? " NULL," : " NOT NULL,");
                }

                if (str.Keys.Any() && _repository.DataBaseTypes == DataBaseTypes.Sqllight)
                {
                    while (str.Keys.Any(x => x.Value.Item1 == tableName))
                    {
                        var key        = str.Keys.FirstOrDefault(x => x.Value.Item1 == tableName);
                        var type       = key.Value.Item2.Type.GetActualType();
                        var keyPrimary = type.GetPrimaryKey().GetPropertyName();
                        var tb         = type.TableName();
                        codeToDataBaseMerge.Sql.Append("FOREIGN KEY(" + key.Key.Split('-')[0] + ") REFERENCES " + tb + "(" + keyPrimary + "),");
                        str.Keys.Remove(key.Key);
                    }
                }

                if (!string.IsNullOrEmpty(isPrimaryKey) && _repository.DataBaseTypes == DataBaseTypes.Mssql)
                {
                    codeToDataBaseMerge.Sql.Append(" CONSTRAINT [PK_" + tableName + "] PRIMARY KEY CLUSTERED");
                    codeToDataBaseMerge.Sql.Append(" ([" + isPrimaryKey + "] ASC");
                    codeToDataBaseMerge.Sql.Append(")");
                    codeToDataBaseMerge.Sql.Append("WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");
                    codeToDataBaseMerge.Sql.Append(") ON [PRIMARY]");
                }
                else
                {
                    if (_repository.DataBaseTypes == DataBaseTypes.Sqllight)
                    {
                        codeToDataBaseMerge.Sql = new StringBuilder(codeToDataBaseMerge.Sql.ToString().TrimEnd(','));
                    }
                    codeToDataBaseMerge.Sql.Append(")");
                }

                str.Add(codeToDataBaseMerge);
            }
            else
            {
                foreach (var prop in props.Where(x => (x.GetDbTypeByType(_repository.DataBaseTypes) != null || !x.IsInternalType) && !x.ContainAttribute <ExcludeFromAbstract>()).GroupBy(x => x.Name).Select(x => x.First())
                         .OrderBy(x => x.ContainAttribute <PrimaryKey>() ? null : x.Name))
                {
                    if (prop.ContainAttribute <ForeignKey>())
                    {
                        GetDatabase_Diff(prop.GetCustomAttribute <ForeignKey>().Type, str, createdTables);
                    }
                    var propType = prop.PropertyType;
                    if (prop.ContainAttribute <Stringify>() || prop.ContainAttribute <DataEncode>() || prop.ContainAttribute <ToBase64String>())
                    {
                        propType = typeof(string);
                    }

                    var modify = prop.IsInternalType ? (_repository.DataBaseTypes == DataBaseTypes.PostgreSql ? table.FindByPrimaryKey <LightDataTableRow>(prop.GetPropertyName().ToLower()) : table.FindByPrimaryKey <LightDataTableRow>(prop.GetPropertyName())) : null;
                    if (modify != null)
                    {
                        if (_repository.DataBaseTypes != DataBaseTypes.Sqllight && !(prop.GetDbTypeListByType(_repository.DataBaseTypes).Any(x => x.ToLower().Contains(modify.Value <string>("data_type").ToLower()))) && _repository.DataBaseTypes != DataBaseTypes.PostgreSql)
                        {
                            codeToDataBaseMerge.Sql.Append($"\nALTER TABLE [{tableName}] ALTER COLUMN [{prop.GetPropertyName()}] {prop.GetDbTypeByType(_repository.DataBaseTypes)} {((Nullable.GetUnderlyingType(propType) != null || propType == typeof(string)) && !prop.ContainAttribute<NotNullable>() ? " NULL" : " NOT NULL")}");
                        }
                        else
                        {
                            if (!(prop.GetDbTypeListByType(_repository.DataBaseTypes).Any(x => x.ToLower().Contains(modify.Value <string>("data_type").ToLower()))) && _repository.DataBaseTypes == DataBaseTypes.PostgreSql)
                            {
                                codeToDataBaseMerge.Sql.Append($"\nALTER TABLE [{tableName}] ALTER COLUMN [{prop.GetPropertyName()}] TYPE {prop.GetDbTypeByType(_repository.DataBaseTypes)}, ALTER COLUMN [{prop.GetPropertyName()}] SET DEFAULT {Querys.GetValueByTypeSTRING(MethodHelper.ConvertValue(null, propType), _repository.DataBaseTypes)};");
                            }
                        }
                    }
                    else if (!prop.IsInternalType)
                    {
                        GetDatabase_Diff(prop.PropertyType, str, createdTables);
                    }
                    else
                    {
                        codeToDataBaseMerge.Sql.Append(string.Format("\nALTER TABLE [{0}] ADD " + (_repository.DataBaseTypes == DataBaseTypes.PostgreSql ? "COLUMN" : "") + " [{1}] {2} {3} DEFAULT {4};", tableName, prop.GetPropertyName(), prop.GetDbTypeByType(_repository.DataBaseTypes),
                                                                     (Nullable.GetUnderlyingType(propType) != null || propType == typeof(string)) && !prop.ContainAttribute <NotNullable>() ? " NULL" : " NOT NULL", Querys.GetValueByTypeSTRING(MethodHelper.ConvertValue(null, propType), _repository.DataBaseTypes)));
                    }
                }
            }

            var colRemove = new CodeToDataBaseMerge()
            {
                Object_Type = tableType
            };

            // Now lets clean the table and remove unused columns
            foreach (LightDataTableRow col in table.SelectMany <LightDataRowCollection>(x =>
                                                                                        !props.Any(a => string.Equals(x.Value <string>("column_name"), a.GetPropertyName(), StringComparison.CurrentCultureIgnoreCase) &&
                                                                                                   (a.GetDbTypeByType(_repository.DataBaseTypes) != null || !a.IsInternalType) &&
                                                                                                   !a.ContainAttribute <ExcludeFromAbstract>())))
            {
                if (_repository.DataBaseTypes != DataBaseTypes.Sqllight)
                {
                    if (_repository.DataBaseTypes == DataBaseTypes.Mssql)
                    {
                        colRemove.Sql.Append("IF EXISTS (SELECT name FROM sys.objects  WHERE name = 'datedflt' AND type = 'D') DROP DEFAULT datedflt;");
                    }
                    colRemove.Sql.Append(string.Format("\nALTER TABLE [{0}] DROP COLUMN [{1}];", tableName, col.Value <string>("column_name")));
                }
                else
                {
                    colRemove.Sql.Append(string.Format("DROP TABLE IF exists [{0}_temp];\nCREATE TABLE [{0}_temp] AS SELECT {1} FROM [{0}];", tableName, string.Join(",", table.SelectMany <LightDataRowCollection>(x =>
                                                                                                                                                                                                                    props.Any(a => string.Equals(x.Value <string>("column_name"), a.GetPropertyName(), StringComparison.CurrentCultureIgnoreCase) &&
                                                                                                                                                                                                                              (a.GetDbTypeByType(_repository.DataBaseTypes) != null || !a.IsInternalType) &&
                                                                                                                                                                                                                              !a.ContainAttribute <ExcludeFromAbstract>())).Select(x => x.Value <string>("column_name")))));
                    colRemove.Sql.Append(string.Format("DROP TABLE [{0}];\n", tableName));
                    colRemove.Sql.Append(string.Format("ALTER TABLE [{0}_temp] RENAME TO [{0}]; ", tableName));
                }
                colRemove.DataLoss = true;
            }
            str.Add(colRemove);

            foreach (var prop in props.Where(x => !x.IsInternalType && !x.ContainAttribute <ExcludeFromAbstract>()).GroupBy(x => x.Name).Select(x => x.First()))
            {
                var type = prop.PropertyType.GetActualType();
                if (type.GetPrimaryKey() != null)
                {
                    GetDatabase_Diff(type, str, createdTables);
                }
            }

            str.Add(codeToDataBaseMerge);
            return(str);
        }
Esempio n. 7
0
        private object Save(object o, bool isIndependentData, bool updateOnly = false)
        {
            try
            {
                GlobalConfiguration.Logg?.Info("Save", o);
                _repository.CreateTransaction();
                var props      = DeepCloner.GetFastDeepClonerProperties(o.GetType());
                var primaryKey = o.GetPrimaryKey();

                if (primaryKey == null)
                {
                    throw new EntityException("Object must have a PrimaryKey");
                }

                var primaryKeyId        = !Extension.ObjectIsNew(o.GetPrimaryKeyValue()) ? o.GetPrimaryKeyValue() : null;
                var availableColumns    = ObjectColumns(o.GetType());
                var objectRules         = o.GetType().GetCustomAttribute <Rule>();
                var tableName           = o.GetType().TableName();
                var primaryKeySubstitut = !primaryKey.GetCustomAttribute <PrimaryKey>().AutoGenerate ? primaryKeyId : null;

                object dbTrigger = null;
                if (objectRules != null && !CachedIDbRuleTrigger.ContainsKey(o.GetType()))
                {
                    dbTrigger = objectRules.RuleType.CreateInstance(true);
                    CachedIDbRuleTrigger.Add(o.GetType(), dbTrigger);
                }
                else if (objectRules != null || CachedIDbRuleTrigger.ContainsKey(o.GetType()))
                {
                    dbTrigger = CachedIDbRuleTrigger[o.GetType()];
                }

                if (primaryKeyId != null && !updateOnly) // lets attach the object
                {
                    var data = GetById(primaryKeyId, o.GetType());
                    if (data == null)
                    {
                        primaryKeyId = null;
                        o.SetPrimaryKeyValue();
                    }
                    else
                    {
                        if (!_repository.IsAttached(o))
                        {
                            _repository.Attach(data);
                        }

                        var changes = _repository.GetObjectChanges(o);
                        foreach (var item in props.Where(x => x.CanRead && !changes.Any(a => a.PropertyName == x.Name) && x.IsInternalType))
                        {
                            item.SetValue(o, item.GetValue(data));
                        }
                    }
                }

                if (!updateOnly)
                {
                    dbTrigger?.GetType().GetMethod("BeforeSave").Invoke(dbTrigger, new List <object>()
                    {
                        _repository, o
                    }.ToArray());                                                                                                    // Check the Rule before save
                }
                object tempPrimaryKey = null;
                var    sql            = "UPDATE [" + (o.GetType().TableName()) + "] SET ";
                var    cols           = props.FindAll(x => (availableColumns.FindByPrimaryKey <bool>(x.GetPropertyName()) || availableColumns.FindByPrimaryKey <bool>(x.GetPropertyName().ToLower())) && x.IsInternalType && !x.ContainAttribute <ExcludeFromAbstract>() && x.GetCustomAttribute <PrimaryKey>() == null);
                if (primaryKeyId == null)
                {
                    if (primaryKey.PropertyType.IsNumeric() && primaryKey.GetCustomAttribute <PrimaryKey>().AutoGenerate)
                    {
                        sql  = "INSERT INTO [" + tableName + "](" + string.Join(",", cols.Select(x => "[" + x.GetPropertyName() + "]")) + ") Values(";
                        sql += string.Join(",", cols.Select(x => "@" + x.GetPropertyName())) + ");";
                        sql += _repository.DataBaseTypes == DataBaseTypes.Sqllight ? " select last_insert_rowid();" : (_repository.DataBaseTypes != DataBaseTypes.PostgreSql ? " SELECT IDENT_CURRENT('" + tableName + "');" : " SELECT currval('" + string.Format("{0}_{1}_seq", tableName, primaryKey.GetPropertyName()) + "');");
                    }
                    else
                    {
                        var colList = new List <IFastDeepClonerProperty>();
                        tempPrimaryKey = primaryKeySubstitut == null?Guid.NewGuid() : primaryKeySubstitut;

                        if (primaryKeySubstitut == null && primaryKey.PropertyType.IsNumeric())
                        {
                            tempPrimaryKey = _repository.ExecuteScalar(_repository.GetSqlCommand(String.Format("SELECT MAX([{0}]) FROM [{1}]", primaryKey.GetPropertyName(), tableName))).ConvertValue <long>() + 1;
                        }
                        else if (primaryKey.PropertyType == typeof(string))
                        {
                            tempPrimaryKey = tempPrimaryKey.ToString();
                        }
                        colList.Insert(0, primaryKey);
                        colList.AddRange(cols);
                        sql  = "INSERT INTO [" + tableName + "](" + string.Join(",", colList.Select(x => "[" + x.GetPropertyName() + "]")) + ") Values(";
                        sql += string.Join(",", colList.Select(x => "@" + x.GetPropertyName())) + "); select '" + tempPrimaryKey + "'";
                    }
                }
                else
                {
                    sql += string.Join(",", cols.Select(x => "[" + x.GetPropertyName() + "]" + " = @" + x.GetPropertyName()));
                    sql += Querys.Where(_repository.DataBaseTypes).Column(o.GetType().GetActualType().GetPrimaryKey().GetPropertyName()).Equal(primaryKeyId).Execute();
                }

                var cmd = _repository.GetSqlCommand(sql);
                if ((!primaryKey.PropertyType.IsNumeric() || !primaryKey.GetCustomAttribute <PrimaryKey>().AutoGenerate) && primaryKeyId == null)
                {
                    _repository.AddInnerParameter(cmd, primaryKey.GetPropertyName(), tempPrimaryKey, _repository.GetSqlType(primaryKey.PropertyType));
                }


                foreach (var col in cols)
                {
                    var v = col.GetValue(o);
                    var defaultOnEmpty = col.GetCustomAttribute <DefaultOnEmpty>();
                    if (col.ContainAttribute <ForeignKey>() && (v?.ObjectIsNew() ?? true))
                    {
                        var ob              = props.FirstOrDefault(x => x.PropertyType == col.GetCustomAttribute <ForeignKey>().Type&& (string.IsNullOrEmpty(col.GetCustomAttribute <ForeignKey>().PropertyName) || col.GetCustomAttribute <ForeignKey>().PropertyName == x.Name));
                        var obValue         = ob?.GetValue(o);
                        var independentData = ob?.GetCustomAttribute <IndependentData>() != null;
                        if (obValue != null)
                        {
                            v = obValue.GetType().GetPrimaryKey().GetValue(obValue)?.ObjectIsNew() ?? true?
                                Save(obValue, independentData) :
                                    obValue.GetType().GetPrimaryKey().GetValue(obValue);

                            col.SetValue(o, v);
                        }
                    }

                    if (col.ContainAttribute <ToBase64String>())
                    {
                        if (!v?.ConvertValue <string>().IsBase64String() ?? false)
                        {
                            v = MethodHelper.EncodeStringToBase64(v.ConvertValue <string>());
                        }
                    }

                    if (col.ContainAttribute <Stringify>() || col.ContainAttribute <DataEncode>())
                    {
                        v = v?.ConvertValue <string>();
                    }

                    if (col.ContainAttribute <DataEncode>())
                    {
                        if (col.PropertyType != typeof(string))
                        {
                            throw new EntityException(string.Format("Property {0} Contain DataEncode. PropertyType must be of type String .", col.FullName));
                        }
                        v = new DataCipher(col.GetCustomAttribute <DataEncode>().Key, col.GetCustomAttribute <DataEncode>().KeySize).Encrypt(v.ToString());
                    }

                    if (col.ContainAttribute <NotNullable>() && v == null && defaultOnEmpty == null)
                    {
                        throw new EntityException(string.Format("Property {0} dose not allow null.", col.FullName));
                    }


                    if (v == null && defaultOnEmpty != null)
                    {
                        v = defaultOnEmpty.Value.ConvertValue(col.PropertyType);
                    }

                    _repository.AddInnerParameter(cmd, col.GetPropertyName(), v, (col.ContainAttribute <Stringify>() || col.ContainAttribute <DataEncode>() || col.ContainAttribute <ToBase64String>() ? _repository.GetSqlType(typeof(string)) : _repository.GetSqlType(col.PropertyType)));
                }

                if (primaryKeyId == null)
                {
                    primaryKeyId = _repository.ExecuteScalar(cmd).ConvertValue(primaryKey.PropertyType);
                }
                else
                {
                    _repository.ExecuteNonQuery(cmd);
                }
                var oState = dbTrigger != null?DeepCloner.Clone(o) : null;

                if (updateOnly)
                {
                    return(primaryKeyId);
                }
                dbTrigger?.GetType().GetMethod("AfterSave").Invoke(dbTrigger, new List <object>()
                {
                    _repository, o, primaryKeyId
                }.ToArray());                                                                                                                 // Check the Rule before save

                foreach (var prop in props.Where(x => !x.IsInternalType && !x.ContainAttribute <ExcludeFromAbstract>()))
                {
                    var independentData = prop.GetCustomAttribute <IndependentData>() != null;
                    var type            = prop.PropertyType.GetActualType();
                    var oValue          = prop.GetValue(o);
                    if (oValue == null)
                    {
                        continue;
                    }
                    var vList = oValue is IList ? (IList)oValue : new List <object>()
                    {
                        oValue
                    };

                    foreach (var item in vList)
                    {
                        var foreignKey = DeepCloner.GetFastDeepClonerProperties(item.GetType()).FirstOrDefault(x => x.GetCustomAttribute <ForeignKey>()?.Type == o.GetType() && string.IsNullOrEmpty(x.GetCustomAttribute <ForeignKey>().PropertyName));
                        foreignKey?.SetValue(item, primaryKeyId);
                        var res = Save(item, independentData);
                        foreignKey = props.FirstOrDefault(x => x.GetCustomAttribute <ForeignKey>()?.Type == type && (x.GetCustomAttribute <ForeignKey>().PropertyName == prop.Name || string.IsNullOrEmpty(x.GetCustomAttribute <ForeignKey>().PropertyName)));
                        if (foreignKey == null || !foreignKey.GetValue(o).ObjectIsNew())
                        {
                            continue;
                        }
                        if (o.GetType() == foreignKey.GetCustomAttribute <ForeignKey>().Type)
                        {
                            continue;
                        }
                        foreignKey.SetValue(o, res);
                    }
                }


                if (oState != null && _repository.GetObjectChanges(o, oState).Count > 0) // a change has been made outside the function Save then resave
                {
                    o.SetPrimaryKeyValue(primaryKeyId);
                    Save(o, false, true);
                }
                o.SetPrimaryKeyValue(primaryKeyId);
                _repository.Attach(o, true);
                return(primaryKeyId);
            }
            catch (Exception e)
            {
                GlobalConfiguration.Logg?.Error(e);
                _repository.Rollback();
                throw;
            }
        }
Esempio n. 8
0
        private List <string> DeleteAbstract(object o, bool save)
        {
            GlobalConfiguration.Logg?.Info("Delete", o);
            var type            = o.GetType().GetActualType();
            var props           = DeepCloner.GetFastDeepClonerProperties(type);
            var table           = "[" + (type.TableName()) + "]";
            var primaryKey      = o.GetType().GetPrimaryKey();
            var primaryKeyValue = o.GetPrimaryKeyValue();

            if (primaryKeyValue.ObjectIsNew())
            {
                return(new List <string>());
            }
            var sql = new List <string>()
            {
                "DELETE " + (_repository.DataBaseTypes == DataBaseTypes.Sqllight || _repository.DataBaseTypes == DataBaseTypes.PostgreSql ? "From " : "") +
                table +
                Querys.Where(_repository.DataBaseTypes).Column(primaryKey.GetPropertyName()).Equal(primaryKeyValue).Execute()
            };

            foreach (var prop in props.Where(x => !x.IsInternalType && x.GetCustomAttribute <IndependentData>() == null && x.GetCustomAttribute <ExcludeFromAbstract>() == null))
            {
                var value = prop.GetValue(o);

                if (value == null)
                {
                    continue;
                }
                var subSql       = new List <string>();
                var propType     = prop.PropertyType.GetActualType();
                var insertBefore = props.Any(x => x.GetCustomAttribute <ForeignKey>()?.Type == propType);
                if (DeepCloner.GetFastDeepClonerProperties(propType).All(x => x.GetCustomAttribute <ForeignKey>()?.Type != type))
                {
                    if (!insertBefore)
                    {
                        continue;
                    }
                }
                if (value is IList)
                {
                    foreach (var item in value as IList)
                    {
                        subSql.AddRange(DeleteAbstract(item, false));
                    }
                }
                else
                {
                    subSql.AddRange(DeleteAbstract(value, false));
                }

                if (insertBefore)
                {
                    sql.InsertRange(sql.Count - 1, subSql);
                }
                else
                {
                    sql.AddRange(subSql);
                }
            }

            if (!save)
            {
                return(sql);
            }
            try
            {
                _repository.CreateTransaction();

                var       i = sql.Count - 1;
                var       exceptionCount      = 0;
                Exception firstChanceExcepion = null;

                while (sql.Count > 0 && exceptionCount <= 10)
                {
                    try
                    {
                        if (i < 0)
                        {
                            i = sql.Count - 1;
                        }
                        var s   = sql[i];
                        var cmd = _repository.GetSqlCommand(s);
                        cmd.Command.ExecuteNonQuery();
                        sql.RemoveAt(i);
                        i--;
                    }
                    catch (Exception e)
                    {
                        firstChanceExcepion = e;
                        exceptionCount++;
                        i--;
                    }
                }

                if (exceptionCount >= 10)
                {
                    throw firstChanceExcepion;
                }
            }
            catch
            {
                _repository.Rollback();
                throw;
            }
            return(sql);
        }
Esempio n. 9
0
        /// <summary>
        /// DeSerilize Xml to IAnimal, this is supposed to handle all unknow object types but there has not been to many tests.
        /// Only IAnimal test been done here.
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public static T FromXml <T>(this string xml, Transaction.Transaction transaction)
        {
            if (string.IsNullOrEmpty(xml))
            {
                return((T)(new object()));
            }
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            var o = (T)FromXml(doc.DocumentElement);

            void LoadXmlIgnoreProperties(object item)
            {
                if (item is IList)
                {
                    foreach (var t in (IList)item)
                    {
                        LoadXmlIgnoreProperties(t);
                    }
                    return;
                }

                var type = item?.GetType().GetActualType();

                if (type == null)
                {
                    return;
                }
                if (!(item?.GetPrimaryKeyValue().ObjectIsNew() ?? true))
                {
                    var primaryId = item.GetPrimaryKeyValue();
                    foreach (var prop in DeepCloner.GetFastDeepClonerProperties(item.GetType()).Where(x => (x.ContainAttribute <XmlIgnore>() || !x.IsInternalType) && !x.ContainAttribute <ExcludeFromAbstract>() && x.CanRead))
                    {
                        var value = prop.GetValue(item);
                        if (prop.PropertyType == typeof(string) && string.IsNullOrEmpty(value?.ToString()))
                        {
                            value = string.Empty;
                        }
                        if (prop.IsInternalType && value == LightDataTableShared.ValueByType(prop.PropertyType)) // Value is default
                        {
                            var cmd  = transaction.GetSqlCommand($"SELECT [{prop.GetPropertyName()}] FROM [{type.TableName()}] WHERE [{item.GetPrimaryKey().GetPropertyName()}] = {Querys.GetValueByType(item.GetPrimaryKeyValue(), transaction.DataBaseTypes)}");
                            var data = transaction.ExecuteScalar(cmd);
                            if (data == null)
                            {
                                continue;
                            }
                            if (prop.ContainAttribute <DataEncode>())
                            {
                                data = new DataCipher(prop.GetCustomAttribute <DataEncode>().Key, prop.GetCustomAttribute <DataEncode>().KeySize).Decrypt(data.ToString());
                            }
                            else if (prop.ContainAttribute <ToBase64String>() && data.ToString().IsBase64String())
                            {
                                data = MethodHelper.DecodeStringFromBase64(data.ToString());
                            }

                            prop.SetValue(item, data.ConvertValue(prop.PropertyType));
                        }
                        else if (value != null)
                        {
                            LoadXmlIgnoreProperties(value);
                        }
                    }
                }
            }

            LoadXmlIgnoreProperties(o);
            return(o);
        }
 public static void DeleteFile(int FileID, string NetID)
 {
     Querys.DeleteQuery("Files", "NetID = " + NetID + " AND FileID = " + FileID);
 }
 public static void CleanNetFromFiles(string NetID)
 {
     Querys.DeleteQuery("Files", "NetID" + NetID);
 }
 public static void DeleteNet(string NetID)
 {
     CleanNetFromFiles(NetID);
     Querys.DeleteQuery("NETS", "NetID = " + NetID);
 }
 public static void UpdateNet(string NetID, Int64 TotalSize, Int64 NumberOfFiles)
 {
     Querys.UpdateQuery("NETS", "TotalSize = " + Convert.ToString(TotalSize) + ", NumberOfFiles = " + Convert.ToString(NumberOfFiles), "NetID = " + NetID);
 }
 public static void CreateNet(string NetID)
 {
     Querys.InsertQuery("NETS", "(NetID, TotalSize, NumberOfFiles)", "(" + NetID + ", 0, 0)");
 }