public Message InsertMulti(List<STT> list,string resultDate,string userName) { Message msg = null; DbTransaction trans = null; try { dbContext.Connection.Open(); trans = dbContext.Connection.BeginTransaction(); dbContext.Transaction = trans; if (list.Count > 0) { dbContext.STTs.InsertAllOnSubmit(list); dbContext.SubmitChanges(); msg = new Message(MessageConstants.I0001, MessageType.Info, list.Count.ToString() + " STT(s)", "insert"); trans.Commit(); List<STT_RefResult> listRef = new List<STT_RefResult>(); string[] arrayDate = resultDate.TrimEnd(',').Split(','); int index = 0; foreach (STT item in list) { if (item.ResultId.HasValue) { STT_RefResult objUI = new STT_RefResult(); objUI.SttID = item.ID; objUI.ResultId = item.ResultId.Value; objUI.EndDate = DateTime.Parse(arrayDate[index]); objUI.CreatedBy = userName; objUI.CreatedDate = DateTime.Now; objUI.UpdatedBy = userName; objUI.UpdatedDate = DateTime.Now; objUI.DeleteFlag = false; listRef.Add(objUI); index++; } } new STTRefResultDao().InsertMulti(listRef); } else { if (trans != null) trans.Rollback(); msg = new Message(MessageConstants.E0007, MessageType.Error); } } catch { if (trans != null) trans.Rollback(); // Show system error msg = new Message(MessageConstants.E0007, MessageType.Error); } return msg; }
public void WriteLogForEditResult(STT_RefResult newInfo, ELogAction action) { try { if (newInfo == null) { return; } bool isUpdated = false; MasterLog objMasterLog = new MasterLog(); string logId = commonDao.UniqueId; commonDao.InsertMasterLog(logId, newInfo.UpdatedBy, ELogTable.STT.ToString(), action.ToString()); STT oldSTTInfo = new STTDao().GetById(newInfo.SttID); STT_RefResult oldInfo = new STTRefResultDao().GetById(newInfo.SttID); if ((oldSTTInfo != null) && (newInfo != null) && (logId != null)) { if (oldInfo.Remarks != newInfo.Remarks) { commonDao.InsertLogDetail(logId, "Remarks", "Remarks", oldInfo.Remarks, newInfo.Remarks); isUpdated = true; } if (oldInfo.Attachfile != newInfo.Attachfile) { //string[] arrayNew = newInfo.Attachfile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX); //foreach (string fileNew in arrayNew) //{ // if (!oldInfo.Attachfile.Contains(fileNew)) // { // commonDao.InsertLogDetail(logId, "AttachFile", "Attach File", "", fileNew); // isUpdated = true; // } //} string[] Attachfile = newInfo.Attachfile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX); foreach (string item in oldInfo.Attachfile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX))//case delete file { if (!newInfo.Attachfile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX).Contains(item)) { commonDao.InsertLogDetail(logId, "AttachFile", "Attach File", item, ""); isUpdated = true; } } foreach (string fileNew in Attachfile) //case add new file { if (!oldInfo.Attachfile.Contains(fileNew)) { commonDao.InsertLogDetail(logId, "AttachFile", "Attach File", "", fileNew); isUpdated = true; } } } if (oldInfo.ResultId != newInfo.ResultId) { if (newInfo.ResultId == Constants.STT_RESULT_FAIL) { isUpdated = true; commonDao.InsertLogDetail(logId, "ResultId", "Result", oldInfo.STT_Result.Name,new STTResultDao().GetById(newInfo.ResultId).Name); commonDao.InsertLogDetail(logId, "STTStatusId", "Status", oldSTTInfo.STT_Status.Name, new STTStatusDao().GetById(Constants.STT_STATUS_REJECTED).Name); } if (newInfo.ResultId == Constants.STT_RESULT_PASS) { isUpdated = true; commonDao.InsertLogDetail(logId, "ResultId", "Result", oldInfo.STT_Result.Name, new STTResultDao().GetById(newInfo.ResultId).Name); commonDao.InsertLogDetail(logId, "STTStatusId", "Status", oldSTTInfo.STT_Status.Name, new STTStatusDao().GetById(Constants.STT_STATUS_NEED_TO_PROMOTED).Name); } } if (oldInfo.EndDate != newInfo.EndDate) { isUpdated = true; commonDao.InsertLogDetail(logId, "EndDate", "End Date", oldInfo.EndDate.ToString(Constants.DATETIME_FORMAT_VIEW), newInfo.EndDate.ToString(Constants.DATETIME_FORMAT_VIEW)); } // Insert Key Name if (isUpdated) { string key = oldSTTInfo.ID + " [" + oldSTTInfo.FirstName + " " + oldSTTInfo.MiddleName + " " + oldSTTInfo.LastName + "]"; commonDao.InsertLogDetail(logId, "STT_ID", "Key for Update", key, null); } else { commonDao.DeleteMasterLog(logId); } } } catch (Exception ex) { throw ex; } }
public void WriteLogForUpdateResult(STT_RefResult newInfo, ELogAction action) { try { if (newInfo == null) { return; } MasterLog objMasterLog = new MasterLog(); string logId = commonDao.UniqueId; commonDao.InsertMasterLog(logId, newInfo.UpdatedBy, ELogTable.STT.ToString(), action.ToString()); STT oldSTTInfo = new STTDao().GetById(newInfo.SttID); if ((oldSTTInfo != null) && (newInfo != null) && (logId != null)) { if (newInfo.ResultId != oldSTTInfo.ResultId) { commonDao.InsertLogDetail(logId, "ResultId", "Result", oldSTTInfo.ResultId.HasValue?oldSTTInfo.STT_Result.Name:"", new STTResultDao().GetById(newInfo.ResultId).Name); if (newInfo.ResultId == Constants.STT_RESULT_FAIL) { commonDao.InsertLogDetail(logId, "STTStatusId", "Status", oldSTTInfo.STT_Status.Name, new STTStatusDao().GetById(Constants.STT_STATUS_REJECTED).Name); } else { commonDao.InsertLogDetail(logId, "STTStatusId", "Status", oldSTTInfo.STT_Status.Name, new STTStatusDao().GetById(Constants.STT_STATUS_NEED_TO_PROMOTED).Name); } } commonDao.InsertLogDetail(logId, "EndDate", "End Date", null, newInfo.EndDate.ToString(Constants.DATETIME_FORMAT_VIEW)); if (!string.IsNullOrEmpty(newInfo.Remarks)) { commonDao.InsertLogDetail(logId, "Remarks", "Remarks", null, newInfo.Remarks); } string[] array = newInfo.Attachfile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX); if (array.Count() > 0) { foreach (string item in array) { commonDao.InsertLogDetail(logId, "AttachFile", "Attach File", null, item); } } // Insert Key Name string key = oldSTTInfo.ID + " [" + oldSTTInfo.FirstName + " " + oldSTTInfo.MiddleName + " " + oldSTTInfo.LastName + "]"; commonDao.InsertLogDetail(logId, "ID", "Key for Update", key, null); } } catch (Exception ex) { throw ex; } }
public void WriteLogForRemoveAttachFile(STT_RefResult newInfo, ELogAction action) { try { bool isUpdated = false; if (newInfo == null) { return; } MasterLog objMasterLog = new MasterLog(); string logId = commonDao.UniqueId; commonDao.InsertMasterLog(logId, newInfo.UpdatedBy, ELogTable.STT.ToString(), action.ToString()); STT_RefResult oldInfo = new STTRefResultDao().GetById(newInfo.SttID); if ((oldInfo != null) && (newInfo != null) && (logId != null)) { foreach (string item in oldInfo.Attachfile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX)) { if (!newInfo.Attachfile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX).Contains(item)) { commonDao.InsertLogDetail(logId, "AttachFile", "Attach File", item, ""); isUpdated = true; } } if (isUpdated) { // Insert Key Name STT obj = new STTDao().GetById(oldInfo.SttID); string key = oldInfo.SttID + " [" + obj.FirstName + " " + obj.MiddleName + " " + obj.LastName + "]"; commonDao.InsertLogDetail(logId, "STT_ID", "Key for Delete", key, null); } else { commonDao.DeleteMasterLog(logId); } } } catch (Exception ex) { throw ex; } }