Ejemplo n.º 1
0
        private DocObject GetDocObject()
        {
            string name = textBox1.Text.Trim();

            if (name == "")
            {
                name = "未命名文档";
            }

            DocObject document = new DocObject();

            document.ID     = (doc == null ? 0 : doc.ID);
            document.Name   = name;
            document.Form   = form;
            document.Owner  = this.User;//文档的作者自动更新为最后修改文档的用户
            document.Remark = textBox2.Text;
            FormItemLogic fil = FormItemLogic.GetInstance();

            foreach (Control c in panel2.Controls)
            {
                if (c is DocEditControl)
                {
                    DocEditControl dec  = c as DocEditControl;
                    FormItem       item = dec.Field;
                    int            id   = 0;
                    if (doc != null)
                    {
                        id = fil.SaveFormItem(item);
                    }
                    else
                    {
                        id = fil.AddFormItem(item);
                    }
                    if (id > 0)
                    {
                        item.ID = id;
                        document.DocItems.Add(item);
                    }
                }
            }
            doc = document;
            return(document);
        }
Ejemplo n.º 2
0
        private void LoadItems(List <FormItem> items)
        {
            if (items != null)
            {
                panel2.SuspendLayout();
                panel2.Controls.Clear();
                for (int i = 0; i < items.Count; i++)
                {
                    FormItem item = items[i];
                    if (doc == null)
                    {
                        SystemType type = Commons.GetSystemType(item.ItemType);
                        switch (type)
                        {
                        case SystemType.附件:
                            break;

                        case SystemType.时间:
                            item.ItemValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            break;

                        case SystemType.数字:
                            item.ItemValue = "0.00";
                            break;

                        case SystemType.字符:
                            item.ItemValue = string.Empty;
                            break;

                        default:
                            break;
                        }
                    }
                    DocEditControl dec = new DocEditControl();
                    dec.Field             = item;
                    dec.Location          = new Point(width, height + (height + dec.Height) * i);
                    dec.Width             = panel2.Width - width * 2;
                    dec.Anchor            = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                    dec.comboBox1.Enabled = (doc == null);
                    if (!dec.comboBox1.Enabled)
                    {//已经存在的文档,限制编辑
                        bool canEdit = false;
                        bool isAppr;
                        int  level;
                        dec.GetExecAppr(out isAppr, out level);
                        TaskInfo task = TaskInfoLogic.GetInstance().GetTaskInfoByEntityId(doc.ID);
                        if (task != null)
                        {
                            TaskStageTemplate stageTemp     = task.Flow.Template.Stages[task.Flow.CurrentIndex];
                            TaskStatus        currentStatus = task.Flow.Current.Status;
                            if (level == 0)
                            {
                                if (task.Sponsor == this.User.Username && currentStatus == TaskStatus.Initiative)
                                {
                                    canEdit = true;//只有未被接收(即初始化状态)的文档允许文档发起者修改普通字段
                                }
                            }
                            else//level>0是执行字段和审批字段...
                            {
                                if (isAppr)//审批
                                {
                                    if (stageTemp.Approvers.Contains(this.User.ID.ToString()) && currentStatus == TaskStatus.Processed)
                                    {
                                        canEdit = true;
                                    }
                                }
                                else//执行
                                {
                                    if (stageTemp.Executors.Contains(this.User.ID.ToString()) && currentStatus == TaskStatus.Processing)
                                    {
                                        canEdit = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            canEdit = true;//没启动流程之前的文档可以修改任何字段
                        }
                        dec.CanEdit = canEdit;
                    }
                    panel2.Controls.Add(dec);
                }
                panel2.ResumeLayout(true);
            }
        }