예제 #1
0
        internal void DeleteWorkReports(List <string> workReportIDs)
        {
            if (workReportIDs == null || workReportIDs.Count < 1)
            {
                return;
            }
            var db = Utils.GetDb();

            foreach (var workReportID in workReportIDs)
            {
                PlanDac planDac = new PlanDac(db);
                db.BeginTransaction();
                try
                {
                    planDac.DeleteWorkReportBaseInfo(workReportID);
                    planDac.DeletaWorkReportComps(workReportID);
                    planDac.DeletaWorkReportRecipients(workReportID);
                    planDac.DeletaWorkReportPics(workReportID);
                    db.Commit();
                }
                catch
                {
                    db.Rollback();
                }
            }
        }
예제 #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();
            }
        }