public void SetParameter(int order, string param) { if (CommonUtil.IsNullOrEmpty(param)) { return; } if (this.ParamList == null) { this.ParamList = new List <ParameterObject>(); } bool isfound = false; foreach (ParameterObject p in this.ParamList) { if (p.Parameter == param) { isfound = true; break; } } if (isfound == false) { this.ParamList.Add(new ParameterObject() { Order = order, Parameter = param }); } }
/// <summary> /// Convert billing code from long <-> short /// </summary> /// <param name="code"></param> /// <param name="ctype"></param> /// <returns></returns> public string ConvertBillingCode(string code, CONVERT_TYPE ctype) { if (CommonUtil.IsNullOrEmpty(code) == false) { if (code.StartsWith("P") || code.StartsWith("p")) { return(code); } } return(ConvertCode(code, ctype, ConstantValue.CommonValue.BILLING_CODE_SHORT_DIGIT, ConstantValue.CommonValue.BILLING_CODE_LONG_DIGIT)); }
public static T GetScreenParameter <T>(string key) where T : new() { try { T param = default(T); if (CommonUtil.IsNullOrEmpty(key) == false) { string sessionKey = string.Format("{0}.{1}", ConstantValue.CommonValue.SESSION_SCREEN_PARAMETER_KEY, key); param = GetSession <T>(sessionKey); } return(param); } catch (Exception) { throw; } }
/// <summary> /// Add error message /// </summary> /// <param name="controller"></param> /// <param name="screen"></param> /// <param name="module"></param> /// <param name="code"></param> /// <param name="id"></param> /// <param name="param"></param> public void AddErrorMessage(string controller, string screen, string module, MessageUtil.MessageList code, string id, params string[] param) { try { if (_iValidatorUtil.ModelState != null) { string template = string.Empty; if (CommonUtil.IsNullOrEmpty(controller) == false) { template += controller; } template += SPLIT_TEMPLATE_MESSAGE; if (CommonUtil.IsNullOrEmpty(screen) == false) { template += screen; } template += SPLIT_TEMPLATE_MESSAGE; template += module + SPLIT_TEMPLATE_MESSAGE; template += code.ToString() + SPLIT_TEMPLATE_MESSAGE; if (param != null) { foreach (string pm in param) { template += pm + SPLIT_TEMPLATE_MESSAGE; } } ModelState state = new System.Web.Mvc.ModelState(); state.Errors.Add(template); _iValidatorUtil.ModelState.Add(id, state); _iValidatorUtil.IsValid = false; this.IsValid = false; } } catch (Exception) { throw; } }
/// <summary> /// Merge PDF /// </summary> /// <param name="filePath1"></param> /// <param name="filePath2"></param> /// <param name="mergeOutputFilename"></param> /// <param name="bEncrypt"></param> /// <param name="encryptOutputFileName"></param> /// <param name="pwd"></param> /// <returns></returns> public static bool MergePDF(string filePath1, string filePath2, string mergeOutputFilename, bool bEncrypt = false, string encryptOutputFileName = null, string pwd = null) { bool result = false; //string essemblyPath = CommonUtil.WebPath + @"\bin\DLL\pdftk.exe"; string essemblyPath = PathUtil.GetAppPath(PathUtil.AppPath.pdftk); try { if (File.Exists(filePath1) == false || File.Exists(filePath2) == false || File.Exists(essemblyPath) == false) { return(false); } string strCommandParameters = string.Format("{0} {1} cat output {2}", filePath1, filePath2, mergeOutputFilename); ExecuteProcess(essemblyPath, strCommandParameters); if (CommonUtil.IsNullOrEmpty(encryptOutputFileName) == true) { string str = mergeOutputFilename.Replace(".pdf", ""); encryptOutputFileName = string.Format("{0}.Encrypt128.pdf", str); } if (CommonUtil.IsNullOrEmpty(pwd) == true) { pwd = "foo"; } if (bEncrypt) { EncryptPDF(mergeOutputFilename, encryptOutputFileName, pwd); } result = true; return(result); } catch (Exception ex) { throw ex; } }
/// <summary> /// Set value to object /// </summary> /// <param name="obj"></param> /// <param name="propName"></param> /// <param name="value"></param> /// <param name="dateFormat"></param> /// <returns></returns> public static bool SetObjectValue(object obj, string propName, string value, string dateFormat = null) { try { if (CommonUtil.IsNullOrEmpty(value)) { return(true); } if (obj != null) { PropertyInfo prop = obj.GetType().GetProperty(propName); if (prop.PropertyType == typeof(string)) { Dictionary <string, MaxTextLengthAttribute> miscAttr = CommonUtil.CreateAttributeDictionary <MaxTextLengthAttribute>(obj); foreach (KeyValuePair <string, MaxTextLengthAttribute> attr in miscAttr) { if (attr.Key == propName) { if (value.Length > attr.Value.MaxLength) { value = value.Substring(0, attr.Value.MaxLength); } break; } } } return(SetObjectValue(prop, obj, value, dateFormat)); } return(false); } catch (Exception ex) { throw ex; } }
public static decimal TargetFee(string currencyType, decimal?fee, decimal?feeUsd) { if (currencyType == CurrencyUtil.C_CURRENCY_LOCAL) { if (CommonUtil.IsNullOrEmpty(fee)) { return(0); } return((decimal)fee); } else if (currencyType == CurrencyUtil.C_CURRENCY_US) { if (CommonUtil.IsNullOrEmpty(feeUsd)) { return(0); } return((decimal)feeUsd); } else { return(0); } }
/// <summary> /// Generate text with newline /// </summary> /// <param name="param"></param> /// <returns></returns> public static string TextLineFormat(params string[] param) { string txt = string.Empty; if (param != null) { for (int idx = 1; idx <= param.Length; idx++) { if (CommonUtil.IsNullOrEmpty(param[idx - 1])) { param[idx - 1] = "-"; } if (txt != string.Empty) { txt += "<br/>"; } txt += string.Format("({0}) {1}", idx, param[idx - 1]); } } return(txt); }
/// <summary> /// Merge PDF /// </summary> /// <param name="sourceFiles"></param> /// <param name="mergeOutputFilename"></param> /// <param name="bEncrypt"></param> /// <param name="encryptOutputFileName"></param> /// <param name="pwd"></param> /// <returns></returns> public static bool MergePDF(string[] sourceFiles, string mergeOutputFilename, bool bEncrypt = false, string encryptOutputFileName = null, string pwd = null, bool isClearTempFile = false) //Modify by Jutarat A. on 14112012 (Add isClearTempFile) { bool result = false; //string essemblyPath = CommonUtil.WebPath + @"\bin\DLL\pdftk.exe"; string essemblyPath = PathUtil.GetAppPath(PathUtil.AppPath.pdftk); int MaxLength = 8000; try { if (sourceFiles.Length == 0) { return(false); } for (int i = 0; i < sourceFiles.Length; i++) { //if (!sourceFiles[i].Contains("\"")) //{ // sourceFiles[i] = string.Format("\"{0}\"", sourceFiles[i]); //} if (File.Exists(sourceFiles[i]) == false) { return(false); } } //if (!mergeOutputFilename.Contains("\"")) //{ // mergeOutputFilename = string.Format("\"{0}\"", mergeOutputFilename); //} //if (!string.IsNullOrEmpty(encryptOutputFileName)) //{ // if (!encryptOutputFileName.Contains("\"")) // { // encryptOutputFileName = string.Format("\"{0}\"", encryptOutputFileName); // } //} string sourceFile = string.Join(" ", sourceFiles); bool isSplit = (sourceFile.Length > MaxLength); string strCommandParameters = string.Empty; if (sourceFiles.Length >= 2) { // Merge file if (isSplit) { List <List <string> > splitList = new List <List <string> >(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < sourceFiles.Length; i++) { if (sb.Length + sourceFiles[i].Length + 3 >= MaxLength) { List <string> strs = new List <string>(); strs.Add(sb.ToString()); strs.Add(PathUtil.GetTempFileName(".pdf")); splitList.Add(strs); sb.Clear(); } //sb.Append(" \"" + sourceFiles[i] + "\""); sb.Append(" " + sourceFiles[i]); } if (sb.Length > 0) { List <string> strs = new List <string>(); strs.Add(sb.ToString()); strs.Add(PathUtil.GetTempFileName(".pdf")); splitList.Add(strs); } string mergeSource = string.Empty; foreach (var item in splitList) { strCommandParameters = string.Format("{0} cat output {1}", item[0], item[1]); ExecuteProcess(essemblyPath, strCommandParameters); mergeSource += " " + item[1]; } if (!string.IsNullOrEmpty(mergeSource)) { strCommandParameters = string.Format("{0} cat output {1}", mergeSource, mergeOutputFilename); ExecuteProcess(essemblyPath, strCommandParameters); } } else { strCommandParameters = string.Format("{0} cat output {1}", sourceFile, mergeOutputFilename); ExecuteProcess(essemblyPath, strCommandParameters); } } if (CommonUtil.IsNullOrEmpty(encryptOutputFileName) == true) { string str = mergeOutputFilename.Replace(".pdf", ""); encryptOutputFileName = string.Format("{0}.Encrypt128.pdf", str); } if (CommonUtil.IsNullOrEmpty(pwd) == true) { pwd = "foo"; } if (sourceFiles.Length >= 2) { if (bEncrypt) { EncryptPDF(mergeOutputFilename, encryptOutputFileName, pwd); } } else { if (bEncrypt) { EncryptPDF(sourceFiles[0], encryptOutputFileName, pwd); } else { File.Copy(sourceFiles[0], mergeOutputFilename, true); } } //Comment by Jutarat A. on 21112013 (Move to delete temp file when Login) ////Add by Jutarat A. on 14112012 /*FileInfo fileInfo; * foreach (string strFile in sourceFiles) * { * fileInfo = new FileInfo(strFile); * fileInfo.Delete(); * * fileInfo = new FileInfo(strFile.Replace(".pdf", "")); * fileInfo.Delete(); * } * * if (isClearTempFile) * { * fileInfo = new FileInfo(mergeOutputFilename); * fileInfo.Delete(); * * fileInfo = new FileInfo(mergeOutputFilename.Replace(".pdf", "")); * fileInfo.Delete(); * }*/ ////End Add //End Comment result = true; return(result); } catch (Exception ex) { throw ex; } }
private void ValidateAtLeast1Field(object obj) { try { List <ValidateMessage> msgLst = new List <ValidateMessage>(); Dictionary <string, AtLeast1FieldNotNullOrEmptyAttribute> langAttr = CommonUtil.CreateAttributeDictionary <AtLeast1FieldNotNullOrEmptyAttribute>(obj); foreach (KeyValuePair <string, AtLeast1FieldNotNullOrEmptyAttribute> attr in langAttr) { ValidateMessage nm = null; foreach (ValidateMessage m in msgLst) { if (m.Controller == attr.Value.Controller && m.Screen == attr.Value.Screen && m.Module == attr.Value.Module && m.Code == attr.Value.MessageCode.ToString()) { nm = m; break; } } if (nm == null) { nm = new ValidateMessage() { Controller = attr.Value.Controller, Screen = attr.Value.Screen, Module = attr.Value.Module, Code = attr.Value.MessageCode.ToString(), HasNullValue = true }; msgLst.Add(nm); } if (nm.HasNullValue == false) { continue; } PropertyInfo prop = obj.GetType().GetProperty(attr.Key); if (prop != null) { object val = prop.GetValue(obj, null); if (CommonUtil.IsNullOrEmpty(val) == false) { nm.HasNullValue = false; nm.ClearParameter(); } else if (attr.Value.UseControl == true) { nm.SetParameter(0, CommonUtil.IsNullOrEmpty(attr.Value.ControlName) ? attr.Key : attr.Value.ControlName); } } } if (msgLst.Count > 0) { foreach (ValidateMessage msg in msgLst) { if (msg.HasNullValue == true) { MessageUtil.MessageList msgCode; if (Enum.TryParse <MessageUtil.MessageList>(msg.Code, out msgCode)) { string template = CommonUtil.TextList(msg.Params == null? null : msg.Params.ToArray()); this.AddErrorMessage(msg.Controller, msg.Screen, msg.Module, msgCode, obj.GetHashCode().ToString(), "", template); this.IsValid = false; } } } } } catch (Exception) { throw; } }