コード例 #1
0
ファイル: PaafHelper.cs プロジェクト: slwinnie/PIMS
    public static PaafDate GetPaafDate(string projectNo, string type, string wbs, int employeeId)
    {
        var paafDate = new PaafDate();
        var db       = new PPPEntities();
        var item     = db.TStaffingPlanDetailYearMonth.Where(x => x.ProjectNo == projectNo &&
                                                             x.Type == type && x.WBS == wbs && x.EmployeeId == employeeId);

        if (item.Any())
        {
            var max = 0;
            var min = 999999;
            foreach (var m in item)
            {
                if (m.YearMonth < min)
                {
                    min = m.YearMonth;
                }
                if (m.YearMonth > max)
                {
                    max = m.YearMonth;
                }
            }
            paafDate.StartDate  = min;
            paafDate.StartYear  = Convert.ToInt32(paafDate.StartDate.ToString().Substring(0, 4));
            paafDate.StartMonth = Convert.ToInt32(paafDate.StartDate.ToString().Substring(4, 2));
            paafDate.EndDate    = max;
            paafDate.EndYear    = Convert.ToInt32(paafDate.EndYear.ToString().Substring(0, 4));
            paafDate.EndMonth   = Convert.ToInt32(paafDate.EndYear.ToString().Substring(4, 2));
        }
        return(paafDate);
    }
コード例 #2
0
    /// <summary>
    /// 取得指定管理者的所有员工ID
    /// </summary>
    /// <param name="ownerEmpId"></param>
    /// <param name="lst"></param>
    /// <param name="db"></param>
    /// <returns></returns>
    public static List <EmpInfo> GetEmpInfos(int ownerEmpId, List <EmpInfo> lst, PPPEntities db)
    {
        lst.Clear();

        // 根据员工ID查询出对应的OrganizationId
        var row = GetOrganizationRow(ownerEmpId, db);
        var Ids = new List <OrganizationRow>();

        if (row != null)
        {
            GetSubIds(Ids, row.OrganizationId, db);
            foreach (var id in Ids)
            {
                var ps = db.TPeople.Where(x => x.OrganizationId == id.OrganizationId);
                foreach (var p in ps)
                {
                    if (!lst.Any(x => x.EmpId == p.EmployeeId))
                    {
                        var pi = GetProjectInfo(p.EmployeeId.ToString(), db);
                        lst.Add(new EmpInfo {
                            EmpId      = p.EmployeeId, EmpName = p.PeopleNameEn,
                            ProjectNos = pi.ProjectNos,
                            StartDate  = pi.StartDate,
                            EndDate    = pi.EndDate
                        });
                    }
                }
            }
        }

        return(lst);
    }
コード例 #3
0
ファイル: RiskHelper.cs プロジェクト: slwinnie/PIMS
    public static bool IsFormalRiskManagementIsRequired(int projectId, int subId, string formType)
    {
        var db   = new PPPEntities();
        var risk = db.RiskClassificationForm.FirstOrDefault(x => x.ProjectId == projectId && x.SubId == subId && x.type == formType);

        if (risk != null)
        {
            return(risk.r1.Contains(RequiredKeyString) ||
                   risk.r2.Contains(RequiredKeyString) ||
                   risk.r3.Contains(RequiredKeyString) ||
                   risk.r4.Contains(RequiredKeyString) ||
                   risk.r5.Contains(RequiredKeyString) ||
                   risk.r6.Contains(RequiredKeyString) ||
                   risk.r7.Contains(RequiredKeyString) ||
                   risk.r8.Contains(RequiredKeyString) ||
                   risk.r9.Contains(RequiredKeyString) ||
                   risk.r10.Contains(RequiredKeyString) ||
                   risk.r11.Contains(RequiredKeyString) ||
                   risk.r12.Contains(RequiredKeyString) ||
                   risk.r13.Contains(RequiredKeyString) ||
                   risk.r14.Contains(RequiredKeyString) ||
                   risk.r22.Contains(RequiredKeyString) ||
                   risk.r23.Contains(RequiredKeyString) ||
                   risk.r24.Contains(RequiredKeyString)
                   );
        }

        return(false);
    }
