//private StringBuilder GetStringBuilder(IEnumerable list, string DataTextFiled, string DataValueField, string selectedValue)
        //{
        //    StringBuilder strBuilder = new StringBuilder();
        //    if (((IList)list).Count == 0)
        //        return strBuilder;
        //    strBuilder.Append("[");
        //    foreach (Object item in list)
        //    {
        //        strBuilder.Append("{");
        //        strBuilder.Append("\"Name\":\"" + item.GetType().GetProperty(DataTextFiled).GetValue(item, null) + "\",");
        //        //strBuilder.Append("\"ID\":\"" + item.GetType().GetProperty(DataValueField).GetValue(item, null) + "\"");
        //        string id = item.GetType().GetProperty(DataValueField).GetValue(item, null).ToString();
        //        if (id.Equals("0"))
        //            id = "";
        //        strBuilder.Append("\"ID\":\"" + id + "\"");
        //        if(id.Equals(selectedValue))
        //            strBuilder.Append("\"Selected\":\"" + true + "\"");
        //        strBuilder.Append("},");
        //    }
        //    strBuilder.Remove(strBuilder.Length - 1, 1);
        //    strBuilder.Append("]");
        //    return strBuilder;
        //}
        public void ProcessRequest(HttpContext context)
        {
            string ID = context.Request.QueryString["ID"];
            string pageName = context.Request.QueryString["Page"];
            StringBuilder strBuilder = new StringBuilder();
            bool toGroup = false;
            switch (pageName)
            {
                case "JRAdmin":
                    List<WFRole> list = null;
                    if (string.IsNullOrEmpty(ID))
                    {
                        list = roleDao.GetList(true);
                    }
                    else
                    {
                        list = roleDao.GetListByWorkflow(int.Parse(ID));
                    }
                    strBuilder = GetStringBuilder(list, "Name", "ID");

                    break;
                case "JobRequest":
                    List<JobTitleLevel> posList = posDao.GetListByLevelId(int.Parse(ID));
                    strBuilder = GetStringBuilder(posList, "DisplayName", "ID");

                    break;
                //Tuc 13-12-11
                //Change name of method
                case "Department":
                    IList<JobTitleLevel> jobTitleList = null;
                    if (!string.IsNullOrEmpty(ID))
                    {
                        // triet.dinh 27-12-2011
                        int rootDeptId = deptDao.GetDepartmentRoot(ConvertUtil.ConvertToInt(ID));
                        jobTitleList = commDao.GetJobTitleList(rootDeptId);
                        //jobTitleList = commDao.GetJobTitleList(int.Parse(ID));
                    }
                    else
                    {
                        jobTitleList = commDao.GetJobTitleLevelList();
                    }
                    strBuilder = GetStringBuilder(jobTitleList, "DisplayName", "ID");

                    break;

                //Show list of Job Title which are fixed with Department when Create or Edit
                case "NewDepartment":
                    IList<JobTitle> jobTitleParentList = null;
                    if (!string.IsNullOrEmpty(ID))
                    {
                        // triet.dinh 27-12-2011
                        int rootDeptId = deptDao.GetDepartmentRoot(ConvertUtil.ConvertToInt(ID));
                        jobTitleParentList = commDao.GetJobTitleListByDepartmentId(rootDeptId);
                        //jobTitleParentList = commDao.GetJobTitleListByDepartmentId(int.Parse(ID));
                    }
                    else
                    {
                        jobTitleParentList = commDao.GetJobTitleList();
                    }
                    strBuilder = GetStringBuilder(jobTitleParentList, "JobTitleName", "JobTitleId");

                    break;

                //Tuc 13-12-11
                case "JobTitleParent":
                    IList<JobTitleLevel> jobTitleLevelList = null;
                    if (!string.IsNullOrEmpty(ID))
                    {
                        jobTitleLevelList = commDao.GetJobTitleLevelListByJobTitleId(int.Parse(ID));
                    }
                    else
                    {
                        jobTitleLevelList = commDao.GetJobTitleLevelList();
                    }
                    strBuilder = GetStringBuilder(jobTitleLevelList, "DisplayName", "ID");

                    break;

                case "SubDepartment":
                    DepartmentDao departmentDao = new DepartmentDao();
                    IList<Department> subDepartmentList = null;
                    if (!string.IsNullOrEmpty(ID))
                    {
                        subDepartmentList = departmentDao.GetSubListByParent(int.Parse(ID));
                    }
                    else
                    {
                        subDepartmentList = departmentDao.GetSubList();
                    }
                    strBuilder = GetStringBuilder(subDepartmentList, "DepartmentName", "DepartmentId");

                    break;

                case "Assign":
                    List<sp_GetListAssignByResolutionIdResult> assignList = jrDao.GetListAssign(int.Parse(ID));
                    strBuilder = GetStringBuilder(assignList, "DisplayName", "UserAdminRole");

                    break;

                case "PReviewAssign":
                    List<sp_GetListAssignByResolutionIdResult> assignPrList = prDao.GetListAssign(int.Parse(ID));
                    strBuilder = GetStringBuilder(assignPrList, "DisplayName", "UserAdminRole");

                    break;
                case "Status":
                    List<WFStatus> staList = new List<WFStatus> ();
                    //staList.Add(new WFStatus() { Name = Constants.PURCHASE_REQUEST_STATUS_FIRST_ITEM});
                    staList.AddRange(staDao.GetListStatusByResolution(int.Parse(ID)));
                    strBuilder = GetStringBuilder(staList, "Name", "ID");

                    break;

                case "Employee":
                    JobTitleLevelDao levelDao = new JobTitleLevelDao();
                    List<JobTitleLevel> titleList = null;
                    if (string.IsNullOrEmpty(ID))
                    {
                        titleList = levelDao.GetList();
                    }
                    else
                    {
                        titleList = levelDao.GetJobTitleListByDepId(int.Parse(ID));
                    }
                    strBuilder = GetStringBuilder(titleList, "DisplayName", "ID");

                    break;
                case "PurChaseAssign":
                    toGroup = false;
                    bool isUsPurchasing = context.Request.QueryString.AllKeys.Contains("isus") ?
                        bool.Parse(context.Request.QueryString["isus"]) : false;
                    if(context.Request.QueryString.AllKeys.Contains("toGroup"))
                        toGroup = bool.Parse(context.Request.QueryString["toGroup"]);
                    if (toGroup)
                    {
                        int roleId = int.Parse(context.Request.QueryString["roleId"]);
                        List<ListItem> prList = new List<ListItem>();
                        prList.Add(new ListItem(Constants.PURCHASE_REQUEST_APPROVAL_MAN, ""));
                        prList.AddRange(userAdminDao.GetListWithRole(roleId));
                        strBuilder = GetStringBuilder(prList, "Text", "Value");
                    }
                    else
                    {
                        List<sp_GetListAssignByResolutionIdResult> pruchaseAssignList = new List<sp_GetListAssignByResolutionIdResult>();
                        pruchaseAssignList.Add(new sp_GetListAssignByResolutionIdResult()
                        {
                            DisplayName = Constants.PURCHASE_REQUEST_APPROVAL_MAN,
                            UserAdminRole = ""
                        });
                        if(isUsPurchasing)
                            pruchaseAssignList.AddRange(purchaseDao.GetListAssign(int.Parse(ID), Constants.WORK_FLOW_PURCHASE_REQUEST_US));
                        else
                            pruchaseAssignList.AddRange(purchaseDao.GetListAssign(int.Parse(ID), Constants.WORK_FLOW_PURCHASE_REQUEST));
                        strBuilder = GetStringBuilder(pruchaseAssignList, "DisplayName", "UserAdminRole");
                    }
                    break;
                case "PurChaseAssignUS":
                    toGroup = false;
                    if (context.Request.QueryString.AllKeys.Contains("toGroup"))
                        toGroup = bool.Parse(context.Request.QueryString["toGroup"]);
                    if (toGroup)
                    {
                        int roleId = int.Parse(context.Request.QueryString["roleId"]);
                        List<ListItem> prList = new List<ListItem>();
                        prList.Add(new ListItem(Constants.PURCHASE_REQUEST_APPROVAL_MAN, ""));
                        prList.AddRange(userAdminDao.GetListWithRole(roleId));
                        strBuilder = GetStringBuilder(prList, "Text", "Value");
                    }
                    else
                    {
                        List<sp_GetListAssignByResolutionIdResult> pruchaseAssignList = new List<sp_GetListAssignByResolutionIdResult>();
                        pruchaseAssignList.Add(new sp_GetListAssignByResolutionIdResult()
                        {
                            DisplayName = Constants.PURCHASE_REQUEST_APPROVAL_MAN,
                            UserAdminRole = ""
                        });
                        pruchaseAssignList.AddRange(purchaseDao.GetListAssign(int.Parse(ID), Constants.WORK_FLOW_PURCHASE_REQUEST_US));
                        strBuilder = GetStringBuilder(pruchaseAssignList, "DisplayName", "UserAdminRole");
                    }
                    break;
                case "AssignListByRole":
                    List<UserAdmin> adminList = commDao.GetUserAdminByRole(int.Parse(ID));
                    strBuilder = GetStringBuilder(adminList, "UserName", "UserAdminId");
                    break;
                case "WFRole":
                    List<WFRole> wfRoleList = new List<WFRole>();
                    if (string.IsNullOrEmpty(ID))
                    {
                       wfRoleList= roleDao.GetList();
                    }
                    else
                    {
                        wfRoleList = roleDao.GetListByWorkflow(int.Parse(ID));
                    }
                    strBuilder = GetStringBuilder(wfRoleList, "Name", "ID");
                    break;
                case "WFResolution":
                    List<WFResolution> wfResolutionList = new List<WFResolution>();
                    if (string.IsNullOrEmpty(ID))
                    {
                       wfResolutionList= resolutionDao.GetList();
                    }
                    else
                    {
                        wfResolutionList = resolutionDao.GetResolutionByWorkFlow(int.Parse(ID));
                    }
                    strBuilder = GetStringBuilder(wfResolutionList, "Name", "ID");
                    break;
                case "PTOType":
                    List<PTO_Type> ptoTypeList = new PTOTypeDao().GetTypeListByParentID(int.Parse(ID));
                    strBuilder = GetStringBuilder(ptoTypeList, "Name","ID" );
                    break;

                case "Category":
                    List<sp_GetSRCategoryResult> catList = new SRCategoryDao().GetList( null, int.Parse(ID), true);
                    strBuilder = GetStringBuilder(catList, "Name", "ID");
                    break;
                case "USAccouting":
                    List<sp_GetListAssignByResolutionIdResult> usAccountingAssignList = new List<sp_GetListAssignByResolutionIdResult>();
                    usAccountingAssignList.Add(new sp_GetListAssignByResolutionIdResult()
                        {
                            DisplayName = Constants.PURCHASE_REQUEST_APPROVAL_MAN,
                            UserAdminRole = ""
                        });
                    usAccountingAssignList.AddRange(purchaseDao.GetListAssign(int.Parse(ID), Constants.WORK_FLOW_PURCHASE_REQUEST));
                    strBuilder = GetStringBuilder(usAccountingAssignList, "DisplayName", "UserAdminRole");
                    break;
            }
            context.Response.ContentType = "application/json";
            context.Response.Write(strBuilder.ToString());
            context.Response.End();
        }
