Esempio n. 1
0
        public ActionResult GetActivityPreview(string ID)
        {
            bool isAdmin = AccessControl.CurrentLogonUser.IsAdmin();
            string contentString = "<tr>";
            contentString += "<td style='width:8%'><h4"+(isAdmin == true ? " style='cursor:pointer' onclick='showUserSetting(\"" + ID + "\", \"Owner\")'" : "") +">Owner</h4></td><td>{0}</td>";
            contentString += "<td style='width:9%'><h4" + (isAdmin == true ? " style='cursor:pointer' onclick='showFieldSetting(\"" + ID + "\", \"Required\")'" : "") + "> Required</h4></td><td>{1}</td>";
            contentString += "</tr><tr>";
            contentString += "<td><h4" + (isAdmin == true ? " style='cursor:pointer' onclick='showUserSetting(\"" + ID + "\", \"CC\")'" : "") + ">CC</h4></td><td>{2}</td>";
            contentString += "<td><h4" + (isAdmin == true ? " style='cursor:pointer' onclick='showFieldSetting(\"" + ID + "\", \"NotRequired\")'" : "") + ">Non Mandatory</h4></td><td>{3}</td>";
            contentString += "</tr>";

            string ownerUser = "";
            string ccUser = "";
            string isRequired = "";
            string notRequired = "";

            int activityId = 0;
            if (int.TryParse(ID, out activityId) && activityId > 0)
            {
                WFActivity act = new WFActivity(activityId);
                string[] users = GetUserString(act);
                string[] fields = GetFieldString(act);

                ownerUser = users[0];
                ccUser = users[1];
                isRequired = fields[0];
                notRequired = fields[1];
            }
            return Content(String.Format(contentString, ownerUser, isRequired, ccUser, notRequired));
        }
Esempio n. 2
0
 public UserChangedEvent(int RFQID)
 {
     return;
     _entityId = RFQID;
     if (_entityId > 0)
     {
         WFTemplate wf = new WFTemplate(1, _entityId);
         _activity = wf.CurrentActivity;
     }
 }