コード例 #4
0
    public static ProjectInfo GetProjectInfo(string empId, PPPEntities db)
    {
        var pi           = new ProjectInfo();
        var sb           = new StringBuilder();
        var minStartDate = DateTime.Now.AddYears(1000);
        var maxEndDate   = DateTime.Now.AddYears(-1000);
        var lst          = new List <string>();

        foreach (var p in db.TSProjectTotalHMs.Where(x => x.EmployeeId == empId))
        {
            if (!lst.Contains(p.ProjectNo))
            {
                sb.Append(p.ProjectNo + ",");
                lst.Add(p.ProjectNo);
            }
            var d = db.TProjectRegister.FirstOrDefault(x => x.ProjectNo == p.ProjectNo);
            if (d != null)
            {
                minStartDate = minStartDate > (DateTime)d.StartDate ? (DateTime)d.StartDate : minStartDate;
                maxEndDate   = maxEndDate < (DateTime)d.EndDate ? (DateTime)d.EndDate : maxEndDate;
            }
        }
        if (sb.Length > 0)
        {
            sb.Length--;
        }
        pi.ProjectNos = sb.ToString();
        pi.StartDate  = minStartDate.ToString();
        pi.EndDate    = maxEndDate.ToString();
        return(pi);
    }
コード例 #5
0
    public static string GetPeopleId(string peopleName)
    {
        try
        {
            if (peopleName == "")
            {
                return(peopleName);
            }

            var db   = new PPPEntities();
            var item = db.TPeople.FirstOrDefault(x => x.PeopleNameEn == peopleName);
            if (item != null)
            {
                return(item.EmployeeId.ToString());
            }
            else
            {
                return(peopleName);
            }
        }
        catch (Exception)
        {
            return(peopleName);
        }
    }
コード例 #6
0
    public static List <Grid4Row> GetEmployeeProjectNo(string fy, int empId)
    {
        var lst = new List <Grid4Row>();
        var db  = new PPPEntities();

        var q = (from t in db.TSProjectTotalHMs
                 select new
        {
            t.EmployeeId,
            t.ProjectType,
            t.ProjectNo,
            t.TotalMHs
        }).ToList();

        var r = q.Where(x => x.EmployeeId == empId.ToString()).ToList();

        if (r.Count > 0)
        {
            foreach (var x in r)
            {
                var r4 = new Grid4Row {
                    EmpId     = empId,
                    ProjectNo = x.ProjectNo,
                    Hours     = x.TotalMHs
                };
                lst.Add(r4);
            }
        }
        return(lst);
    }
コード例 #7
0
    /// <summary>
    /// 中间表格::计算当前(财年,所有者,员工)的
    /// [Employee_ID, Employee_Name, OH_Budget, Up_to_now_Chargeability, Current_Chargeability, Project_Id, Project_No, Start_Date, End_Date]
    /// </summary>
    /// <param name="fy"></param>
    /// <param name="ownerEmpId"></param>
    /// <returns></returns>
    public static List <Grid2Row> GetEmpProjectInfoInFy(string fy, int ownerEmpId)
    {
        var lst = new List <Grid2Row>();
        var db  = new PPPEntities();

        //db.TSProjectTotalHMs.Where(x=>x.)


        return(null);
    }