Esempio n. 2
0
 public static string SetHTMLForPTO_Detail(string ptoID, int pto_Type)
 {
     string result = string.Empty;
     List<PTO_Detail> listPTO_Detail = new PTODao().GetPTO_DetailByPTO_ID(ptoID);
     PTO_Type objPTO_Type = new PTOTypeDao().GetByID(pto_Type);
     if (objPTO_Type != null)
     {
         if (objPTO_Type.IsHourType)
         {
             int index = 0;
             string oldField = string.Empty;
             foreach (PTO_Detail pto_Detail in listPTO_Detail)
             {
                 string date = pto_Detail.DateOff.HasValue ? pto_Detail.DateOff.Value.ToString(Constants.DATETIME_FORMAT) : string.Empty;
                 result += "<tr class='trTypeDay'>" +
                          "<td class='label'>Date</td>" +
                         "<td class='input'><input type='text' style='width:120px' id='Date" + index + "' name='Date" + index + "' value='" + date + "' /></td>" +
                         "<td class='label'>Hour(s)</td>" +
                         "<td class='input'><input type='text' style='width:120px' id='Hour" + index + "' name='Hour" + index + "' value='" + (pto_Detail.TimeOff.HasValue ? pto_Detail.TimeOff.Value.ToString() : string.Empty) + "'/></td>";
                 if (index == 0)
                 {
                     result += "<td valign='top'><button type='button' class='icon plus' onclick='AddDate(" + index + ");'> </button>" +
                             "<button type='button' class='icon minus' onclick='RemoveDate();'></button></td>";
                 }
                 result += "<script type='text/javascript'>" +
                             "$(function () {" +
                                 "$('#Date" + index + "').datepicker({" +
                                     "onClose: function () {$(this).valid();}" +
                                 "});" +
                             "});" +
                             "$('#Date" + index + "').rules('add', { required: true, checkDate: true });" +
                             "$('#Hour" + index + "').rules('add', { required: true, number: true, min: 1, max: 8 });" +
                     "</script>";
                 oldField += index + ",";
                 index++;
             }
             result += "<script type='text/javascript'>" +
                           "$('#hidDate').val('" + oldField + "');" +
                     "</script>";
         }
         else
         {
             PTO_Detail pto_Detail = listPTO_Detail[0];
             string fromDate = pto_Detail.DateOffFrom.HasValue ? pto_Detail.DateOffFrom.Value.ToString(Constants.DATETIME_FORMAT) : string.Empty;
             string toDate = pto_Detail.DateOffTo.HasValue ? pto_Detail.DateOffTo.Value.ToString(Constants.DATETIME_FORMAT) : string.Empty;
             result += "<tr id='trRangeDay'>" +
                               "<td class='label'>From Date <span>*</span></td>" +
                               "<td class='input'><input type='text' style='width:120px' id='FromDate' name='FromDate' value='" + fromDate + "' /></td>" +
                               "<td class='label'>To Date <span>*</span></td>" +
                               "<td class='input'><input type='text' style='width:120px' id='ToDate' name='ToDate'  value='" + toDate + "'/></td>" +
                           "</tr>";
             result += "<script type='text/javascript'>" +
                             "$('#hidDate').val('');" +
                             "$(function () {" +
                                 "$('#FromDate').datepicker({" +
                                     "onClose: function () {$(this).valid();}" +
                                 "});" +
                                 "$('#ToDate').datepicker({" +
                                     "onClose: function () {$(this).valid();}" +
                                 "});" +
                             "});" +
                     "</script>";
         }
     }
     return result;
 }