private void RecursiveCreate(StringBuilder builder, SysObject @object) { if (isGenerated[@object.object_id]) { return; } else if (dbDependencies.ContainsKey(@object.object_id)) { var dependencies = dbDependencies[@object.object_id].Select(id => { var type = sourceTypes[id]; if (type == SQLTypes.InlineTableFunction.Description()) { return(sourceFuncs[id]); } else if (type == SQLTypes.View.Description()) { return(sourceViews[id]); } else if (type == SQLTypes.StoredProcedure.Description()) { return(sourceProcs[id]); } return(null); // should not get here }); foreach (var dep in dependencies) { RecursiveCreate(builder, dep); } } CreateByType(builder, @object); isGenerated[@object.object_id] = true; }
private static Type GetObjectTrueType(ISysObjectManager mgr, SysObject obj) { var type = CustomProperty.DefaultType; if (obj.ObjectDataType.HasValue) { type = mgr.GetTypeBySysObjectId(obj.ObjectDataType.Value); } if (type == null) { throw new DeveloperException( string.Format( "Для свойства '{0}' объекта '{1}' не удалось определить тип данных '{2}'. Проверьте создан ли объект с данным типом.", obj.ObjectName, obj.ObjectEntityCode, obj.ObjectDataType)); } // если перед нами коллекция - "ну что ж, приступим ..." if (obj.ObjectRelationship == Relationship.Many) { type = typeof(WMSBusinessCollection <>).MakeGenericType(type); } else { // Если не указано значение по умолчанию - значит может быть и null if (obj.ObjectDefaultValue == null) { type = type.GetNullAssignableType(); } } return(type); }
public bool addObject(List <roleSysObject> roleObjects, List <SysObject> sysObjs, int roleId) { bool result = true; using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlTransaction tan = conn.BeginTransaction(); SqlCommand objCommand = conn.CreateCommand(); objCommand.Transaction = tan; try { int i; string sql; string deleteRoleObj = string.Format("delete role_sys_form where role_Id=" + roleId, new object[0]); objCommand.CommandText = deleteRoleObj; objCommand.ExecuteNonQuery(); string deleteObjcts = string.Format("delete sys_object where roleId=" + roleId, new object[0]); objCommand.CommandText = deleteObjcts; objCommand.ExecuteNonQuery(); for (i = 0; i < sysObjs.Count; i++) { SysObject sysObj = sysObjs[i]; string maxId = "select max(AutoID) from sys_Object"; int id = 1; try { objCommand.CommandText = maxId; objCommand.ExecuteNonQuery(); id = 1 + ((int)objCommand.ExecuteScalar()); } catch (Exception) { } sql = string.Format("insert into sys_Object values({6},{0},'{1}','{2}','{3}','{4}',{5})", new object[] { sysObj.FromId, sysObj.TxtName, sysObj.Name, "Enabled", "false", roleId, id }); objCommand.CommandText = sql; objCommand.ExecuteNonQuery(); } for (i = 0; i < roleObjects.Count; i++) { sql = string.Format("insert into role_sys_form values({0},{1})", roleId, roleObjects[i]._SysObject.FromId); objCommand.CommandText = sql; objCommand.ExecuteNonQuery(); } tan.Commit(); conn.Close(); } catch (Exception) { tan.Rollback(); result = true; } } return(result); }
private static string CreateObjectDefinition(SysObject @object) { return(string.Join("\n", new string[] { $"IF (OBJECT_ID('{@object.qualified_name}') IS NOT NULL)", "\tSET NOEXEC ON", "GO\n", @object.object_definition, "GO\n", "SET NOEXEC OFF", BatchSeperator })); }
public bool addObject(SysObject sysObj) { string maxId = "select max(AutoID) from sys_Object"; int id = 1; try { id = 1 + ((int)DBHelp.ExeScalar(maxId)); } catch (Exception) { } return(DBHelp.ExeCommand(string.Format("insert into sys_Object values({6},{0},'{1}','{2}','{3}','{4}',{5})", new object[] { sysObj.From.FormID, sysObj.TxtName, sysObj.Name, sysObj.ObjctPro, sysObj.ObjProValue, sysObj.SysRole.RID, id }))); }
private static string AlterObject(SysObject @object) { var pattern = $@"CREATE(\s+\w+\s+(?:\[?{@object.schema_name}\]?)?\.?\[?{@object.name}\]?)"; var definition = Regex.Replace(@object.object_definition, pattern, "ALTER$1", RegexOptions.IgnoreCase); return(string.Join("\n", new string[] { $"IF EXISTS (SELECT object_id FROM sys.objects WHERE object_id = OBJECT_ID('{@object.qualified_name}')" + $" AND modify_date {([email protected]_date.HasValue? "IS NULL": $"> {DateTimeFromParts(@object.modify_date.Value)}")})", "\tSET NOEXEC ON", "GO\n", definition, "GO\n", "SET NOEXEC OFF", BatchSeperator })); }
protected void btnSave_Click(object sender, EventArgs e) { if (this.ddlRoles.SelectedItem != null) { int role = Convert.ToInt32(this.ddlRoles.SelectedItem.Value); List <roleSysObject> roleObjects = new List <roleSysObject>(); List <SysObject> sysobjs = new List <SysObject>(); for (int i = 0; i < this.TreeView1.Nodes.Count; i++) { TreeNodeCollection secondNodeColl = this.TreeView1.Nodes[i].ChildNodes; for (int j = 0; j < secondNodeColl.Count; j++) { TreeNode second = secondNodeColl[j]; if (second.Checked) { roleSysObject roleObj = new roleSysObject(); roleObj.Role.RID = role; roleObj._SysObject.FromId = Convert.ToInt32(second.Value); roleObjects.Add(roleObj); } TreeNodeCollection ThiNodeColl = second.ChildNodes; for (int k = 0; k < ThiNodeColl.Count; k++) { TreeNode third = ThiNodeColl[k]; if (!third.Checked) { SysObject sysobj = new SysObject(); sysobj.FromId = Convert.ToInt32(second.Value); sysobj.TxtName = third.Text; sysobj.Name = Convert.ToString(third.Value); sysobjs.Add(sysobj); } } } } SysObjectService objsMan = new SysObjectService(); if (objsMan.addObject(roleObjects, sysobjs, role)) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, base.GetType(), "click", "alert('保存成功')", true); } else { ScriptManager.RegisterStartupScript(this.UpdatePanel1, base.GetType(), "click", "alert('保存失败')", true); } } }
public List <SysObject> getObjects(string roleStr, SysObject sysObj) { int count = roleStr.Split(new char[] { ',' }).Length; List <SysObject> sysObjs = new List <SysObject>(); DataTable dt = DBHelp.getDataTable(string.Format("select [FormID] ,[TextName],[Name],[ObjectPro],[objectProVal] from sys_object where formID={0} and roleId in ({1})\r\ngroup by [FormID] ,[TextName],[Name],[ObjectPro],[objectProVal] having count(*)={2}", sysObj.From.FormID, roleStr, count)); foreach (DataRow dr in dt.Rows) { SysObject obj = new SysObject(); obj.Name = dr["Name"].ToString(); obj.ObjctPro = dr["ObjectPro"].ToString(); obj.ObjProValue = dr["objectProVal"].ToString(); int formId = Convert.ToInt32(dr["FormID"]); obj.From = new sysFormService().getFormsByFormId(formId); obj.TxtName = dr["TextName"].ToString(); sysObjs.Add(obj); } return(sysObjs); }
public SysObject checkIfExist(SysObject sysObj) { SysObject obj = null; DataTable dt = DBHelp.getDataTable(string.Format("select * from sys_Object where FormId={0} and name='{1}' and objectPro='{2}' and roleId={3}", new object[] { sysObj.From.FormID, sysObj.Name, sysObj.ObjctPro, sysObj.SysRole.RID })); foreach (DataRow dr in dt.Rows) { obj = new SysObject(); obj.Obj_ID = Convert.ToInt32(dr["AutoID"]); obj.Name = dr["Name"].ToString(); obj.ObjctPro = dr["ObjectPro"].ToString(); obj.ObjProValue = dr["objectProVal"].ToString(); int formId = Convert.ToInt32(dr["FormID"]); obj.From = new sysFormService().getFormsByFormId(formId); int roleId = Convert.ToInt32(dr["roleId"]); obj.TxtName = dr["TextName"].ToString(); obj.SysRole = new RoleService().getRoleById(roleId); } return(obj); }
private void CreateByType(StringBuilder builder, SysObject @object) { string query = null; if (@object.type == SQLTypes.InlineTableFunction.Description()) { query = Query.CreateFunction(@object); } else if (@object.type == SQLTypes.View.Description()) { query = Query.CreateView(@object); } else if (@object.type == SQLTypes.StoredProcedure.Description()) { query = Query.CreateProc(@object); } if (query != null) { builder.Append(query); } }
public List <SysObject> getSomeObjects(string assemblyPath, int roleID) { List <SysObject> sysObjs = new List <SysObject>(); string sql = string.Format("select Name from sys_Object where formID in(select formId from sys_form where assemblyPath='{0}') and roleId={1}", assemblyPath, roleID); using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlCommand objCommand = new SqlCommand(sql, conn); using (SqlDataReader objReader = objCommand.ExecuteReader()) { while (objReader.Read()) { SysObject obj = new SysObject(); obj.Name = objReader[0].ToString(); sysObjs.Add(obj); } objReader.Close(); } } return(sysObjs); }
public List <SysObject> getSomeObjects(int roleID) { List <SysObject> sysObjs = new List <SysObject>(); string sql = string.Format("select Name,formId from sys_Object where roleId={0}", roleID); using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlCommand objCommand = new SqlCommand(sql, conn); using (SqlDataReader objReader = objCommand.ExecuteReader()) { while (objReader.Read()) { SysObject obj = new SysObject(); obj.Name = objReader[0].ToString(); obj.FromId = Convert.ToInt32(objReader[1]); sysObjs.Add(obj); } objReader.Close(); } } return(sysObjs); }
public void SetPrice(OrderLine orderLine) { try { if (orderLine == null) { return; } Product prod = Products.FirstOrDefault(p => p.Id == orderLine.ProductId); Catalog catalog = Catalogs.FirstOrDefault(c => c.Id == prod.CatalogId); if (prod == null || catalog == null) { return; } if (string.IsNullOrWhiteSpace(orderLine.Description)) { orderLine.Description = prod.Name; } // if the orderline has a custom price, then we will NOT re-evaluate it if (!orderLine.IsCustomPrice) { decimal price = 0; // price component 1: sales price defined on product price = prod.SalesPrice; // price component 2: prices of all the selected option values if (orderLine.OrderLineOptions != null && orderLine.OrderLineOptions.Count > 0) { foreach (OrderLineOption olo in orderLine.OrderLineOptions.Where(olo => !string.IsNullOrWhiteSpace(olo.ProductOptionValueId))) { ProductOptionValue productOptionValue = cache.GetProductOptionValue(olo.ProductOptionValueId); if (productOptionValue != null) { price += productOptionValue.Price; } } } // price component 3: if there is a formula defined, add the result to the price if (!string.IsNullOrWhiteSpace(prod.SalesPriceFormulaInternal)) { CalculationSvc calcSvc = new CalculationSvc(); decimal formulaPrice = calcSvc.Calculate(prod.SalesPriceFormulaInternal, orderLine); price += formulaPrice; } orderLine.UnitPrice = price; } orderLine.TotalPrice = Math.Round(orderLine.UnitPrice * orderLine.Quantity, 2); string taxClassId = null; if (prod.SalesTaxClassId != null) { taxClassId = prod.SalesTaxClassId; } else { taxClassId = catalog.DefaultSalesTaxClassId; } orderLine.TaxPctg = 0; if (taxClassId != null) { SysObject taxClass = TaxClasses.FirstOrDefault(so => so.Id == taxClassId); if (taxClass != null && taxClass.Value.HasValue) { orderLine.TaxPctg = taxClass.Value.Value; } } orderLine.Tax = Math.Round(orderLine.CalculateTotalTax(), 2); } catch (Exception ex) { _Logger.Error(ex.ToString()); throw; } }
private static Attribute[] GetAttributes(SysObject sysObject, Type type) { var attributes = new List <Attribute>(); // определяем первичный ключ if (sysObject.ObjectPK) { attributes.Add(new PrimaryKeyAttribute()); } if (typeof(Working) == type && sysObject.ObjectDataType.HasValue) { if (sysObject.ObjectName == "WORKINGTILL" || sysObject.ObjectName == "WORKINGFROM") { attributes.Add(new DbTypeAttribute(DbTypeAttribute.DbTypeCustom.TimeStamp)); } } // если поле виртуальное - ничего читать, передавать не нужно if (string.IsNullOrEmpty(sysObject.ObjectDBName)) { attributes.Add(new XmlIgnoreAttribute()); } else { // для остальных полей - добавляем стандартные аттрибуты чтения/записи attributes.Add(new SourceNameAttribute(sysObject.ObjectDBName)); attributes.Add(new XmlElementAttribute(sysObject.ObjectDBName)); } // Заполняем LookUP if (sysObject.ObjectLookupCode_r != null) { attributes.Add(new LookupAttribute(sysObject.ObjectLookupCode_r, sysObject.ObjectFieldKeyLink)); } if (sysObject.ObjectExt != null) { foreach (var objectExt in sysObject.ObjectExt) { if (string.IsNullOrEmpty(objectExt.AttrName)) { throw new DeveloperException("Attribute name can't be null or empty."); } // ищем зарегистрированные стратегии var strategies = _processAttributeStrategies .Where(i => i.AttributeName.EqIgnoreCase(objectExt.AttrName)) .ToArray(); if (UnknownAttibuteThrowExceptionMode && strategies.Length == 0) { throw new DeveloperException("Can't find stategy for attribute with name '{0}'.", objectExt.AttrName); } // применяем foreach (var strategy in strategies) { if (strategy.Processor != null) { strategy.Processor(attributes, objectExt.AttrValue); } } } } // добавляем атрибут, ограничивающий длину поля if (sysObject.ObjectFieldLength != null) { attributes.Add(new MaxLengthAttribute((int)sysObject.ObjectFieldLength)); } return(attributes.ToArray()); }
public static string AlterProc(SysObject proc) { return(AlterObject(proc)); }
public static string AlterView(SysObject view) { return(AlterObject(view)); }
public static string AlterFunc(SysObject func) { return(AlterObject(func)); }
public static string CreateProc(SysObject proc) { return(CreateObjectDefinition(proc)); }
public static string CreateView(SysObject view) { return(CreateObjectDefinition(view)); }
public static string CreateFunction(SysObject func) { return(CreateObjectDefinition(func)); }
public void setTabPage(int selectedIndex) { this.formIndexs = new Dictionary <int, List <SysForm> >(); this.TreeView1.Nodes.Clear(); sysMenuService menuMan = new sysMenuService(); List <SysObject> sysobjects = new SysObjectService().getSomeObjects(selectedIndex); List <SysMenu> sysMenus = menuMan.getAllSysMenus(); sysFormService form1 = new sysFormService(); List <AllObjs> allobjs = new AllObjsService().getAllobjs(); List <SysForm> sysForms = form1.getAllForms_1(); foreach (SysMenu sysm in sysMenus) { int i; TreeNode fristNode = new TreeNode(sysm.DisplayName); SysForm form = new SysForm(); form.UpperID = sysm.MenuID; List <SysForm> currentForms = sysForms.FindAll(new Predicate <SysForm>(form.getForms)); this.formIndexs.Add(sysm.MenuIndex, currentForms); currentForms.Sort(delegate(SysForm from1, SysForm form2) { return(from1.FormIndex.CompareTo(form2.FormIndex)); }); foreach (SysForm currentForm in currentForms) { TreeNode secondNode = new TreeNode(currentForm.DisplayName); secondNode.Value = currentForm.FormID.ToString(); fristNode.ChildNodes.Add(secondNode); AllObjs all = new AllObjs(); all.FormId = currentForm.FormID; List <AllObjs> currentObjs = allobjs.FindAll(new Predicate <AllObjs>(all.getForms)); i = 0; while (i < currentObjs.Count) { TreeNode tiridNode = new TreeNode(currentObjs[i].Chinese); tiridNode.Value = currentObjs[i].English; SysObject oo = new SysObject(); oo.FromId = currentForm.FormID; List <SysObject> someObjs = sysobjects.FindAll(new Predicate <SysObject>(oo.getSomeObjct)); tiridNode.Checked = this.getEnable(someObjs, currentObjs[i].English); secondNode.ChildNodes.Add(tiridNode); i++; } } List <roleSysform> rsf = new roleSysFormService().getRightsByRoleId_1(selectedIndex); for (int j = 0; j < rsf.Count; j++) { for (i = 0; i < fristNode.ChildNodes.Count; i++) { int formId = Convert.ToInt32(fristNode.ChildNodes[i].Value); try { if (formId == rsf[j].Sysform.FormID) { fristNode.ChildNodes[i].Checked = true; fristNode.Checked = true; } } catch (Exception) { } } } this.TreeView1.Nodes.Add(fristNode); } }
public bool modifyObject(SysObject sysObj) { return(DBHelp.ExeCommand(string.Format("update sys_Object set objectProVal='{0}' where autoId={1}", sysObj.ObjProValue, sysObj.Obj_ID))); }