示例#1
0
        public ActionResult Execute(int number)
        {
            string id       = (string)RouteData.Values["id"];
            int    position = Int32.Parse(id);
            User   user     = (User)Session["users"];

            if (user == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            NH.NHibernateOperation operation = new NH.NHibernateOperation();

            List <int> users = operation.GetUsersByPosition(position);

            if (!users.Contains(user.Id_user))
            {
                ViewBag.Result = 403;
            }

            Position     p     = operation.FindPositionById(position);
            IList <Flow> flows = operation.GetUserActiveFlows(p);
            Flow         flow  = new Flow();

            foreach (Flow f in flows)
            {
                if (f.id_flow == number)
                {
                    ViewBag.Flow = f;
                    flow         = f;
                    break;
                }
            }
            FlowDefinition fl  = operation.GetFlowDefinition(flow.id_flowdefinition.id_flowDefinition);
            Document       doc = operation.GetDocumentByName(fl.Flow_name);

            byte[] data = doc.Data;
            string str2 = System.Text.Encoding.UTF8.GetString(data, 0, data.Length);
            string sub  = str2.Substring(1);

            XmlSerializer deserializer = new XmlSerializer(typeof(Items));
            XmlDocument   docxml       = new XmlDocument();

            docxml.LoadXml(sub);
            XmlNodeReader node    = new XmlNodeReader(docxml);
            object        obj     = deserializer.Deserialize(node);
            Items         XmlData = (Items)obj;

            node.Close();
            Dictionary <string, Item> itemMap = new Dictionary <string, Item>();

            foreach (Item it in XmlData.itemList)
            {
                if (it.id.name.Equals("Item "))
                {
                    it.id.name = "check";
                }
                itemMap.Add(it.id.name, it);
            }

            IList <Attributes> attrList = operation.GetAttributesByFlow(flow.id_flowdefinition.id_flowDefinition);
            FullFlowModel      model    = new FullFlowModel();

            model.list     = new List <FlowModel <string> >();
            model.list_int = new List <FlowModel <int> >();
            model.values   = new List <string>();
            model.items    = XmlData;
            foreach (Attributes a in attrList)
            {
                Access acc = operation.GetAttributeAccess(position, a.Id_attribute);
                if (acc.Read_property == 1 && (acc.Required_change == 1 || acc.Optional_change == 1))
                {
                    if (a.Type.Equals("int"))
                    {
                        FlowModel <int> f = new FlowModel <int>();
                        f.name     = a.Name;
                        f.required = acc.Required_change;
                        f.type     = a.Type;
                        f.item     = itemMap[a.Name];
                        model.list_int.Add(f);
                    }
                    else
                    {
                        FlowModel <string> f = new FlowModel <string>();
                        f.name     = a.Name;
                        f.required = acc.Required_change;
                        f.type     = a.Type;
                        f.item     = itemMap[a.Name];
                        if (a.Type.Equals("list"))
                        {
                            IList <ListElement> ll  = operation.GetAttributeList(a.Id_attribute);
                            List <string>       str = new List <string>();
                            str.Add(null);
                            foreach (ListElement l in ll)
                            {
                                str.Add(l.Name);
                            }
                            f.list = str;
                        }
                        model.list.Add(f);
                    }
                }
                else if (acc.Read_property == 1)
                {
                    FlowExtension ext = operation.FindExtension(flow.id_flow, a.Id_attribute);
                    if (ext != null)
                    {
                        model.values.Add(a.Id_attribute.ToString() + " = " + ext.Value);
                    }
                }
            }
            ViewBag.Test = model;

            int max = 0;

            foreach (Item i in XmlData.itemList)
            {
                if ((i.location.y + i.size.height) > max)
                {
                    max = (i.location.y + i.size.height);
                }
            }

            max         = max + 70;
            ViewBag.Max = max.ToString() + "px";

            ViewBag.Tekst = "";

            return(View(model));
        }