コード例 #8
0
    public static List <Grid3Row> GetEmployeeMonthChargeability(string fy, int empId)
    {
        var lst = new List <Grid3Row>();
        var db  = new PPPEntities();
        var ms  = FYearMonths(fy);
        Func <DateTime, string> fmt = (d) =>
        {
            return(string.Format("{0}/{1}", d.Year, d.Month.ToString().PadLeft(2, '0')));
        };
        var q = (from t in db.TSProjectTotalHMs
                 select new
        {
            t.EmployeeId,
            t.ProjectType,
            t.ProjectNo,
            t.TotalMHs,
            WE = t.WeekEnding.Year.ToString() + "/" + (t.WeekEnding.Month < 10 ? "0" + t.WeekEnding.Month.ToString() : t.WeekEnding.Month.ToString())
        }).ToList();

        foreach (var m in ms)
        {
            var r = q.Where(x => x.EmployeeId == empId.ToString() && x.WE == m).ToList();
            if (r.Count > 0)
            {
                var r3 = new Grid3Row
                {
                    EmpId = empId,
                    Month = m
                };
                var leave = r.Where(x => x.ProjectType == "Leave").Sum(x => x.TotalMHs);
                r3.Leave = leave.ToString();
                var oh = r.Where(x => x.ProjectType == "OH").Sum(x => x.TotalMHs);
                r3.OH = oh.ToString();
                var totalHours = r.Sum(x => x.TotalMHs);
                r3.Total_Hours = totalHours.ToString();
                var holiday = r.Where(x => x.ProjectType == "Holiday").Sum(x => x.TotalMHs);
                r3.Holiday = holiday.ToString();
                lst.Add(r3);
            }
            //else
            //{
            //    var r3 = new Grid3Row
            //    {
            //        EmpId = empId,
            //        Month = m
            //    };
            //    lst.Add(r3);
            //}
        }

        return(lst);
    }
コード例 #9
0
    public static string GetAccountName(int employeeId)
    {
        var db  = new PPPEntities();
        var acc = db.TAccount.FirstOrDefault(x => x.EmployeeId == employeeId);

        if (acc != null)
        {
            return(acc.Account);
        }
        else
        {
            return(employeeId.ToString());
        }
    }
コード例 #10
0
    /// <summary>
    /// 删除组织结构中的一个节点
    /// </summary>
    /// <param name="id"></param>
    /// <param name="db"></param>
    public static void DeleteThisAndChild(int id, PPPEntities db)
    {
        var acc = db.TOrganization.FirstOrDefault(x => x.OrganizationId == id);

        if (acc != null)
        {
            var children = db.TOrganization.Where(x => x.ParentId == id);
            foreach (var c in children)
            {
                DeleteThisAndChild(c.OrganizationId, db);
            }
            db.TOrganization.Remove(acc);
            db.TOrganizationPeoples.RemoveRange(db.TOrganizationPeoples.Where(x => x.OrganizationId == id));
        }
    }
コード例 #11
0
    public static void GetSubIds(List <OrganizationRow> lst, int organizationId, PPPEntities db)
    {
        var subIds = db.TOrganization.Where(x => x.ParentId == organizationId);

        foreach (var item in subIds)
        {
            if (!lst.Any(x => x.OrganizationId == item.OrganizationId))
            {
                lst.Add(new OrganizationRow {
                    OrganizationId = item.OrganizationId, Title = item.Title
                });
            }
            GetSubIds(lst, item.OrganizationId, db);
        }
    }
コード例 #12
0
    public static OrganizationRow GetOrganizationRow(int ownerEmpId, PPPEntities db)
    {
        var rtn = new OrganizationRow();
        var p   = db.TPeople.FirstOrDefault(x => x.EmployeeId == ownerEmpId);

        if (p != null && p.OrganizationId != null)
        {
            rtn.OrganizationId = (int)p.OrganizationId;
            rtn.OwnerId        = ownerEmpId;
            rtn.EmpName        = p.PeopleNameEn;
            return(rtn);
        }
        else
        {
            return(null);
        }
    }
