internal static void Load() { if (!Directory.Exists(ErrorPath)) { Directory.CreateDirectory(ErrorPath); } SalePromotions = new List <IPromotion>(); TotalPromotions = new List <IPromotion>(); try { TotalPromotion.Load(); } catch (Exception ex) { Settings.Log(String.Format("Promo.dat dosyasi yuklenemedi!\r{0}", ex.Message)); } #if !WindowsCE try { ProductPromotion.Load(); } catch (Exception ex) { Settings.Log(String.Format("Prourun.dat dosyasi yuklenemedi!\r{0}", ex.Message)); } try { CategoryPromotion.Load(); } catch (Exception ex) { Settings.Log(String.Format("Proreyon.dat dosyasi yuklenemedi!\r{0}", ex.Message)); } try { SpecialPromotion.Load(); } catch (Exception ex) { Settings.Log(String.Format("Ozelpromo.dat dosyasi yuklenemedi!\r{0}", ex.Message)); } #endif try { FileWatcher.Start(); } catch (Exception ex) { Settings.Log(String.Format("Promosyon dosyasý bulunamadý.\r{0}", ex.Message)); } }
static void LoadChangedFile(string filePath) { string fileName = filePath.Substring(filePath.LastIndexOfAny(new char[] { '\\', '/' }) + 1); int fileContentHashCode = String.Empty.GetHashCode(); StreamReader sr = null; string context; using (sr = new StreamReader(filePath, Settings.DefaultEncoding)) { context = sr.ReadToEnd(); } fileContentHashCode = context.GetHashCode(); if (contentHashCodes.ContainsKey(fileName)) { if (contentHashCodes[fileName] == fileContentHashCode) { return; } contentHashCodes.Remove(fileName); } Settings.Log("File is changed : " + fileName); try { switch (fileName) { case Settings.PRODUCT_PROMOTION_FILE_NAME: case Settings.CATEGORY_PROMOTION_FILE_NAME: Settings.SalePromotions = new List <IPromotion>(); CategoryPromotion.Load(); ProductPromotion.Load(); break; case Settings.TOTAL_PROMOTION_FILE_NAME: case Settings.SPECIAL_PROMOTION_FILE_NAME: Settings.TotalPromotions = new List <IPromotion>(); TotalPromotion.Load(); SpecialPromotion.Load(); break; } contentHashCodes.Add(fileName, fileContentHashCode); } catch (Exception ex) { Settings.Log(ex.Message); } }
internal static void Load() { StreamReader sr = null; Exception lastException = null; CategoryPromotion pro; try { sr = new StreamReader(Settings.DataPath + Settings.CATEGORY_PROMOTION_FILE_NAME, Settings.DefaultEncoding); } catch (FileNotFoundException fnfe) { if (sr != null) { sr.Close(); } throw new InvalidDataException(fnfe.Message); } using (sr) { String line = String.Empty; String[] lineArray; int lineNo = 0; while ((line = sr.ReadLine()) != null) { try { if (line.Trim().Length == 0) { break; } lineArray = line.Split(','); pro = new CategoryPromotion(); pro.id = Int32.Parse(lineArray[0]); lineNo++; // pro.range = LineArray[1] == "H" ? PromotionRange.ALL : PromotionRange.CUSTOMER; switch (lineArray[1]) { case "H": pro.range = PromotionRange.ALL; break; case "M": pro.range = PromotionRange.CUSTOMER; break; case "I": pro.range = PromotionRange.ALL; pro.limitType = LimitType.Amount; break; case "N": pro.range = PromotionRange.CUSTOMER; pro.limitType = LimitType.Amount; break; } pro.SetDateRange(lineArray[2], lineArray[3], lineArray[4], lineArray[5]); pro.percentDiscount = Int32.Parse(lineArray[6]) == -1 ? 100 : Int32.Parse(lineArray[6]); pro.discount = decimal.Parse(lineArray[7]) / 100m; pro.point = Int32.Parse(lineArray[8]); pro.extraPoint = Int32.Parse(lineArray[9]); pro.requiredQuantity = Math.Max(Int32.Parse(lineArray[10]), 1); pro.requiredAmount = pro.LimitType != LimitType.NoLimit ? pro.Discount : 0m; pro.giftProductLabelNo = Int32.Parse(lineArray[11]); pro.giftProductQuantity = Int32.Parse(lineArray[12]); if (pro.RequiredQuantity > 1 && pro.GiftProductLabelNo == 0) { pro.limitType = LimitType.Quantity; } if (pro.limitType == LimitType.Amount) { pro.requiredAmount = pro.Discount; pro.discount = 0; } pro.customerGroups = new List <string>(); long groupId; for (int counter = 13; counter < lineArray.Length; counter++) { if (Parser.TryLong(lineArray[counter], out groupId)) { pro.customerGroups.Add(lineArray[counter]); } else { pro.promoRemark = lineArray[counter]; } } pro.code = "R" + (lineNo).ToString(); Settings.SalePromotions.Add(pro); } catch (ParameterRelationException) { //Date range is invalid } catch (Exception e) { lastException = e; Settings.Log("Proreyon.dat okuma hatasi! " + e.Message); continue; } } } if (lastException != null) { throw new InvalidDataException(lastException.Message); } }