Esempio n. 3
0
        public static void CheckField(WFTemplate template, List<WFActivityField> listFields, SystemMessages sysMsg, WFActivity activity)
        {
            if (sysMsg == null)
            {
                sysMsg = CreateMessages();
            }

            foreach (WFActivityField field in listFields)
            {
                if (field.IsRequired)
                {
                    if (String.IsNullOrEmpty(field.SubDataType))
                    {
                        bool isEmpty = true;
                        if (template.MasterData.Table.Columns.Contains(field.FieldName))
                        {
                            string fieldValue = Convert.ToString(template.MasterData[field.FieldName]).Trim();
                            isEmpty = FieldIsEmpty(field, fieldValue);
                        }
                        if (isEmpty)
                        {
                            sysMsg.isPass = false;
                            sysMsg.Messages.Add(String.Format("{0} - Validation", template.MasterData[activity.Template.MessageField])  , String.Format("\"{0}\" is required.", field.DisplayName));
                        }
                    }
                    else
                    {
                        bool isEmpty = true;
                        string tableName = field.SubDataType.ToUpper();
                        if (template.SubData.ContainsKey(tableName))
                        {
                            DataTable subDt = template.SubData[tableName];
                            if (subDt.Rows.Count > 0)
                            {
                                isEmpty = false;
                                for (int i = 0; i < subDt.Rows.Count; i++)
                                {
                                    string fieldValue = Convert.ToString(subDt.Rows[i][field.FieldName]).Trim();
                                    if (FieldIsEmpty(field, fieldValue))
                                    {
                                        sysMsg.isPass = false;
                                        sysMsg.Messages.Add(String.Format("{0} - Validation", template.MasterData[activity.Template.MessageField]), String.Format("\"{0}(line:{1})\" is required.", field.DisplayName, i+1));
                                    }
                                }
                            }
                        }
                        if (isEmpty)
                        {
                            sysMsg.isPass = false;
                            sysMsg.Messages.Add(String.Format("{0} - Validation", template.MasterData[activity.Template.MessageField]), String.Format("\"{0}\" is required.", field.DisplayName));
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private void SubmitToNextActivity(SystemMessages sysMsg, WFActivity nextActivity, params int[] toChildActivityId)
        {
            string strSql = String.Format("DELETE FROM SGP_CurrentUserTask WHERE TemplateID={0} AND EntityId={1}", this.ID, EntityID);
            DbHelperSQL.ExecuteSql(strSql);
            string extSql = "";

            if (nextActivity.ID == LastActivity.ID)
            {
                extSql = ",StatusID = 9";
            }
            else
            {
                if (nextActivity.ChildActivities.Count > 0)
                {
                    if (toChildActivityId != null && toChildActivityId.Length > 0)
                    {
                        for (int i = 0; i < toChildActivityId.Length; i++)
                        {
                            WFActivity ncta = nextActivity.MatchChildActivities.Get(toChildActivityId[i]);
                            if (ncta != null)
                            {
                                AddCurrentUserTask(ncta);
                            }
                        }
                    }
                    else
                    {
                        foreach (WFActivity nca in nextActivity.MatchChildActivities)
                        {
                            AddCurrentUserTask(nca);
                        }
                    }
                }
                else
                {
                    AddCurrentUserTask(nextActivity);
                }
            }

            if (nextActivity.ChildActivities.Count > 0)
            {
                if (toChildActivityId != null && toChildActivityId.Length > 0)
                {
                    for (int i = 0; i < toChildActivityId.Length; i++)
                    {

                        WFActivity ncta = nextActivity.MatchChildActivities.Get(toChildActivityId[i]);
                        if (ncta != null)
                        {
                            AddProcessLog(nextActivity.ID, ncta.ID, 4);
                        }
                    }
                }
                else
                {
                    foreach (WFActivity nca in nextActivity.MatchChildActivities)
                    {
                        AddProcessLog(nextActivity.ID, nca.ID, 4);
                    }
                }

                AddProcessLog(CurrentActivity == null ? 0 : CurrentActivity.ID, nextActivity.ID, 3);
            }
            else
            {
                AddProcessLog(CurrentActivity == null ? 0 : CurrentActivity.ID, nextActivity.ID, (CurrentActivity != null && CurrentActivity.ChildActivities.Count > 0) ? 1 : 0);
            }

            strSql = String.Format("UPDATE {0} SET ActivityID = @ActivityID, TemplateID = @TemplateID {2} WHERE {1} = @{1}", this.TableName, this.TableKey, extSql);
            DbHelperSQL.ExecuteSql(strSql, new SqlParameter[]{
                    new SqlParameter("@ActivityID", nextActivity.ID),
                    new SqlParameter("@TemplateID", this.ID),
                    new SqlParameter("@" + this.TableKey, this.EntityID)
                });

            this.FromActivity = CurrentActivity;
            this.ToActivity = nextActivity;
            _masterData = null;

            nextActivity.DoAction();
            foreach (WFActivity nca in nextActivity.MatchChildActivities)
            {
                nca.DoAction();
            }
        }
Esempio n. 5
0
        private void SubmitChildActivity(SystemMessages sysMsg, WFActivity fromActivity, WFActivity nextActivity)
        {
            string strUserSql = String.Format("DELETE FROM SGP_CurrentUserTask WHERE TemplateID={0} AND EntityId={1} AND ActivityID = {2}", this.ID, EntityID, fromActivity.ID);
            DbHelperSQL.ExecuteSql(strUserSql);

            AddProcessLog(fromActivity.ID, nextActivity.ID, 2);

            this.FromActivity = CurrentActivity;
            this.ToActivity = nextActivity;
            _masterData = null;

            fromActivity.DoAction();

            if (this.CurrentActivity.CurrentUserChildActivities.Contains(fromActivity))
            {
                this.CurrentActivity.CurrentUserChildActivities.Remove(fromActivity);
            }
        }
Esempio n. 6
0
 private void AddCurrentUserTask(WFActivity activity)
 {
     string strSql = String.Format("INSERT INTO SGP_CurrentUserTask(TemplateID,ActivityID,EntityID,UID) VALUES({0},{1},{2},@UID)", this.ID, activity.ID, this.EntityID);
     foreach (KeyValuePair<string, WFUser> kvUser in activity.WFUsers)
     {
         if (kvUser.Value.IsKeyUser || kvUser.Value.IsApprover)
         {
             DbHelperSQL.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("@UID", kvUser.Value.UserID) });
         }
     }
 }
Esempio n. 7
0
 public static string WFActivityToJSON(WFActivity activity)
 {
     return "{\"id\":" + activity.ID + ",\"name\":" + Newtonsoft.Json.JsonConvert.SerializeObject(activity.Name) + ", \"sort\":" + activity.Sort + ",\"activityType\":" + Newtonsoft.Json.JsonConvert.SerializeObject(activity.ActivityType) + ",\"activityDeac\":" + Newtonsoft.Json.JsonConvert.SerializeObject(activity.Description) + ",\"childCount\":" + activity.CurrentChildActivities.Count + "}";
 }
Esempio n. 8
0
        public ActionResult SaveFieldSort()
        {
            bool success = true;
            string errMessage = "";
            string actId = Request["actId"];
            int activityId = 0;
            if (int.TryParse(actId, out activityId) && activityId > 0)
            {
                try
                {
                    WFActivity activity = new WFActivity(activityId);
                    List<WFActivityField> lstFields = activity.GetCheckFields();
                    if (lstFields != null)
                    {
                        string strSql = "UPDATE SYS_WFActivityField SET Sort = @Sort WHERE ID = @ID";

                        foreach (WFActivityField field in lstFields)
                        {
                            string fieldSort = Request[field.ID.ToString()];
                            if (!String.IsNullOrWhiteSpace(fieldSort))
                            {
                                int iSort = 0;
                                if (int.TryParse(fieldSort, out iSort) && iSort > 0)
                                {
                                    DbHelperSQL.ExecuteSql(strSql, new SqlParameter[] {
                                        new SqlParameter("@Sort",iSort),
                                        new SqlParameter("@ID",field.ID),
                                    });
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    success = false;
                    errMessage = ex.Message;
                }
            }

            var jsonResult = new
            {
                success = success,
                errMessage = errMessage
            };
            return Json(jsonResult);
        }
Esempio n. 9
0
        public ActionResult GetPreviewUser()
        {
            string actId = Request["actId"];
            int activityId = 0;
            if (int.TryParse(actId, out activityId))
            {
                WFActivity activity = new WFActivity(activityId);

                var previewUser = new
                {
                    Specified = activity.GetEntityPreviewUser(),
                    Fixed = activity.GetStaticUsers(),
                    Role = activity.GetRolePreviewUser()
                };
                return Json(previewUser);
            }
            else
            {
                return null;
            }
        }
Esempio n. 10
0
 public ActionResult GetPreviewFields()
 {
     string actId = Request["actId"];
     int activityId = 0;
     if (int.TryParse(actId, out activityId))
     {
         WFActivity activity = new WFActivity(activityId);
         List<WFActivityField> lstFields = activity.GetCheckFields();
         if (lstFields != null)
         {
             return Json(lstFields);
         }
     }
     return Content("[]");
 }
Esempio n. 11
0
        private string[] GetUserString(WFActivity activity)
        {
            string ownerString = "<div class='clearfix'>";
            string ccString = "<div class='clearfix'>";

            Dictionary<string, WFUser> wfUsers = new Dictionary<string, WFUser>();

            activity.MergeUser(wfUsers, activity.GetStaticUsers());
            activity.MergeUser(wfUsers, activity.GetRoleUsers());

            activity.MergeUser(wfUsers, WFHelper.GetDelegateUsers(wfUsers));

            List<WFUser> lstPrevUser = activity.GetEntityPreviewUser();

            if (lstPrevUser != null)
            {
                foreach (WFUser u in lstPrevUser)
                {
                    if (u.IsApprover || u.IsKeyUser)
                    {
                        ownerString += GetUserString(u, "Specified");
                    }
                    else
                    {
                        ccString += GetUserString(u, "Specified");
                    }
                }
            }

            foreach (KeyValuePair<string, WFUser> kvUser in wfUsers)
            {
                if (kvUser.Value.IsApprover || kvUser.Value.IsKeyUser)
                {
                    ownerString += GetUserString(kvUser.Value, "Fixed");
                }
                else
                {
                    ccString += GetUserString(kvUser.Value, "Fixed");
                }
            }

            ownerString += "</div>";
            ccString += "</div>";

            return new string[] { ownerString, ccString };
        }
Esempio n. 12
0
        private string[] GetFieldString(WFActivity activity)
        {
            string requiredField = "<div class='clearfix'>";
            string notRequiredField = "<div class='clearfix'>";
            string fieldString = "";
            List<WFActivityField> lstField = activity.GetCheckFields();

            if (lstField != null)
            {
                foreach (WFActivityField f in lstField)
                {
                    fieldString = "<div class='itemdiv memberdiv'><div class='user'><i class='{0} icon-edit icon-3x'></i></div>";
                    fieldString += "<div class='body'>";
                    fieldString += "<div class='name'>" + f.DisplayName + "</div>";
                    fieldString += "<div><span class='label label-success label-sm'>" + f.Sort + "</span></div>";
                    fieldString += "</div></div>";

                    if (f.IsRequired)
                    {
                        requiredField += String.Format(fieldString, "blue"); ;
                    }
                    else
                    {
                        notRequiredField += String.Format(fieldString, "light-grey"); ;
                    }
                }
            }

            requiredField += "</div>";
            notRequiredField += "</div>";
            return new string[] { requiredField, notRequiredField };
        }
Esempio n. 13
0
 public static string GetCurrentSubComplatedTimelineString(WFProcessLog complatedLog)
 {
     WFActivity activity = new WFActivity(complatedLog.FromActivityID);
     return "{\"activityName\":" + Newtonsoft.Json.JsonConvert.SerializeObject(activity.Name) +
                         ",\"actionUser\":" + Newtonsoft.Json.JsonConvert.SerializeObject(complatedLog.ActionUserName) +
                         ", \"actionTime\":\"" + String.Format("{0:yyyy-MM-dd HH:mm:ss}", complatedLog.ActionTime) + "\"" +
                         ", \"sort\":" + activity.Sort +
                         ",\"activityType\":" + Newtonsoft.Json.JsonConvert.SerializeObject(activity.ActivityType) +
                         ",\"subActivityComplated\":" + (complatedLog.SubActivityComplated ? "1" : "0") + "}";
 }
Esempio n. 14
0
        public static string ExportWorkflowTemplate(WFActivity activity)
        {
            List<WFActivityField> fields = activity.GetCheckFields();
            List<WFActivityField> mainFields = new List<WFActivityField>();
            Dictionary<string, List<WFActivityField>> subFields = new Dictionary<string, List<WFActivityField>>();
            Dictionary<string, ISheet> subSheets = new Dictionary<string, ISheet>();

            foreach (WFActivityField f in fields)
            {
                if (String.IsNullOrEmpty(f.SubDataType))
                {
                    mainFields.Add(f);
                }
                else
                {
                    if (!subFields.ContainsKey(f.SubDataType))
                    {
                        subFields.Add(f.SubDataType, new List<WFActivityField>());
                    }
                    subFields[f.SubDataType].Add(f);
                }
            }

            IWorkbook workbook = new XSSFWorkbook();

            ISheet sheet = workbook.CreateSheet("Primary");
            foreach (string k in subFields.Keys)
            {
                string strSql = "SELECT RelationFields FROM SYS_WFSubData WHERE TemplateID=@TemplateID AND TableName=@TableName";
                DataTable dt = DbHelperSQL.Query(strSql, new SqlParameter[] { new SqlParameter("@TemplateID", activity.TemplateID), new SqlParameter("@TableName", k) }).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    string[] rfs = Convert.ToString(dt.Rows[0]["RelationFields"]).Split(',');
                    if (rfs != null && rfs.Length > 0)
                    {
                        List<WFActivityField> relationFields = new List<WFActivityField>();
                        foreach (string rf in rfs)
                        {
                            if (!String.IsNullOrEmpty(rf))
                            {
                                WFActivityField f = mainFields.Find(t => String.Compare(t.FieldName, rf, true) == 0);
                                if (f != null)
                                {
                                    relationFields.Add(f);
                                }
                            }
                        }
                        if (relationFields.Count > 0)
                        {
                            subFields[k].InsertRange(0, relationFields);
                        }
                    }
                }

                subSheets.Add(k, workbook.CreateSheet(k.Replace(" ", "_")));
            }

            int dsStartIndex = 0;
            ISheet sheetDS = workbook.CreateSheet("DataSource");

            int sheetIndex = 0;
            buildTemplateSheet(workbook, sheet, sheetDS, mainFields, ref dsStartIndex, sheetIndex);
            foreach (string k in subFields.Keys)
            {
                sheetIndex++;
                buildTemplateSheet(workbook, subSheets[k], sheetDS, subFields[k], ref dsStartIndex, sheetIndex);
            }

            string tempFile = System.Web.HttpContext.Current.Server.MapPath("~/temp/") + Guid.NewGuid() + ".xlsx";
            using (var fileStream = FileHelper.CreateFile(tempFile))
            {
                workbook.Write(fileStream);
            }
            return tempFile;
        }