コード例 #13
0
ファイル: StaffingPlanHelper.cs プロジェクト: slwinnie/PIMS
    public static void UpdatePlanDetailYearMonth(string projectNo)
    {
        var db       = new PPPEntities();
        var type     = "Project";
        var projInfo = db.TProjectBasicInfo.FirstOrDefault(x => x.ProjectNo == projectNo);

        if (projInfo != null)
        {
            var lst     = GetYearMonthListMix(projInfo.StartDate, projInfo.EndDate);
            var wbsList = (from x in db.TStaffingPlan.Where(x => x.ProjectNo == projectNo && x.Type == "Project")
                           select x.WBS).Distinct().ToList();
            foreach (var wbs in wbsList)
            {
                var wbs1   = wbs;
                var empLst = (from x in db.TStaffingPlanDetail.Where(x => x.ProjectNo == projectNo &&
                                                                     x.Type == type &&
                                                                     x.WBS == wbs1)
                              select x.EmployeeId
                              ).Distinct().ToList();
                foreach (var employeeId in empLst)
                {
                    foreach (var ym in lst)
                    {
                        if (!db.TStaffingPlanDetailYearMonth.Any(x => x.ProjectNo == projectNo &&
                                                                 x.Type == type &&
                                                                 x.WBS == wbs1 && x.EmployeeId == employeeId &&
                                                                 x.YearMonth == ym.NValue))
                        {
                            var row = new TStaffingPlanDetailYearMonth
                            {
                                ProjectNo      = projectNo,
                                Type           = type,
                                WBS            = wbs,
                                EmployeeId     = employeeId,
                                YearMonth      = ym.NValue,
                                YearMonthValue = 0
                            };
                            db.TStaffingPlanDetailYearMonth.Add(row);
                        }
                    }
                }
            }
            db.SaveChanges();
        }
    }
コード例 #14
0
    public static string DomainUserName()
    {
        var isDebugMode = HttpContext.Current.Server.MachineName.ToLower() != "cnbeiwpenc02v";
        var db          = new PPPEntities();
        var employeeId  = Convert.ToInt32(GetEmployeeId(HttpContext.Current.User.Identity.Name));
        var item        = db.TAccount.FirstOrDefault(x => x.EmployeeId == employeeId);

        if (item != null)
        {
            item.LastLogin = DateTime.Now;
            db.SaveChanges();
        }
        //isDebugMode = false; // 启动生产模式
        if (!isDebugMode)
        {
            // 生产模式
            return(HttpContext.Current.User.Identity.Name);
        }
        else
        {
            // 调试模式
            //return @"Debug\ZHENHUA.LIU";
            //return @"Debug\FUJU.ZHAO";
            //return @"Debug\LI.MA";
            try
            {
                var sr  = new System.IO.StreamReader(System.Web.HttpContext.Current.Server.MapPath("~/DebugUser.txt"));
                var str = sr.ReadToEnd();
                sr.Close();
                var arr = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                if (arr[0].IndexOf("\\") >= 0)
                {
                    return(arr[0]);
                }
                else
                {
                    return(string.Format("Debug{0}{1}", "\\", arr[0]));
                }
            }
            catch (Exception ex)
            {
                return(@"Debug\ZHENHUA.LIU");
            }
        }
    }
コード例 #15
0
ファイル: PaafHelper.cs プロジェクト: slwinnie/PIMS
    public void SyncPaaf(string projectNo, string type)
    {
        var db    = new PPPEntities();
        var items = db.TStaffingPlanDetail.Where(x => x.ProjectNo == projectNo && x.Type == type);

        foreach (var item in items)
        {
            var     employeeId   = item.EmployeeId;
            var     hourByPerson = item.HourByPerson;
            decimal?sellingRate  = 0;
            var     position     = "";
            var     ppl          = db.TStaffingBasicInfo.FirstOrDefault(x => x.EmployeeId == employeeId);
            if (ppl != null)
            {
                sellingRate = ppl.SellingRate;
                position    = ppl.Position;
            }
            if (!db.PAAF.Any(x => x.ProjectNo == projectNo &&
                             x.Type == type &&
                             x.EmployeeId == employeeId &&
                             x.Position == position))
            {
                // 不存在,则追加
                var paaf = new PAAF();
                paaf.ProjectNo  = projectNo;
                paaf.Type       = type;
                paaf.Position   = position;
                paaf.EmployeeId = employeeId;
                if (!db.PAAF.Any(x => x.ProjectNo == projectNo &&
                                 x.Type == type))
                {
                    paaf.No = 1;
                }
                else
                {
                    paaf.No = Convert.ToInt32(db.PAAF.Max(x => x.ProjectNo == projectNo && x.Type == type)) + 1;
                }
            }
            else
            {
                // 存在,则更新
            }
        }
    }
