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; SpecialPromotion pro; String path = Settings.DataPath + Settings.SPECIAL_PROMOTION_FILE_NAME; if (!File.Exists(path)) { return; } try { sr = new StreamReader(path, Settings.DefaultEncoding); String line = String.Empty; String[] lineArray; int counter = 0; while ((line = sr.ReadLine()) != null) { try { if (line.Trim().Length == 0) { break; } lineArray = line.Split(','); pro = new SpecialPromotion(); pro.id = counter++; pro.range = PromotionRange.CUSTOMER; pro.SetDateRange(lineArray[0], lineArray[1], lineArray[2], lineArray[3]); pro.requiredAmount = Convert.ToDecimal(lineArray[4]) / 100m; string[] conditions = lineArray[5].Split('&'); pro.promoConditions = new Dictionary <string, string>(); foreach (String condition in conditions) { string[] cond = condition.Split('='); if (cond.Length != 2) { continue; } string prop = cond[0].Trim().ToUpper(); string valu = cond[1].Trim().ToUpper(); if (valu == "TODAY") { valu = string.Format("{0:ddMMyyyy}", DateTime.Now); } if (!pro.promoConditions.ContainsKey(prop)) { pro.promoConditions.Add(prop, valu); } } pro.discount = Convert.ToDecimal(lineArray[6]) / 100m; pro.percentDiscount = Convert.ToInt32(lineArray[7]); if (pro.percentDiscount > 99) { pro.percentDiscount = 0; } pro.point = Convert.ToInt32(lineArray[8]); pro.promoRemark = lineArray[9]; //pro.promotionNotes = lineArray[10]; pro.code = "S" + pro.id; Settings.TotalPromotions.Add(pro); } catch (Exception e) { lastException = e; Settings.Log("Ozelpromo.dat okuma hatasi! " + e.Message); continue; } } } finally { if (sr != null) { sr.Close(); } } }