/// <summary> /// Generate model object from csv file by using ImportCsvModelMapping.xml /// List<CsvParseSetPropertyError> setPropertyError = new List<CsvParseSetPropertyError>(); /// List<tbt_tmpImportContent> tmpImportContent = CSVReportUtil2.GenerateModelofCsvData<tbt_tmpImportContent>(session.CsvData, out setPropertyError); /// </summary> /// <typeparam name="T">Model</typeparam> /// <param name="csvData">Input: csv data, seperated by each line</param> /// <param name="setPropertyError">Output: Unable set property (Error)</param> /// <returns>List of model object</returns> public static List <T> GenerateModelofCsvData <T>(List <string> csvData, out List <CsvParseSetPropertyError> setPropertyError, string dateFormat = null) where T : class { List <T> resultModels = new List <T>(); Type type = typeof(T); bool canSetValue = false; setPropertyError = new List <CsvParseSetPropertyError>(); var csvQuery = from line in csvData let data = line.CsvSplit() select data; if (csvQuery.Count() > 1) { string propertyName = ""; string value = ""; PropertyInfo[] props = type.GetProperties(); PropertyInfo prop = null; string[] csvColName = csvQuery.ElementAt(0); //first line in csv file int xmlModelIndex = 0; bool isMatchModelName = false; //Get Xml template file XmlDocument doc = new XmlDocument(); string filePath = CommonUtil.WebPath + SECOM_AJIS.Common.Util.ConstantValue.CommonValue.IMPORT_CSV_MODEL_MAPPING_FILE; doc.Load(filePath); XmlNodeList nodes = doc.SelectNodes("models/model"); #region Validate //Check Model name for (int m = 0; m < nodes.Count; m++) { if (nodes[m].Attributes["name"].Value == typeof(T).Name) { xmlModelIndex = m; isMatchModelName = true; break; } } if (!isMatchModelName) { throw new CsvParseException("Was not found model name in xml config file."); } //Check no. of column int csvColumnCount = csvColName.Count(); int xmlColumnCount = nodes[xmlModelIndex].ChildNodes.Count; if (csvColumnCount != xmlColumnCount) { throw new CsvParseException("No. of column in csv file isn't equal no. of column in xml config file."); } //Check column name for (int c = 0; c < xmlColumnCount; c++) { string xmlColName = nodes[xmlModelIndex].ChildNodes[c].Attributes["name"].Value; if (xmlColName == null) { throw new CsvParseException("Column name in xml config file is empty."); } prop = props.Where(p => p.Name.Equals(xmlColName)).FirstOrDefault(); if (prop == null) { throw new CsvParseException("Column name in xml config file is invalid."); } } #endregion #region Set value for (int l = 1; l < csvQuery.Count(); l++) //Start at line 2 { T item = Activator.CreateInstance <T>(); for (int c = 0; c < xmlColumnCount; c++) { propertyName = nodes[xmlModelIndex].ChildNodes[c].Attributes["name"].Value; value = csvQuery.ElementAt(l)[c]; prop = props.Where(p => p.Name.Equals(propertyName)).First(); canSetValue = CommonUtil.SetObjectValue(item, propertyName, value != string.Empty ? value : null, dateFormat); if (canSetValue == false) { setPropertyError.Add(new CsvParseSetPropertyError() { Line = l, Column = c + 1, CsvColumnName = csvQuery.ElementAt(0)[c], Value = value, PropertyName = propertyName, PropertyType = prop.GetType() }); } } resultModels.Add(item); } #endregion } return(resultModels); }
/// <summary> /// Generate custom combobox (include first element) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id"></param> /// <param name="lst"></param> /// <param name="display"></param> /// <param name="value"></param> /// <param name="firstElement"></param> /// <param name="attribute"></param> /// <param name="include_idx0"></param> /// <returns></returns> public static MvcHtmlString CommonComboBoxWithCustomFirstElement <T>(string id, List <T> lst, string display, string value, string firstElement, object attribute = null, bool include_idx0 = true) where T : class { string currentLang = CommonUtil.GetCurrentLanguage(); string sVal = null; //MessageModel all = MessageUtil.GetMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0120); // ---All--- //MessageModel select = MessageUtil.GetMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0113); // ---Select-- string strFirstElemText; if (string.IsNullOrWhiteSpace(firstElement) || firstElement.ToUpper() == COMBO_FIRSTELEMTXT_SELECT) { //strFirstElemText = CommonUtil.GetLabelFromResource("Common", "CMS030", "lblComboboxSelect"); strFirstElemText = CommonUtil.GetLabelFromResource("Common", "CommonResources", "lblComboboxSelect"); } else if (firstElement.ToUpper() == COMBO_FIRSTELEMTXT_ALL) { //strFirstElemText = CommonUtil.GetLabelFromResource("Common", "CMS030", "lblComboboxAll"); strFirstElemText = CommonUtil.GetLabelFromResource("Common", "CommonResources", "lblComboboxAll"); } else if (firstElement.ToUpper() == COMBO_FIRSTELEMTXT_CUSTOM_SELECT) { //strFirstElemText = CommonUtil.GetLabelFromResource("Common", "CMS030", "lblComboboxAll"); strFirstElemText = CommonUtil.GetLabelFromResource("Common", "CommonResources", "lblComboboxCUSTOM_SELECT"); } else if (firstElement.ToUpper() == COMBO_FIRSTELEMTXT_NONE) { //strFirstElemText = CommonUtil.GetLabelFromResource("Common", "CMS030", "lblComboboxAll"); strFirstElemText = COMBO_FIRSTELEMTXT_CUSTOM_NONE; } else { strFirstElemText = firstElement; } var selectBuilder = new TagBuilder("select"); selectBuilder.MergeAttribute("id", id); selectBuilder.MergeAttribute("name", id); if (attribute != null) { PropertyInfo[] prop = attribute.GetType().GetProperties(); if (prop != null) { if (prop.Length > 0) { Dictionary <string, string> dic = new Dictionary <string, string>(); foreach (PropertyInfo p in prop) { object o = p.GetValue(attribute, null); if (o != null) { if (p.Name == "selected") { //sVal = (string)o; sVal = o.ToString(); } else { //dic.Add(p.Name, (String)o); dic.Add(p.Name, o.ToString()); } } } SetHtmlTagAttribute(selectBuilder, dic); } } } if (include_idx0) { var fOptionBuilder = new TagBuilder("option"); fOptionBuilder.MergeAttribute("value", ""); fOptionBuilder.InnerHtml = strFirstElemText; selectBuilder.InnerHtml += fOptionBuilder.ToString(TagRenderMode.Normal); } if (lst != null) { foreach (T et in lst) { PropertyInfo propD = et.GetType().GetProperty(display); PropertyInfo propV = et.GetType().GetProperty(value); PropertyInfo propS = et.GetType().GetProperty("Selected"); if (propD != null && propV != null) { if (propV.GetValue(et, null) != null && propD.GetValue(et, null) != null) { var optionBuilder = new TagBuilder("option"); optionBuilder.MergeAttribute("value", Encoder.HtmlEncode(propV.GetValue(et, null).ToString())); optionBuilder.InnerHtml = Encoder.HtmlEncode(propD.GetValue(et, null).ToString()); string tt = optionBuilder.ToString(TagRenderMode.Normal); if (sVal != null) { if (sVal == propV.GetValue(et, null).ToString()) { string chk = "<option "; int idx = tt.IndexOf(chk); if (idx >= 0) { tt = tt.Substring(0, chk.Length) + "selected=\"true\" " + tt.Substring(chk.Length); } } } if (propS != null) { if ((bool)propS.GetValue(et, null) == true) { string chk = "<option "; int idx = tt.IndexOf(chk); if (idx >= 0) { tt = tt.Substring(0, chk.Length) + "selected=\"true\" " + tt.Substring(chk.Length); } } } selectBuilder.InnerHtml += tt; } } } } return(MvcHtmlString.Create(selectBuilder.ToString(TagRenderMode.Normal))); }
public void Execute(JobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; List <BatchProcessRunAll_Result> list = (List <BatchProcessRunAll_Result>)dataMap.Get("BatchList"); string UserId = dataMap.GetString("UserId"); DateTime BatchDate = dataMap.GetDateTime("BatchDate"); BatchWriteLogDel writeLog = (BatchWriteLogDel)dataMap.Get("WriteLog"); try { //=== start 'run batch all' === doBatchProcessResult allResult_start = new doBatchProcessResult(); allResult_start.BatchName = "Run All Batch"; allResult_start.BatchUser = UserId; allResult_start.BatchStatus = BatchStatus.C_BATCH_STATUS_PROCESSING; allResult_start.BatchCode = "AL"; allResult_start.BatchJobName = ""; allResult_start.BatchDate = DateTime.Now; writeLog(allResult_start); foreach (BatchProcessRunAll_Result s in list) { doBatchProcessResult result = CommonUtil.CloneObject <BatchProcessRunAll_Result, doBatchProcessResult>(s); try { string[] batchJobName = s.BatchJobName.Split(','); string assemblyName = batchJobName[0]; string typeName = assemblyName + '.' + batchJobName[1]; result.BatchStatus = BatchStatus.C_BATCH_STATUS_PROCESSING; writeLog(result); Assembly assembly = Assembly.Load(assemblyName + ", Version=0.0.0.0, PublicKeyToken=null,Culture=neutral"); Type type = assembly.GetType(typeName); IBatchProcess process = (IBatchProcess)Activator.CreateInstance(type); result = process.WorkProcess(UserId, BatchDate); // == add by Narupon == result.BatchCode = s.BatchCode; result.BatchName = s.BatchName; result.BatchJobName = s.BatchJobName; result.BatchDate = DateTime.Now; if (result.Result) { result.BatchStatus = BatchStatus.C_BATCH_STATUS_SUCCEEDED; } else { result.BatchStatus = BatchStatus.C_BATCH_STATUS_FAILED; } // == (end) add by Narupon == result.BatchUser = UserId; writeLog(result); } catch (Exception ex) { result.ErrorMessage += string.Format("Error: {0} {1}\n", ex.Message, ex.InnerException != null ? ex.InnerException.Message : ""); result.BatchStatus = BatchStatus.C_BATCH_STATUS_FAILED; writeLog(result); } } //=== finish 'run batch all' === doBatchProcessResult allResult_finish = new doBatchProcessResult(); allResult_finish.BatchName = "Run All Batch"; allResult_finish.BatchUser = UserId; allResult_finish.BatchStatus = BatchStatus.C_BATCH_STATUS_SUCCEEDED; allResult_finish.BatchCode = "AL"; allResult_finish.BatchJobName = ""; allResult_finish.BatchDate = DateTime.Now; writeLog(allResult_finish); } catch (Exception ex) { doBatchProcessResult errorResult = new doBatchProcessResult(); errorResult.BatchCode = null; errorResult.ErrorMessage = ex.Message; errorResult.BatchUser = UserId; errorResult.BatchStatus = BatchStatus.C_BATCH_STATUS_FAILED; writeLog(errorResult); throw ex; } finally { context.Scheduler.Shutdown(); } }
public static MvcHtmlString CommonComboBox <T>(string id, List <T> lst, string display, string[] value, object attribute = null, bool include_idx0 = true) where T : class { string currentLang = CommonUtil.GetCurrentLanguage(); var selectBuilder = new TagBuilder("select"); selectBuilder.MergeAttribute("id", id); selectBuilder.MergeAttribute("name", id); if (attribute != null) { SetHtmlTagAttribute(selectBuilder, attribute); } if (lst != null) { if (lst.Count > 0 && include_idx0) { var fOptionBuilder = new TagBuilder("option"); fOptionBuilder.MergeAttribute("value", ""); //MessageModel select = MessageUtil.GetMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0113); string strSelect = CommonUtil.GetLabelFromResource("Common", "CMS030", "lblComboboxSelect"); fOptionBuilder.InnerHtml = strSelect; selectBuilder.InnerHtml += fOptionBuilder.ToString(TagRenderMode.Normal); } foreach (T et in lst) { PropertyInfo propD = et.GetType().GetProperty(display); if (propD != null) { if (propD.GetValue(et, null) != null) { bool valIsSet = false; if (value != null) { if (value.Length > 0) { valIsSet = true; } } string valSet = string.Empty; if (valIsSet) { foreach (string val in value) { PropertyInfo propV = et.GetType().GetProperty(val); if (propV != null) { if (propV.GetValue(et, null) != null) { if (valSet != string.Empty) { valSet += ","; } valSet += propV.GetValue(et, null).ToString(); } } } } var optionBuilder = new TagBuilder("option"); optionBuilder.MergeAttribute("value", valSet); optionBuilder.InnerHtml = propD.GetValue(et, null).ToString(); selectBuilder.InnerHtml += optionBuilder.ToString(TagRenderMode.Normal); } } } } return(MvcHtmlString.Create(selectBuilder.ToString(TagRenderMode.Normal))); }