コード例 #16
0
    public static IEnumerable <FunctionInfo> GetFunctions(string employeeId)
    {
        var db     = new PPPEntities();
        var iempId = Convert.ToInt32(employeeId);
        var acc    = db.TAccount.FirstOrDefault(x => x.EmployeeId == iempId);

        if (acc != null)
        {
            var q = (from x in db.TAccountRole.Where(x => x.AccountId == acc.AccountId)
                     join y1 in db.TRole on x.RoleId equals y1.RoleId into tmp
                     from y in tmp.DefaultIfEmpty()
                     select new RoleInfo
            {
                RoleId = x.RoleId,
                Role = y.Role
            }).ToList();

            var y2 = (from z1 in q
                      join z2 in db.TRoleDetail on z1.RoleId equals z2.RoleId into tmp
                      from z in tmp
                      select new FunctionInfo
            {
                FunctionId = (int)z.FunctionId,
                Access = z.Access
            }).ToList();

            var y3 = (from z in y2
                      join m1 in db.TFunction on z.FunctionId equals m1.Id into tmp2
                      from m in tmp2
                      select new FunctionInfo
            {
                FunctionId = z.FunctionId,
                Function = m.FunctionName,
                Access = z == null ? "" : z.Access
            }).ToList();

            return(y3);
        }
        else
        {
            return(new List <FunctionInfo>());
        }
    }
コード例 #17
0
ファイル: OrganizationHelper.cs プロジェクト: slwinnie/PIMS
    public static string OrganizationPeoples(int organizationId)
    {
        var db      = new PPPEntities();
        var peoples = new StringBuilder();

        foreach (var org in db.TOrganizationPeoples.Where(x => x.OrganizationId == organizationId))
        {
            var p = db.TPeople.FirstOrDefault(x => x.EmployeeId == org.PeopleId);
            if (p != null)
            {
                peoples.Append(string.Format("{0},", p.PeopleNameEn));
            }
        }
        if (peoples.Length > 0)
        {
            peoples.Length--;
        }

        return(string.Format("<span class='organization-peoples'>{0}</span>", peoples));
    }
コード例 #18
0
 public static string GetPeopleName(string peopleId)
 {
     try
     {
         var db        = new PPPEntities();
         var iPeopleId = Convert.ToInt32(peopleId);
         var item      = db.TPeople.FirstOrDefault(x => x.EmployeeId == iPeopleId);
         if (item != null)
         {
             return(item.PeopleNameEn);
         }
         else
         {
             return(peopleId);
         }
     }
     catch (Exception)
     {
         return(peopleId);
     }
 }
コード例 #19
0
ファイル: StaffingPlanHelper.cs プロジェクト: slwinnie/PIMS
    public static List <int> GetYearMonthListNum(string projectNo)
    {
        var db       = new PPPEntities();
        var projInfo = db.TProjectBasicInfo.FirstOrDefault(x => x.ProjectNo == projectNo);

        if (projInfo != null)
        {
            try
            {
                return(GetYearMonthListNum(projInfo.StartDate, projInfo.EndDate));
            }
            catch (Exception)
            {
                return(new List <int>());
            }
        }
        else
        {
            return(new List <int>());
        }
    }
