public ActionResult SyncService(string id)
        {
            int idInt;

            if (string.IsNullOrWhiteSpace(id) || !int.TryParse(id, out idInt))
            {
                ShowNotify("无效同步服务ID");
                return(UIHelper.Result());
            }
            try
            {
                var list = _alertContacts.Find(t => t.ServiceId == idInt).ToList();
                if (list.Count > 0)
                {
                    var model = Rep.Get(t => t._id == idInt);
                    var sList = Rep.Find(t => t.PrimaryId == model.PrimaryId && t._id != idInt).ToList();

                    var rList = new List <ServiceAlertContacts>();

                    sList.ForEach(k =>
                    {
                        list.ForEach(l =>
                        {
                            var m       = (ServiceAlertContacts)l.Clone();
                            m._id       = Guid.NewGuid().ToString();
                            m.ServiceId = Convert.ToInt32(k._id);
                            m.PrimaryId = k.PrimaryId;
                            rList.Add(m);
                        });
                    });
                    _alertContacts.Delete(t => t.PrimaryId == model.PrimaryId && t.ServiceId != idInt);
                    _alertContacts.BulkInsert(rList);
                    ShowNotify("同步成功");
                }
                else
                {
                    ShowNotify("无同步数据");
                }
            }
            catch (Exception e)
            {
                Alert.Show(e.Message, MessageBoxIcon.Warning);
                throw;
            }
            return(UIHelper.Result());
        }
        public ActionResult RepairsImport(HttpPostedFileBase file)
        {
            if (file == null || file.ContentLength == 0)
            {
                return(UIHelper.Result());
            }
            var fileName = file.FileName;
            var fileType = GetFileType(fileName);

            if (!ValidFileTypes.Contains(fileType))
            {
                // 清空文件上传组件
                UIHelper.FileUpload("file").Reset();
                ShowNotify("无效的文件类型!");
            }
            else
            {
                try
                {
                    var       list    = new List <ScreenRepairs>();
                    var       listLog = new List <ScreenRecDetail>();
                    IWorkbook wb;
                    if (fileType == "xls")
                    {
                        wb = new HSSFWorkbook(file.InputStream);
                    }
                    else
                    {
                        wb = new XSSFWorkbook(file.InputStream);
                    }
                    var sheet    = wb.GetSheetAt(0);
                    var maxId    = (int)(_rep.Max(t => t._id) ?? 0) + 1;
                    var maxLogId = (int)(_repDetail.Max(t => t._id) ?? 0) + 1;
                    var logs     = _repDetail.Find(t => !t.IsLog).ToList();
                    for (var i = 1; i <= sheet.LastRowNum; i++)
                    {
                        var row   = sheet.GetRow(i);
                        var model = new ScreenRepairs();
                        model._id = maxId + i - 1;
                        row.GetCell(1).SetCellType(CellType.Numeric);
                        model.RepairsDate = row.GetCell(1).DateCellValue;
                        row.GetCell(2).SetCellType(CellType.String);
                        model.LineName = row.GetCell(2).StringCellValue;
                        model.Station  = row.GetCell(3).StringCellValue;
                        model.Owner    = row.GetCell(4).StringCellValue;
                        row.GetCell(5).SetCellType(CellType.String);
                        model.RepairsSource = row.GetCell(5).StringCellValue;
                        model.Accepter      = row.GetCell(6).StringCellValue;
                        model.Handler       = row.GetCell(7).StringCellValue;
                        model.HitchType     = row.GetCell(8).StringCellValue;
                        HitchStatusEnum e;
                        if (Enum.TryParse(row.GetCell(9).StringCellValue, out e))
                        {
                            model.Status = e;
                        }
                        //if (string.IsNullOrWhiteSpace(model.Status))
                        //{
                        //    model.Status = "未解决";
                        //}
                        model.HitchContent = row.GetCell(10).StringCellValue;
                        model.Solution     = row.GetCell(11).StringCellValue;


                        var lines = model.LineName.Replace("、", "/")
                                    .Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                        //var filter =
                        //    Builders<ScreenRecDetail>.Filter.And(
                        //        Builders<ScreenRecDetail>.Filter.Eq(t => t.InstallStation, model.Station),
                        //        Builders<ScreenRecDetail>.Filter.Or(
                        //            Builders<ScreenRecDetail>.Filter.In(t => t.LineName, lines),
                        //            Builders<ScreenRecDetail>.Filter.Eq(t => t.LineName, model.LineName),Builders<ScreenRecDetail>.Filter.Regex(t=>t.LineName,new BsonRegularExpression())));
                        if (model.LineName == null)
                        {
                            model.LineName = "";
                        }
                        var devs =
                            logs.Where(
                                t =>
                                (t.InstallStation == model.Station || model.Station.Contains(t.InstallStation) ||
                                 t.InstallStation.Contains(model.Station ?? "")) &&
                                (model.LineName.Contains(t.LineName) || t.LineName == model.LineName)).ToList();
                        if (devs.Any())
                        {
                            var devNums = new HashSet <string>();
                            foreach (var dev in devs)
                            {
                                if (!devNums.Add(dev.DeviceNum))
                                {
                                    continue;
                                }
                                //var log = new ScreenRecDetail();
                                //log._id = maxLogId;
                                //maxLogId++;
                                //log.DeviceNum = dev.DeviceNum;
                                //log.LogType = "服务类型";
                                //log.HandlingType = "维修";
                                //log.Date = model.RepairsDate;
                                //log.IsLog = true;
                                //log.Materials.Remark = string.Format("故障问题:{0};解决方法:{1}", model.HitchContent,
                                //    model.Solution);
                                //listLog.Add(log);

                                model.DeviceNum = dev.DeviceNum;
                            }
                        }
                        if (!string.IsNullOrEmpty(model.LineName) && !string.IsNullOrEmpty(model.Station) && !string.IsNullOrEmpty(model.Owner))
                        {
                            list.Add(model);
                        }
                    }
                    if (list.Any())
                    {
                        _rep.BulkInsert(list);
                    }
                    if (listLog.Any())
                    {
                        _repDetail.BulkInsert(listLog);
                    }
                    // 关闭本窗体(触发窗体的关闭事件)
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                    ShowNotify("导入成功");
                }
                //catch (Exception e)
                //{
                //    Alert.Show(e.Message, MessageBoxIcon.Warning);
                //    return UIHelper.Result();
                //}
                finally
                {
                    file.InputStream.Close();
                }
            }
            return(UIHelper.Result());
        }