Ejemplo n.º 1
0
        internal List <string> AddWorkReports(List <WorkReport> workReports)
        {
            if (workReports == null || workReports.Count < 1)
            {
                return(null);
            }
            var           db      = Utils.GetDb();
            PlanDac       planDac = new PlanDac(db);
            List <string> users   = new List <string>();
            List <string> wrids   = new List <string>();

            db.BeginTransaction();
            try
            {
                foreach (var workReport in workReports)
                {
                    string wrid = planDac.AddWorkReportBaseInfo(workReport);
                    wrids.Add(wrid);
                    planDac.AddWorkReportComps(workReport.WorkReportComps, wrid);
                    planDac.AddWorkReportPictures(workReport.WorkReportPics, wrid);
                    planDac.AddWorkReportRecipients(workReport.WorkReportRecipients, wrid);
                    if (workReport.WorkReportRecipients != null && workReport.WorkReportRecipients.Count > 0)
                    {
                        workReport.WorkReportRecipients.ForEach(user =>
                        {
                            if (!users.Contains(user.ID))
                            {
                                users.Add(user.ID);
                            }
                        });
                    }
                }
                db.Commit();
                if (users.Count > 0)
                {
                    NoticeRecipients(users);
                }
                return(wrids);
            }
            catch
            {
                db.Rollback();
                return(null);
            }
        }
Ejemplo n.º 2
0
        internal void UpdateWorkReport(WorkReport workReport, bool isReNotice)
        {
            if (workReport == null || string.IsNullOrWhiteSpace(workReport.ID))
            {
                return;
            }
            var     db      = Utils.GetDb();
            PlanDac planDac = new PlanDac(db);

            db.BeginTransaction();
            try
            {
                planDac.UpdateWorkReportBaseInfo(workReport);
                planDac.DeletaWorkReportComps(workReport.ID);
                // planDac.DeletaWorkReportRecipients(workReport.ID);
                planDac.AddWorkReportComps(workReport.WorkReportComps, workReport.ID);
                // planDac.AddWorkReportRecipients(workReport);

                List <WRPicture> newPics = workReport.WorkReportPics;
                if (newPics == null || newPics.Count <= 0)
                {
                    planDac.DeletaWorkReportPics(workReport.ID);
                }
                else
                {
                    List <WRPicture> oldPics = planDac.GetPicturesByID(workReport.ID);
                    if (oldPics == null || oldPics.Count <= 0)
                    {
                        planDac.AddWorkReportPictures(newPics, workReport.ID);
                    }
                    else
                    {
                        List <WRPicture> newAddPics  = new List <WRPicture>();
                        List <string>    deletedPics = new List <string>();
                        List <string>    oldPicIDs   = new List <string>();
                        List <string>    newPicIDs   = new List <string>();
                        oldPics.ForEach(pic =>
                        {
                            oldPicIDs.Add(pic.ID);
                        });
                        newPics.ForEach(pic =>
                        {
                            newPicIDs.Add(pic.ID);
                            if (string.IsNullOrEmpty(pic.ID) || !oldPicIDs.Contains(pic.ID))
                            {
                                newAddPics.Add(pic);
                            }
                        });
                        oldPics.ForEach(pic =>
                        {
                            if (!newPicIDs.Contains(pic.ID))
                            {
                                deletedPics.Add(pic.ID);
                            }
                        });
                        planDac.DeletaWorkReportPics(deletedPics);
                        planDac.AddWorkReportPictures(newAddPics, workReport.ID);
                    }
                }

                db.Commit();
                // 推送通知
                if (isReNotice)
                {
                    List <string> recipients = planDac.GetRecipientsByID(workReport.ID);
                    if (recipients != null && recipients.Count > 0)
                    {
                        NoticeRecipients(recipients);
                    }
                }
            }
            catch
            {
                db.Rollback();
            }
        }