コード例 #20
0
    public static List <CurrentChargeability> GetCurrentChargeability(string fy, int ownerEmpId)
    {
        var db  = new PPPEntities();
        var lst = new List <EmpInfo>();
        var rst = new List <CurrentChargeability>();

        GetEmpInfos(ownerEmpId, lst, db);
        var months = FYearMonths(fy);

        // select convert(nvarchar(50), DATEPART(yyyy, WeekEnding)) + right('0'+cast(DATEPART(mm, WeekEnding) as varchar) ,2) as FYMonth from TSProjectTotalHMs
        foreach (var m in months)
        {
            lst.Clear();
            GetEmpInfos(ownerEmpId, lst, db);
            foreach (var emp in lst)
            {
                var item = new CurrentChargeability();
                //item.Chargeability =
            }
        }

        return(null);
    }
コード例 #21
0
    public static string GetEmployeeId(string pUserName)
    {
        var items = pUserName.Split(new char[] { '\\' }, StringSplitOptions.None);

        if (items.Length > 0)
        {
            var enUserName = items[items.Length - 1];
            var db         = new PPPEntities();
            var acc        = db.TAccount.FirstOrDefault(x => x.UserName == enUserName);
            if (acc != null)
            {
                return(acc.EmployeeId.ToString());
            }
            else
            {
                return("0");
            }
        }
        else
        {
            return("0");
        }
    }
コード例 #22
0
    public static IEnumerable <RoleInfo> GetRoles(string employeeId)
    {
        var db     = new PPPEntities();
        var iempId = Convert.ToInt32(employeeId);
        var acc    = db.TAccount.FirstOrDefault(x => x.EmployeeId == iempId);

        if (acc != null)
        {
            var q = from x in db.TAccountRole.Where(x => x.AccountId == acc.AccountId)
                    join y1 in db.TRole on x.RoleId equals y1.RoleId into tmp
                    from y in tmp.DefaultIfEmpty()
                    select new RoleInfo
            {
                RoleId = x.RoleId,
                Role   = y.Role
            };

            return(q);
        }
        else
        {
            return(new List <RoleInfo>());
        }
    }
