public void TestMethod1() { using (ISession session = NHibernateHelper.OpenSession()) { ICriteria criteria = session.CreateCriteria <Requests>().SetFirstResult(10).SetMaxResults(25); var rowcount = CriteriaTransformer.Clone(criteria).SetProjection(Projections.RowCount()); System.Diagnostics.Debug.WriteLine("rowcount ::: " + rowcount.FutureValue <int>().Value); IList <Requests> list = criteria.List <Requests>(); var i = 0; foreach (var it in list) { System.Diagnostics.Debug.WriteLine("Child ::: " + ++i + ". " + it.RequestId); } var sReqAct = new RequestActivities(); //sReqAct.RequestActivityId = new Guid(); sReqAct.RequestId = new Guid(); sReqAct.ActivityDetail = "สร้างใบงานใหม่"; //สร้างใบงานใหม่ sReqAct.ActivityType = "CN"; sReqAct.ContactFeeling = ""; sReqAct.InternalFlag = "1"; //ไม่ต้องการแสดง status ที่ผู้ร้องเรียน sReqAct.ActionBy = new Guid(); sReqAct.ActionDate = ""; sReqAct.RequestStatus = "N"; sReqAct.ProgressId = 0; sReqAct.AckFlag = ""; sReqAct.ActiveFlag = "1"; sReqAct.ActivityDate = ""; sReqAct.ActivityPersonName = "PersonName"; sReqAct.ActivityPriority = "N"; sReqAct.ContactFlow = ""; //sReqAct.RunningSort = 0; Console.WriteLine("yy--------------"); session.Save(sReqAct); session.Flush(); Console.WriteLine("rr"); } }
private JsonData createRequest(RequestData data) { JsonData jd = new JsonData(); var jss = new JavaScriptSerializer(); using (ISession session = NHibernateHelper.OpenSession()) using (var trans = session.BeginTransaction()) { try { var categoryId = Convert.ToInt32(ConfigurationManager.AppSettings["REQUEST_CATAGERY_ID"]); var requestCategory = session.Get <RequestCategories>(categoryId); string openDate = DateTime.Now.ToString(Global.DATE_TIME_FORMAT); var contact = session.Get <Contacts>(data.ContactId); var contactId = contact.ContactId; var LogBy = data.LogBy; // Guid.Parse(ConfigurationManager.AppSettings["DUMMYUSER"]); var agent = session.Get <Agents>(LogBy); Guid LogByGroup = Guid.Empty; string AgentName = ""; string AgentGroupName = ""; if (agent != null) { LogByGroup = agent.AgentGroupId.GetValueOrDefault(); AgentName = agent.AgentName; AgentGroupName = session.Get <AgentGroups>(agent.AgentGroupId).GroupName; } var cultureInfo = Global.THAI_CULTUREINFO; var BookDate = (data.OpenDate != null) ? DateTime.ParseExact(data.OpenDate, "dd/MM/yyyy", cultureInfo).ToString(Global.DATE_FORMAT) : openDate; var expireDate = DateTime.Today; var expireDateTxt = expireDate.ToString(Global.DATE_TIME_FORMAT); var prefix = session.CreateQuery("from Prefix where ObjectType=?").SetParameter(0, "R").UniqueResult <Prefix>(); int Prefixnum = Convert.ToInt32(prefix.ObjectRunningId); string Prefix = prefix.ObjectRunningId; string ReqPrefix = prefix.ObjectPrefix; string yearnow = DateTime.Today.ToString("yyMM", new System.Globalization.CultureInfo("en-US")); //string shortCode = Convert.ToString(iDbX.ExecuteScalar("SELECT short_code FROM request_categories WHERE req_category_id = " + sReq.category_id)); ReqPrefix = ReqPrefix.Trim() + yearnow.Trim() + Prefix.Trim(); //ปีเด Prefixnum += 1; prefix.ObjectRunningId = Prefixnum.ToString().PadLeft(Prefix.Trim().Length, '0'); session.Update(prefix); var requests = new Requests { RequestNumber = ReqPrefix, ContactId = contactId, PersonName = data.PersonName, CategoryId = requestCategory.ReqCategoryId, RequestStatus = "N", RequestPriority = "N", AssigneeGroupId = LogByGroup, AssigneeId = agent.AgentId, ContactFeeling = "", ProductId = null, RequestDetail = data.RequestDetail, RequestDetail2 = "", OpenDate = openDate, ExpireFlag = "", LogBy = agent.AgentId, ActiveFlag = "1", ContactClass = "", EscalateRound = 0, ChannelType = "LI", KbNumber = "", FirstClose = "", ReopenDate = "", ReopenReason = "", PolicyNumber = "", LastupdateProgress = "", RequestPhone = "", AlertExpireFlag = "", ViewDate = "", SurveyResult = 0, SurveyNote = "", Corrective = "", Preventive = "", DelayReasonId = 0, UncontrollableFlag = "", ServiceFlag = "", CloseType = 0, OpenTime = "", SurveyDate = "", Open2Date = "", LastupdateAgent = "", LastupdateCust = "", ComplaintStore = 0, CommercialGroup = "", MediaType = 0, MediaName = 0, AssigneeLastView = "", SupCheckFlag = "", SupComment = "", ReserveField1 = "", ReserveFlag1 = "", ReserveField2 = "", ReserverFlag2 = "", FollowFlag = "", ComplaintTo = "", LastEscalateDate = "", ComplaintToName = "", EscalateCount = 0, HiddencustFlag = "", ImpactArea1 = 0, ImpactArea2 = 0, ImpactAreaDetail = "" }; var requestId = (Guid)session.Save(requests); string attachmentList = data.AttachmentList; //:["10077","10078"] if (attachmentList != null && attachmentList != "") { Hashtable[] attachs = jss.Deserialize <Hashtable[]>(attachmentList); for (int i = 0; i < attachs.Length; i++) { var attachId = Convert.ToInt32(attachs[i]["id"].ToString()); var objAttachment = session.Get <Attachments>(attachId); if (objAttachment.RelateId == null) { objAttachment.RelateId = requestId; objAttachment.Description = attachs[i]["description"].ToString(); session.Update(objAttachment); } else { var attachment = new Attachments(); attachment.RelateType = objAttachment.RelateType; attachment.RelateId = requestId; attachment.FileName = objAttachment.FileName; attachment.OriginalFilename = objAttachment.OriginalFilename; attachment.FolderName = objAttachment.FolderName; attachment.FileType = objAttachment.FileType; attachment.FileDate = objAttachment.FileDate; attachment.FileSize = objAttachment.FileSize; attachment.Description = objAttachment.Description; attachment.CreateBy = objAttachment.CreateBy; attachment.ActiveFlag = objAttachment.ActiveFlag; jd.refId = session.Save(attachment).ToString(); } } } var sReqAct = new RequestActivities(); sReqAct.RequestId = requestId; sReqAct.ActivityDetail = Properties.Resources.newRequest + " / " + agent.AgentName; //สร้างใบงานใหม่ sReqAct.ActivityType = "CN"; sReqAct.ContactFeeling = requests.ContactFeeling; sReqAct.InternalFlag = "1"; //ไม่ต้องการแสดง status ที่ผู้ร้องเรียน sReqAct.ActionBy = LogBy; sReqAct.ActionDate = openDate; sReqAct.RequestStatus = requests.RequestStatus; sReqAct.ProgressId = 0; sReqAct.AckFlag = ""; sReqAct.ActiveFlag = "1"; sReqAct.ActivityDate = openDate; sReqAct.ActivityPersonName = requests.PersonName; sReqAct.ActivityPriority = requests.RequestPriority; sReqAct.ContactFlow = ""; sReqAct.RunningSort = 0; session.Save(sReqAct); trans.Commit(); jd.msg = requests.RequestNumber; jd.refId = requests.RequestId.ToString(); } catch (Exception ex) { trans.Rollback(); jd.success = false; jd.msg = ex.Message; } } return(jd); }
private JsonData updateRequest(RequestData data) { JsonData jd = new JsonData(); var jss = new JavaScriptSerializer(); using (ISession session = NHibernateHelper.OpenSession()) using (var trans = session.BeginTransaction()) { try { string openDate = DateTime.Now.ToString(Global.DATE_TIME_FORMAT); var contact = session.Get <Contacts>(data.ContactId); var contactId = contact.ContactId; var LogBy = data.LogBy; // Guid.Parse(ConfigurationManager.AppSettings["DUMMYUSER"]); var agent = session.Get <Agents>(LogBy); Guid LogByGroup = Guid.Empty; string AgentName = ""; string AgentGroupName = ""; if (agent != null) { LogByGroup = agent.AgentGroupId.GetValueOrDefault(); AgentName = agent.AgentName; AgentGroupName = session.Get <AgentGroups>(agent.AgentGroupId).GroupName; } var cultureInfo = Global.THAI_CULTUREINFO; var BookDate = (data.OpenDate != null) ? DateTime.ParseExact(data.OpenDate, "dd/MM/yyyy", cultureInfo).ToString(Global.DATE_FORMAT) : openDate; var expireDate = DateTime.Today; var expireDateTxt = expireDate.ToString(Global.DATE_TIME_FORMAT); var requests = session.CreateQuery("from Requests where RequestNumber=?") .SetParameter(0, data.RequestNumber) .UniqueResult <Requests>(); //requests.RequestDetail = data.RequestDetail; session.SaveOrUpdate(requests); var requestId = requests.RequestId; string attachmentList = data.AttachmentList; //:["10077","10078"] if (attachmentList != null && attachmentList != "") { Hashtable[] attachs = jss.Deserialize <Hashtable[]>(attachmentList); for (int i = 0; i < attachs.Length; i++) { var attachId = Convert.ToInt32(attachs[i]["id"].ToString()); var objAttachment = session.Get <Attachments>(attachId); if (objAttachment.RelateId == null) { objAttachment.RelateId = requestId; objAttachment.Description = attachs[i]["description"].ToString(); session.Update(objAttachment); } else { var attachment = new Attachments(); attachment.RelateType = objAttachment.RelateType; attachment.RelateId = requestId; attachment.FileName = objAttachment.FileName; attachment.OriginalFilename = objAttachment.OriginalFilename; attachment.FolderName = objAttachment.FolderName; attachment.FileType = objAttachment.FileType; attachment.FileDate = objAttachment.FileDate; attachment.FileSize = objAttachment.FileSize; attachment.Description = objAttachment.Description; attachment.CreateBy = objAttachment.CreateBy; attachment.ActiveFlag = objAttachment.ActiveFlag; jd.refId = session.Save(attachment).ToString(); } } } var sReqAct = new RequestActivities(); sReqAct.RequestId = requestId; sReqAct.ActivityDetail = Properties.Resources.editRequest + " -> " + data.RequestDetail; //สร้างใบงานใหม่ sReqAct.ActivityType = "CN"; sReqAct.ContactFeeling = requests.ContactFeeling; sReqAct.InternalFlag = "1"; //ไม่ต้องการแสดง status ที่ผู้ร้องเรียน sReqAct.ActionBy = LogBy; sReqAct.ActionDate = openDate; sReqAct.RequestStatus = requests.RequestStatus; sReqAct.ProgressId = 0; sReqAct.AckFlag = ""; sReqAct.ActiveFlag = "1"; sReqAct.ActivityDate = openDate; sReqAct.ActivityPersonName = requests.PersonName; sReqAct.ActivityPriority = requests.RequestPriority; sReqAct.ContactFlow = ""; sReqAct.RunningSort = 0; session.Save(sReqAct); trans.Commit(); jd.msg = requests.RequestNumber; jd.refId = requests.RequestId.ToString(); } catch (Exception ex) { trans.Rollback(); jd.success = false; jd.msg = ex.Message; } } return(jd); }