//建立新叫修單 //20160801拿掉自動派工 public String[] Create(WBSEventViewModel wBSEventViewModel) { String[] ret = new String[4]; ret[0] = "false"; ret[1] = ""; ret[2] = ""; //area ret[3] = ""; //auto assign user name int casecode = 0, caseID = 0, num = 0, childCaseID = 0; String caseClass = wBSEventViewModel.EventClass[0].ToString(); //casecode = db.WBSEventM.AsEnumerable().Where(x => x.CaseClass == "C" && x.CaseDate == DateTime.Now.ToString("yyyyMMdd")).Select(x => x.CaseCode).DefaultIfEmpty(0).Max(x => x) + 1; casecode = db.WBSEventM.AsEnumerable().Where(x => x.CaseClass == caseClass && x.CaseDate == DateTime.Now.ToString("yyyyMMdd")).Select(x => x.CaseCode).DefaultIfEmpty(0).Max(x => x) + 1; caseID = db.WBSEventM.AsEnumerable().Select(x => x.CaseID).DefaultIfEmpty(0).Max(x => x) + 1; num = db.WBSEventC.AsEnumerable().Select(x => x.Num).DefaultIfEmpty(0).Max(x => x) + 1; childCaseID = db.WBSEventC.AsEnumerable().Where(x => x.MomCaseID == caseID).Select(x => x.ChildCaseID).DefaultIfEmpty(0).Max(x => x) + 1; int questionGrade = db.QuestionClass.AsEnumerable().Where(x => x.QuestionClassID == Int32.Parse(wBSEventViewModel.QuestionClass)).Select(x => x.QuestionGrade).First(); int serviceHours = db.QuestionClass.AsEnumerable().Where(x => x.QuestionClassID == Int32.Parse(wBSEventViewModel.QuestionClass)).Select(x => x.QuestionServiceHours).First(); String groupSW = db.Customer.AsEnumerable().Where(x => x.CustomerRef == wBSEventViewModel.CustomerRef).Select(x => x.GroupSW).First(); if (wBSEventViewModel.ExpectArriveDTStr == null) wBSEventViewModel.ExpectArriveDTStr = "19000101 00:01"; if (wBSEventViewModel.ExpectFinishDTStr == null) wBSEventViewModel.ExpectFinishDTStr = "19000101 00:01"; wBSEventViewModel.ExpectArriveDT = DateTime.ParseExact(wBSEventViewModel.ExpectArriveDTStr, "yyyyMMdd HH:mm", CultureInfo.InvariantCulture); wBSEventViewModel.ExpectFinishDT = DateTime.ParseExact(wBSEventViewModel.ExpectFinishDTStr, "yyyyMMdd HH:mm", CultureInfo.InvariantCulture); ret[2] = GetCustomerArea(wBSEventViewModel.CustomerRef); try { WBSEventM wBSEventM = new WBSEventM(); wBSEventM.CaseID = caseID; wBSEventM.ProductID = wBSEventViewModel.ProductID; //wBSEventM.CaseClass = wBSEventViewModel.WBSCaseNumberM.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[0]; //wBSEventM.CaseClass = wBSEventViewModel.WBSCaseNumberM.Substring(0, 1); //wBSEventM.CaseClass = "C"; wBSEventM.CaseClass = caseClass; //wBSEventM.CaseDate = wBSEventViewModel.WBSCaseNumberM.Substring(1, 8); wBSEventM.CaseDate = DateTime.Now.ToString("yyyyMMdd"); wBSEventM.CaseCode = casecode; wBSEventViewModel.WBSCaseNumberM = wBSEventM.CaseClass + wBSEventM.CaseDate + "-"; if (wBSEventM.CaseCode < 10) wBSEventViewModel.WBSCaseNumberM += "0000" + wBSEventM.CaseCode.ToString(); else if (wBSEventM.CaseCode < 100 && wBSEventM.CaseCode >= 10) wBSEventViewModel.WBSCaseNumberM += "000" + wBSEventM.CaseCode.ToString(); else if (wBSEventM.CaseCode < 1000 && wBSEventM.CaseCode >= 100) wBSEventViewModel.WBSCaseNumberM += "00" + wBSEventM.CaseCode.ToString(); else if (wBSEventM.CaseCode < 10000 && wBSEventM.CaseCode >= 1000) wBSEventViewModel.WBSCaseNumberM += "0" + wBSEventM.CaseCode.ToString(); else wBSEventViewModel.WBSCaseNumberM += wBSEventM.CaseCode.ToString(); wBSEventM.CustomerRef = wBSEventViewModel.CustomerRef; wBSEventM.CustomerUserID = wBSEventViewModel.CustomerUserID; wBSEventM.CustomerUserName = wBSEventViewModel.CustomerUserName; wBSEventM.CustomerUserPhone1 = wBSEventViewModel.CustomerUserPhone1; wBSEventM.CustomerUserPhone2 = wBSEventViewModel.CustomerUserPhone2; wBSEventM.CustomerCaseNum = wBSEventViewModel.CustomerCaseNum; //20150811新增-Hsiuyang if (wBSEventViewModel.ChangeAddr != null) if (wBSEventViewModel.ChangeAddr.Trim().Length > 0) wBSEventM.CustomerAddr = wBSEventViewModel.ChangeAddr; wBSEventM.SpareMach = "R"; //預設無借出備機 wBSEventM.UserMach = "R"; //預設無取回客戶機器 wBSEventM.CaseMStatus = "1"; //1為開立新問題 wBSEventM.CreateDT = DateTime.Now; wBSEventM.CreateUserID = wBSEventViewModel.CreateUserID; wBSEventM.ModifyDT = DateTime.Now; wBSEventM.ModifyUserID = wBSEventViewModel.CreateUserID; WBSEventC wBSEventC = new WBSEventC(); ret[1] = num.ToString(); wBSEventC.Num = num; wBSEventC.MomCaseID = caseID; wBSEventC.ChildCaseID = childCaseID; wBSEventViewModel.WBSCaseNumberC = (wBSEventC.ChildCaseID < 10) ? ("0" + wBSEventC.ChildCaseID.ToString()) : wBSEventC.ChildCaseID.ToString(); wBSEventC.EventClass = wBSEventViewModel.EventClass; wBSEventC.ProductClass = Int32.Parse(wBSEventViewModel.ProductClass); wBSEventC.ItemClass = Int32.Parse(wBSEventViewModel.ItemClass); wBSEventC.QuestionClass = Int32.Parse(wBSEventViewModel.QuestionClass); wBSEventC.QuestionGrade = questionGrade; wBSEventC.QuestionServiceHours = serviceHours; wBSEventC.QuestionDescription = wBSEventViewModel.QuestionDescription; wBSEventC.QuestionCreateUserID = wBSEventViewModel.QuestionCreateUserID; wBSEventC.QuestionCreateDateTime = DateTime.Now; wBSEventC.ExpectArriveDateTime = wBSEventViewModel.ExpectArriveDT; wBSEventC.ExpectFinishDateTime = wBSEventViewModel.ExpectFinishDT; wBSEventC.ExpectArriveSW = wBSEventViewModel.ExpectArriveSW; wBSEventC.DeleteMarkSW = wBSEventViewModel.DeleteMarkSW; wBSEventC.DeleteReason = wBSEventViewModel.DeleteReason; wBSEventC.DeleteMarkUserID = wBSEventViewModel.DeleteMarkUserID; wBSEventC.DeleteMarkDateTime = wBSEventViewModel.DeleteMarkDT; wBSEventC.CreateDateTime = DateTime.Now; wBSEventC.CreateUserID = wBSEventViewModel.CreateUserID; wBSEventC.ModifyDateTime = DateTime.Now; wBSEventC.ModifyUserID = wBSEventViewModel.CreateUserID; //wBSEventC.ModifyDateTime = wBSEventViewModel.ModifyDT; //wBSEventC.ModifyUserID = wBSEventViewModel.ModifyUserID; //20150811新增-Hsiuyang wBSEventC.SugProvideSpareMach = wBSEventViewModel.SugProvideSpareMach; wBSEventC.SugRetrieveSpareMach = wBSEventViewModel.SugRetrieveSpareMach; wBSEventC.SugRetrieveUserMach = wBSEventViewModel.SugRetrieveUserMach; wBSEventC.SugReturnUserMach = wBSEventViewModel.SugReturnUserMach; wBSEventC.SugMachMemo = (wBSEventViewModel.SugMachMemo == null) ? "" : wBSEventViewModel.SugMachMemo; //建議備機說明 wBSEventC.EventStatus = 11; //11為問題已開立 //20150813新增-Hsiuyang if (wBSEventViewModel.Closed == "T") //線上處理結案影響 { wBSEventM.CaseMStatus = "9"; //9為問題已結案 wBSEventM.CloseDT = DateTime.Now; wBSEventC.EventStatus = 50; //50為任務已解決(維修附件上傳) wBSEventC.QuestionFinishSW = "Y"; wBSEventC.QuestionFinishDT = DateTime.Now; wBSEventC.QuestionFinishSysDT = DateTime.Now; wBSEventC.ServiceReport = wBSEventViewModel.AssignDescription; //當結案時解決方式即為服務報告 } wBSEventC.AssignDescription = wBSEventViewModel.AssignDescription; //解決方式(派單)描述 //20150812新增-Hsiuyang-SugProduct建議部分 JArray SugProduct = JsonConvert.DeserializeObject<JArray>(wBSEventViewModel.MaterialJson); for (int i = 0; i < SugProduct.Count; i++) { SugProduct sugProduct = new SugProduct(); sugProduct.CID = wBSEventC.Num; sugProduct.Class = Int32.Parse(SugProduct[i]["Class"].ToString()); //sugProduct.Class = Int32.Parse(SugProduct[i][0].ToString()); //if (SugProduct[i][1].ToString() == "") if (SugProduct[i]["ProductNum"].ToString() == "") sugProduct.ProductName = SugProduct[i]["ProductName"].ToString(); //sugProduct.ProductName = SugProduct[i][2].ToString(); else sugProduct.ProductNum = Int32.Parse(SugProduct[i]["ProductNum"].ToString()); //sugProduct.ProductNum = Int32.Parse(SugProduct[i][1].ToString()); db.SugProduct.Add(sugProduct); } //20150813新增-Hsiuyang-解決方式知識庫附件 JArray KnowledgeData = JsonConvert.DeserializeObject<JArray>(wBSEventViewModel.KnowledgeJson); for (int i = 0; i < KnowledgeData.Count; i++) { Files knowledgefile = new Files(); knowledgefile.CID = wBSEventC.Num; knowledgefile.Class = 3; knowledgefile.FileAddr = ""; knowledgefile.FileName = ""; //knowledgefile.KnowledgeID = Int32.Parse(KnowledgeData[i][0].ToString()); knowledgefile.KnowledgeID = Int32.Parse(KnowledgeData[i]["KnowledgeID"].ToString()); db.Files.Add(knowledgefile); } //20150814新增-Hsiuyang-執行預先保養單 JArray maintainCases = JsonConvert.DeserializeObject<JArray>(wBSEventViewModel.MaintainCaseJson); for (int i = 0; i < maintainCases.Count; i++) { EventRelation maintainCase = new EventRelation(); maintainCase.CID = wBSEventC.Num; maintainCase.RelationCID = Int32.Parse(maintainCases[i]["cID"].ToString()); db.EventRelation.Add(maintainCase); } //20151113新增-Hsiuyang-Hyperlink建議參考網頁(CLASS=9) JArray Hyperlink = JsonConvert.DeserializeObject<JArray>(wBSEventViewModel.HyperlinkJson); for (int i = 0; i < Hyperlink.Count; i++) { Files hyperlink = new Files(); hyperlink.CID = wBSEventC.Num; hyperlink.Class = 9; hyperlink.FileAddr = Hyperlink[i]["Href"].ToString(); hyperlink.FileName = Hyperlink[i]["Name"].ToString(); db.Files.Add(hyperlink); } //20160801拿掉 //20151221-自動派單 //if (wBSEventViewModel.isAutoAssign.ToLower() == "true") //{ // String subAreaID = db.Customer.AsEnumerable().Where(x => x.CustomerRef == wBSEventM.CustomerRef).Select(x => x.RegionID).First(); // String AreaID = db.SubArea.AsEnumerable().Where(x => x.SubAreaID == subAreaID).Select(x => x.AreaID).First(); // int rID = 0; // if (db.SystemSetting.Where(x => x.EventClass == wBSEventViewModel.EventClass && x.AutoAssign == true).Count() > 0) //事件個別指定 // { // if (db.SystemSetting.Where(x => x.EventClass == wBSEventViewModel.EventClass && x.AutoAssignUserType == 2).Count() > 0) // rID = db.SubArea.AsEnumerable().Where(x => x.SubAreaID == subAreaID).Select(x => x.ResponsibleID).First(); // else // { // if (db.DefaultAssignSetting.Where(x => x.isSysDefault == true && x.AreaID == AreaID).Count() > 0) // rID = db.DefaultAssignSetting.Where(x => x.isSysDefault == true && x.AreaID == AreaID).Select(x => x.ResponsibleClassID).First(); // else if (db.DefaultAssignSetting.Where(x => x.EventClass == wBSEventViewModel.EventClass && x.AreaID == AreaID).Count() > 0) // rID = db.DefaultAssignSetting.Where(x => x.EventClass == wBSEventViewModel.EventClass && x.AreaID == AreaID).Select(x => x.ResponsibleClassID).First(); // } // } // else //系統預設 // { // if (db.SystemSetting.Where(x => x.isSysDefault == true && x.AutoAssignUserType == 2).Count() > 0) // rID = db.SubArea.AsEnumerable().Where(x => x.SubAreaID == subAreaID).Select(x => x.ResponsibleID).First(); // else // { // if (db.DefaultAssignSetting.Where(x => x.isSysDefault == true && x.AreaID == AreaID).Count() > 0) // rID = db.DefaultAssignSetting.Where(x => x.isSysDefault == true && x.AreaID == AreaID).Select(x => x.ResponsibleClassID).First(); // else if (db.DefaultAssignSetting.Where(x => x.EventClass == wBSEventViewModel.EventClass && x.AreaID == AreaID).Count() > 0) // rID = db.DefaultAssignSetting.Where(x => x.EventClass == wBSEventViewModel.EventClass && x.AreaID == AreaID).Select(x => x.ResponsibleClassID).First(); // } // } // wBSEventC.ResponsibleID = rID; // wBSEventC.AssignCreateDT = DateTime.Now; // wBSEventC.AssignCreateUserID = wBSEventViewModel.CreateUserID; // wBSEventC.AssignDT = DateTime.Now; // wBSEventC.AssignUserID = wBSEventViewModel.CreateUserID; // wBSEventC.AssignModifyDT = DateTime.Now; // wBSEventC.AssignModifyUserID = wBSEventViewModel.CreateUserID; // wBSEventC.RespondSW = "Y"; // wBSEventC.RespondDT = DateTime.Now; // wBSEventC.RespondReason = ""; // //wBSEventC.ScheduleStartDT = wBSEventViewModel.ExpectArriveDT; // //wBSEventC.ScheduleEndDT = wBSEventViewModel.ExpectFinishDT; // //wBSEventC.ScheduleServiceHours = wBSEventC.QuestionServiceHours; // wBSEventC.EventStatus = 30; //30任務已接受未排程 // wBSEventM.CaseMStatus = "3"; //3為已接受 // String ExpectArriveSW, EventStatusStr; // if (wBSEventC.ExpectArriveSW == "0") // ExpectArriveSW = "自行約定"; // else if (wBSEventC.ExpectArriveSW == "1") // ExpectArriveSW = "合約規定"; // else if (wBSEventC.ExpectArriveSW == "2") // ExpectArriveSW = "建議期望"; // else if (wBSEventC.ExpectArriveSW == "4") // ExpectArriveSW = "自派新單"; // else // ExpectArriveSW = "客戶指定"; // String ExpectArriveDTStr = wBSEventC.ExpectArriveDateTime.Value.ToString("yyyy/MM/dd HH:mm"); // if (wBSEventC.ExpectArriveSW == "0") // ExpectArriveDTStr = "自行約定"; // EventStatusStr = "已接受未排程"; // String UserID = db.ResponsibleClass.Where(x => x.ID == rID).Select(x => x.UserID).First(); // String UserName = db.ResponsibleClass.Where(x => x.ID == rID).Select(x => x.UserData2.UserName).First(); // ret[3] = db.ResponsibleClass.Where(x => x.ID == rID).Select(x => x.Name).First() + "-" + UserName; // String url = "http://" + wBSEventViewModel.Url + "/Mobile/MobileCaseDetail?type=2&&mid=" + wBSEventC.MomCaseID + "&&cid=" + wBSEventC.Num; // String title = ""; //[燈號]-[推播事件說明] // String content = ""; //[被推播人員姓名]您好:案件-[客戶簡稱]-[到達約定選擇]:[應到達時間],[事件說明],請您盡速處理。 // String sname = db.Customer.Find(wBSEventViewModel.CustomerRef).ShortName; // title = "綠燈-執行人已接受未排程"; // content = UserName + "您好:案件-" + sname + "-" + ExpectArriveSW + ":" + ExpectArriveDTStr + "," + EventStatusStr + ",請您盡速處理。"; // messageRepository.AddMsgbyUser(UserID, title, content, url); //} db.WBSEventM.Add(wBSEventM); db.WBSEventC.Add(wBSEventC); db.SaveChanges(); //ret = "true"; ret[0] = wBSEventViewModel.WBSCaseNumberM + "-" + wBSEventViewModel.WBSCaseNumberC; } catch { } return ret; }
//建立新叫修單 public string[] Create(WBSEventViewModel wBSEventViewModel) { string[] ret = new string[3]; ret[0] = "false"; ret[1] = ""; ret[2] = ""; //area int casecode = 0, caseID = 0, num = 0, childCaseID = 0; casecode = db.WBSEventM.AsEnumerable().Where(x => x.CaseClass == "C" && x.CaseDate == DateTime.Now.ToString("yyyyMMdd")).Select(x => x.CaseCode).DefaultIfEmpty(0).Max(x => x) + 1; caseID = db.WBSEventM.AsEnumerable().Select(x => x.CaseID).DefaultIfEmpty(0).Max(x => x) + 1; num = db.WBSEventC.AsEnumerable().Select(x => x.Num).DefaultIfEmpty(0).Max(x => x) + 1; childCaseID = db.WBSEventC.AsEnumerable().Where(x => x.MomCaseID == caseID).Select(x => x.ChildCaseID).DefaultIfEmpty(0).Max(x => x) + 1; int questionGrade = db.QuestionClass.AsEnumerable().Where(x => x.QuestionClassID == Int32.Parse(wBSEventViewModel.QuestionClass)).Select(x => x.QuestionGrade).First(); int serviceHours = db.QuestionClass.AsEnumerable().Where(x => x.QuestionClassID == Int32.Parse(wBSEventViewModel.QuestionClass)).Select(x => x.QuestionServiceHours).First(); string groupSW = db.Customer.AsEnumerable().Where(x => x.CustomerRef == wBSEventViewModel.CustomerRef).Select(x => x.GroupSW).First(); if (wBSEventViewModel.ExpectArriveDTStr == null) wBSEventViewModel.ExpectArriveDTStr = "19000101 00:01"; if (wBSEventViewModel.ExpectFinishDTStr == null) wBSEventViewModel.ExpectFinishDTStr = "19000101 00:01"; wBSEventViewModel.ExpectArriveDT = DateTime.ParseExact(wBSEventViewModel.ExpectArriveDTStr, "yyyyMMdd HH:mm", CultureInfo.InvariantCulture); wBSEventViewModel.ExpectFinishDT = DateTime.ParseExact(wBSEventViewModel.ExpectFinishDTStr, "yyyyMMdd HH:mm", CultureInfo.InvariantCulture); ret[2] = GetCustomerArea(wBSEventViewModel.CustomerRef); try { WBSEventM wBSEventM = new WBSEventM(); wBSEventM.CaseID = caseID; //wBSEventM.CaseClass = wBSEventViewModel.WBSCaseNumberM.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[0]; //wBSEventM.CaseClass = wBSEventViewModel.WBSCaseNumberM.Substring(0, 1); wBSEventM.CaseClass = "C"; //wBSEventM.CaseDate = wBSEventViewModel.WBSCaseNumberM.Substring(1, 8); wBSEventM.CaseDate = DateTime.Now.ToString("yyyyMMdd"); wBSEventM.CaseCode = casecode; wBSEventViewModel.WBSCaseNumberM = wBSEventM.CaseClass + wBSEventM.CaseDate + "-"; if (wBSEventM.CaseCode < 10) wBSEventViewModel.WBSCaseNumberM += "0000" + wBSEventM.CaseCode.ToString(); else if (wBSEventM.CaseCode < 100 && wBSEventM.CaseCode >= 10) wBSEventViewModel.WBSCaseNumberM += "000" + wBSEventM.CaseCode.ToString(); else if (wBSEventM.CaseCode < 1000 && wBSEventM.CaseCode >= 100) wBSEventViewModel.WBSCaseNumberM += "00" + wBSEventM.CaseCode.ToString(); else if (wBSEventM.CaseCode < 10000 && wBSEventM.CaseCode >= 1000) wBSEventViewModel.WBSCaseNumberM += "0" + wBSEventM.CaseCode.ToString(); else wBSEventViewModel.WBSCaseNumberM += wBSEventM.CaseCode.ToString(); wBSEventM.CustomerRef = wBSEventViewModel.CustomerRef; wBSEventM.CustomerUserID = wBSEventViewModel.CustomerUserID; wBSEventM.CustomerUserName = wBSEventViewModel.CustomerUserName; wBSEventM.CustomerUserPhone1 = wBSEventViewModel.CustomerUserPhone1; wBSEventM.CustomerUserPhone2 = wBSEventViewModel.CustomerUserPhone2; //20150811新增-Hsiuyang if (wBSEventViewModel.ChangeAddr != null) if (wBSEventViewModel.ChangeAddr.Trim().Length > 0) wBSEventM.CustomerAddr = wBSEventViewModel.ChangeAddr; wBSEventM.SpareMach = "R"; //預設無借出備機 wBSEventM.UserMach = "R"; //預設無取回客戶機器 wBSEventM.CaseMStatus = "1"; //1為開立新問題 WBSEventC wBSEventC = new WBSEventC(); ret[1] = num.ToString(); wBSEventC.Num = num; wBSEventC.MomCaseID = caseID; wBSEventC.ChildCaseID = childCaseID; wBSEventViewModel.WBSCaseNumberC = (wBSEventC.ChildCaseID < 10) ? ("0" + wBSEventC.ChildCaseID.ToString()) : wBSEventC.ChildCaseID.ToString(); wBSEventC.EventClass = "C01"; wBSEventC.ProductClass = Int32.Parse(wBSEventViewModel.ProductClass); wBSEventC.ItemClass = Int32.Parse(wBSEventViewModel.ItemClass); wBSEventC.QuestionClass = Int32.Parse(wBSEventViewModel.QuestionClass); wBSEventC.QuestionGrade = questionGrade; wBSEventC.QuestionServiceHours = serviceHours; wBSEventC.QuestionDescription = wBSEventViewModel.QuestionDescription; wBSEventC.QuestionCreateUserID = wBSEventViewModel.QuestionCreateUserID; wBSEventC.QuestionCreateDateTime = DateTime.Now; wBSEventC.ExpectArriveDateTime = wBSEventViewModel.ExpectArriveDT; wBSEventC.ExpectFinishDateTime = wBSEventViewModel.ExpectFinishDT; wBSEventC.ExpectArriveSW = wBSEventViewModel.ExpectArriveSW; wBSEventC.DeleteMarkSW = wBSEventViewModel.DeleteMarkSW; wBSEventC.DeleteReason = wBSEventViewModel.DeleteReason; wBSEventC.DeleteMarkUserID = wBSEventViewModel.DeleteMarkUserID; wBSEventC.DeleteMarkDateTime = wBSEventViewModel.DeleteMarkDT; wBSEventC.CreateDateTime = DateTime.Now; wBSEventC.CreateUserID = wBSEventViewModel.CreateUserID; wBSEventC.ModifyDateTime = DateTime.Now; wBSEventC.ModifyUserID = wBSEventViewModel.CreateUserID; //wBSEventC.ModifyDateTime = wBSEventViewModel.ModifyDT; //wBSEventC.ModifyUserID = wBSEventViewModel.ModifyUserID; //20150811新增-Hsiuyang wBSEventC.SugProvideSpareMach = wBSEventViewModel.SugProvideSpareMach; wBSEventC.SugRetrieveSpareMach = wBSEventViewModel.SugRetrieveSpareMach; wBSEventC.SugRetrieveUserMach = wBSEventViewModel.SugRetrieveUserMach; wBSEventC.SugReturnUserMach = wBSEventViewModel.SugReturnUserMach; wBSEventC.EventStatus = 11; //11為問題已開立 //20150813新增-Hsiuyang if (wBSEventViewModel.Closed == "T") //線上處理結案影響 { wBSEventM.CaseMStatus = "9"; //9為問題已結案 wBSEventM.CloseDT = DateTime.Now; wBSEventC.EventStatus = 50; //50為任務已解決(維修附件上傳) wBSEventC.QuestionFinishSW = "Y"; wBSEventC.QuestionFinishDT = DateTime.Now; wBSEventC.ServiceReport = wBSEventViewModel.AssignDescription; //當結案時解決方式即為服務報告 } wBSEventC.AssignDescription = wBSEventViewModel.AssignDescription; //解決方式(派單)描述 //20150812新增-Hsiuyang-SugProduct建議部分 JArray SugProduct = JsonConvert.DeserializeObject<JArray>(wBSEventViewModel.MaterialJson); for (int i = 0; i < SugProduct.Count; i++) { SugProduct sugProduct = new SugProduct(); sugProduct.CID = wBSEventC.Num; sugProduct.Class = Int32.Parse(SugProduct[i]["Class"].ToString()); //sugProduct.Class = Int32.Parse(SugProduct[i][0].ToString()); //if (SugProduct[i][1].ToString() == "") if (SugProduct[i]["ProductNum"].ToString() == "") sugProduct.ProductName = SugProduct[i]["ProductName"].ToString(); //sugProduct.ProductName = SugProduct[i][2].ToString(); else sugProduct.ProductNum = Int32.Parse(SugProduct[i]["ProductNum"].ToString()); //sugProduct.ProductNum = Int32.Parse(SugProduct[i][1].ToString()); db.SugProduct.Add(sugProduct); } //20150813新增-Hsiuyang-解決方式知識庫附件 JArray KnowledgeData = JsonConvert.DeserializeObject<JArray>(wBSEventViewModel.KnowledgeJson); for (int i = 0; i < KnowledgeData.Count; i++) { Files knowledgefile = new Files(); knowledgefile.CID = wBSEventC.Num; knowledgefile.Class = 3; knowledgefile.FileAddr = ""; knowledgefile.FileName = ""; //knowledgefile.KnowledgeID = Int32.Parse(KnowledgeData[i][0].ToString()); knowledgefile.KnowledgeID = Int32.Parse(KnowledgeData[i]["KnowledgeID"].ToString()); db.Files.Add(knowledgefile); } //20150814新增-Hsiuyang-執行預先保養單 JArray maintainCases = JsonConvert.DeserializeObject<JArray>(wBSEventViewModel.MaintainCaseJson); for (int i = 0; i < maintainCases.Count; i++) { EventRelation maintainCase = new EventRelation(); maintainCase.CID = wBSEventC.Num; maintainCase.RelationCID = Int32.Parse(maintainCases[i]["cID"].ToString()); db.EventRelation.Add(maintainCase); } db.WBSEventM.Add(wBSEventM); db.WBSEventC.Add(wBSEventC); db.SaveChanges(); //ret = "true"; ret[0] = wBSEventViewModel.WBSCaseNumberM + "-" + wBSEventViewModel.WBSCaseNumberC; } catch { } return ret; }