コード例 #23
0
ファイル: BidApprovalHelper.cs プロジェクト: slwinnie/PIMS
    public static void GetBidFormNextAppover(string pProjectId, string pSubId, string meId, Page page)
    {
        var db          = new PPPEntities();
        var iPprojectId = Convert.ToInt32(pProjectId);
        var iPsubId     = Convert.ToInt32(pSubId);
        var frm         = db.BIDForm.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId);
        var iEmployeeId = 0;

        ;
        if (frm != null)
        {
            #region Init
            var lst = new BidFormBlock[7];
            var pos = 0;
            if (!string.IsNullOrEmpty(frm.t69))
            {
                iEmployeeId = Convert.ToInt32(frm.t69);
                var appr = db.TApproval.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId && x.EmployeeId == iEmployeeId && x.FormType == "Bid");
                lst[pos]            = new BidFormBlock();
                lst[pos].Checked    = frm.c78 == "true";
                lst[pos].EmployeeId = iEmployeeId;
                if (appr != null)
                {
                    lst[pos].Status = appr.Status;
                }
                pos++;
            }
            if (!string.IsNullOrEmpty(frm.t67))
            {
                iEmployeeId = Convert.ToInt32(frm.t67);
                var appr = db.TApproval.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId && x.EmployeeId == iEmployeeId && x.FormType == "Bid");
                lst[pos]            = new BidFormBlock();
                lst[pos].Checked    = frm.c74 == "true";
                lst[pos].EmployeeId = iEmployeeId;
                if (appr != null)
                {
                    lst[pos].Status = appr.Status;
                }
                pos++;
            }

            if (!string.IsNullOrEmpty(frm.t65))
            {
                iEmployeeId = Convert.ToInt32(frm.t65);
                var appr = db.TApproval.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId && x.EmployeeId == iEmployeeId && x.FormType == "Bid");
                lst[pos]            = new BidFormBlock();
                lst[pos].Checked    = frm.c70 == "true";
                lst[pos].EmployeeId = iEmployeeId;
                if (appr != null)
                {
                    lst[pos].Status = appr.Status;
                }
                pos++;
            }
            if (!string.IsNullOrEmpty(frm.t63))
            {
                iEmployeeId = Convert.ToInt32(frm.t63);
                var appr = db.TApproval.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId && x.EmployeeId == iEmployeeId && x.FormType == "Bid");
                lst[pos]            = new BidFormBlock();
                lst[pos].Checked    = frm.c66 == "true";
                lst[pos].EmployeeId = iEmployeeId;
                if (appr != null)
                {
                    lst[pos].Status = appr.Status;
                }
                pos++;
            }
            if (!string.IsNullOrEmpty(frm.t61))
            {
                iEmployeeId = Convert.ToInt32(frm.t61);
                var appr = db.TApproval.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId && x.EmployeeId == iEmployeeId && x.FormType == "Bid");
                lst[pos]            = new BidFormBlock();
                lst[pos].Checked    = frm.c62 == "true";
                lst[pos].EmployeeId = iEmployeeId;
                if (appr != null)
                {
                    lst[pos].Status = appr.Status;
                    pos++;
                }
            }
            if (!string.IsNullOrEmpty(frm.t59))
            {
                iEmployeeId = Convert.ToInt32(frm.t59);
                var appr = db.TApproval.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId && x.EmployeeId == iEmployeeId && x.FormType == "Bid");
                lst[pos]            = new BidFormBlock();
                lst[pos].Checked    = frm.c58 == "true";
                lst[pos].EmployeeId = iEmployeeId;
                if (appr != null)
                {
                    lst[pos].Status = appr.Status;
                }
                pos++;
            }
            if (!string.IsNullOrEmpty(frm.t57))
            {
                iEmployeeId = Convert.ToInt32(frm.t57);
                var appr = db.TApproval.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId && x.EmployeeId == iEmployeeId && x.FormType == "Bid");
                lst[6]            = new BidFormBlock();
                lst[6].Checked    = frm.c54 == "true";
                lst[6].EmployeeId = iEmployeeId;
                if (appr != null)
                {
                    lst[6].Status = appr.Status;
                }
                pos++;
            }
            #endregion

            var iMeId = Convert.ToInt32(meId);
            var index = -1;
            for (var i = 0; i < lst.Length; i++)
            {
                if (lst[i] != null && lst[i].Status != "Approved" && lst[i].EmployeeId != iMeId)
                {
                    index = i;
                    break;
                }
            }
            if (index >= 0)
            {
                // 还需要领导批复
                var item = lst[index];
                var v    = db.TApproval.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId && x.FormType == "Bid" && x.EmployeeId == item.EmployeeId);
                if (v == null)
                {
                    // Insert data to tapproval
                    v             = new TApproval();
                    v.EmployeeId  = item.EmployeeId;
                    v.Status      = "New";
                    v.ProjectId   = iPprojectId;
                    v.SubId       = iPsubId;
                    v.FormType    = "Bid";
                    v.CreatedDate = DateTime.Now;
                    db.TApproval.Add(v);
                }
                else
                {
                    v.Status      = "New";
                    v.CreatedDate = DateTime.Now;
                }
                var plp = db.TAccount.FirstOrDefault(x => x.EmployeeId == v.EmployeeId);

                var myStatus = db.TApproval.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId && x.FormType == "Bid" && x.EmployeeId == iMeId);
                if (myStatus != null)
                {
                    myStatus.ApprovedDate = DateTime.Now;
                }
                db.SaveChanges();

                #region Send Email

                var sys = db.SystemEMail.First();

                var emialTo       = plp.Email;
                var subject       = string.Format("Approval/Submission Reminder for {0} BID/NOBID", iPprojectId);
                var loginUrl      = string.Format("{0}://{1}:{2}{3}", page.Request.Url.Scheme, page.Request.Url.Host, page.Request.Url.Port, string.Format("{0}Default.aspx", page.ResolveUrl("~")));
                var emailContent  = string.Format("<p>BID/NOBID Form for project {0} is ready for approval. Please click <a href='{1}' target='_blank'>here</a>.</p><p style='color:gray;'>This is a system generated email from PIMs Online. Please do not reply to this email. </p>", iPprojectId, loginUrl);
                var strSmtpServer = sys.Smtp;
                var strFrom       = sys.Sender;
                var strFromPass   = sys.Password;
                var strTo         = emialTo;
                var strSubject    = subject;
                var strBody       = emailContent;

                var client = new SmtpClient(strSmtpServer);
                client.UseDefaultCredentials = false;
                client.Credentials           = new System.Net.NetworkCredential(strFrom, strFromPass);
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;

                var message = new MailMessage(strFrom, strTo, strSubject, strBody);
                message.BodyEncoding = Encoding.UTF8;
                message.IsBodyHtml   = true;
                client.Send(message);
                #endregion
            }
            else
            {
                // 批复完成
                var f = db.TProposalX.FirstOrDefault(x => x.ProjectId == iPprojectId && x.SubId == iPsubId);
                var p = db.TPeople.FirstOrDefault(x => x.EmployeeId == iEmployeeId);
                if (f != null && p != null)
                {
                    f.BidApproveDate = DateTime.Now;
                    db.SaveChanges();
                }
            }
        }
    }
コード例 #24
0
ファイル: RiskHelper.cs プロジェクト: slwinnie/PIMS
    public static void SendEmailToRiskManager(int projectId, int subId, string formType)
    {
        if (IsFormalRiskManagementIsRequired(projectId, subId, formType))
        {
            var db          = new PPPEntities();
            var projectNo   = string.Empty;
            var projectName = string.Empty;
            if (formType == "1")
            {
                var pi = db.TProposalX.FirstOrDefault(x => x.ProjectId == projectId && x.SubId == subId);
                if (pi != null)
                {
                    projectNo   = pi.ProposalNo;
                    projectName = pi.ProjectName;
                }
            }
            else
            {
                var pi = db.TProjectX.FirstOrDefault(x => x.ProjectId == projectId && x.SubId == subId);
                if (pi != null)
                {
                    projectNo   = pi.ProjectNo;
                    projectName = pi.ProjectName;
                }
            }


            #region Send Email to releation people groups
            try
            {
                var sys          = db.SystemEMail.First();
                var emailReciver = db.SystemRiskManagementEmail.FirstOrDefault();
                if (emailReciver != null)
                {
                    var subject      = string.Format("FORMAL RISK MANAGEMENT is required. Project No.- {0}", projectNo);
                    var loginUrl     = string.Format("{0}://{1}:{2}{3}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port, string.Format("{0}Default.aspx", HttpContext.Current.Request.ApplicationPath));
                    var emailContent = string.Format("<p>FORMAL RISK MANAGEMENT is required. Project No.:{0}, Project Name:{1}.</p><p style='color:gray;'>This is a system generated email from <a href='{2}'>PIMs</a> Online. Please do not reply to this email. </p>", projectNo, projectName, loginUrl);

                    var strSmtpServer = sys.Smtp;
                    var strFrom       = sys.Sender;
                    var strFromPass   = sys.Password;
                    var strTo         = emailReciver.RiskManagementEmail;
                    var strSubject    = subject;
                    var strBody       = emailContent;
                    var client        = new SmtpClient(strSmtpServer);
                    client.UseDefaultCredentials = false;
                    client.Credentials           = new System.Net.NetworkCredential(strFrom, strFromPass);
                    client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    var message = new MailMessage(strFrom, strTo, strSubject, strBody);
                    message.BodyEncoding = System.Text.Encoding.UTF8;

                    message.IsBodyHtml = true;
                    client.Send(message);
                }
            }
            catch (Exception ex2)
            {
            }
            #endregion
        }
    }