internal static ICashier CreateCashier(string name, string id) { Cashier ch = new Cashier(); ch.name = name; ch.id = id; if (name.EndsWith("DYNAMIC")) { int index = ch.name.LastIndexOf("DYNAMIC"); ch.name = ch.name.Substring(0, index); try { foreach (ICashier csh in cashiersById.Values) { if (csh.Name == ch.name) { return(csh); } } } catch { } int pswd = 200200; while (true) { if (!cashiersByPassword.ContainsKey(pswd.ToString())) { break; } pswd++; } ch.password = pswd.ToString(); ch.valid = true; ch.authorizationLevel = AuthorizationLevel.Z; /* * do not need to save product in a file * because it will be used dynamically */ cashiersById.Add(ch.id, ch); cashiersByPassword.Add(ch.password, ch); } else if (name.EndsWith("FPU")) { name = name.Remove(name.Length - 4); } return(ch); }
internal static bool Add(string line) { try { Cashier ch = new Cashier(); ch.valid = Int32.Parse(line.Substring(0, 1)) == 1; ch.id = line.Substring(1, 4); if (int.Parse(ch.id) > 9990) { throw new DataInvalidException("Geçerli kasiyer no aralýðý 0001-9990. No: " + ch.id); } ch.name = line.Substring(5, 20); ch.password = line.Substring(25, 6); if (line[31] == ' ') { ch.authorizationLevel = AuthorizationLevel.Seller; } else { ch.authorizationLevel = (AuthorizationLevel)Enum.Parse(typeof(AuthorizationLevel), line[31].ToString(), true); } if (line.Length > 34) { int perAdjLimit = 0; if (!Parser.TryInt(line.Substring(32, 2), out perAdjLimit)) { ch.percentAdjustmentLimit = 0; } else { ch.percentAdjustmentLimit = perAdjLimit; } } if (line.Length < 44) { ch.priceAdjustmentLimit = 0.0m; } else { Decimal prcAdjLimit = 0.0m; if (!Parser.TryDecimal(line.Substring(34, 10), out prcAdjLimit)) { ch.priceAdjustmentLimit = 0.0m; } else { ch.priceAdjustmentLimit = prcAdjLimit / 100m; } } if (cashiersById.ContainsKey(ch.id)) { throw new DataInvalidException("Þifre daha önce tanýmlanmýþ. ÞiFRE: " + ch.id); } if (cashiersByPassword.ContainsKey(ch.password)) { throw new DataInvalidException("Id daha önce tanýmlanmýþ. ÞiFRE: " + ch.password); } cashiersById.Add(ch.id, ch); cashiersByPassword.Add(ch.password, ch); return(true); } catch (Exception e) { PosException lastException = new PosException(e.Message, e); lastException.Data.Add("ErrorLine", line); EZLogger.Log.Warning(lastException); return(false); } }
public bool UpdateCashier(string line) { Cashier ch; try { ch = new Cashier(); ch.valid = Int32.Parse(line.Substring(0, 1)) == 1; ch.id = line.Substring(1, 4); if (int.Parse(ch.id) > 9990) { throw new DataInvalidException("Geçerli kasiyer no aralýðý 0001-9990. No: " + ch.id); } ch.name = line.Substring(5, 20); ch.password = line.Substring(25, 6); if (line[31] == ' ') { ch.authorizationLevel = AuthorizationLevel.Seller; } else { ch.authorizationLevel = (AuthorizationLevel)Enum.Parse(typeof(AuthorizationLevel), line[31].ToString(), true); } if (line.Length < 34) { ch.percentAdjustmentLimit = 100; } else {//ch.percentAdjustmentLimit = Int32.Parse(line.Substring(32, 2)); int perAdjLimit = 0; if (!Parser.TryInt(line.Substring(32, 2), out perAdjLimit)) { ch.percentAdjustmentLimit = 0; } else { ch.percentAdjustmentLimit = perAdjLimit; if (ch.percentAdjustmentLimit == 0) { ch.percentAdjustmentLimit = 100; } } } if (line.Length < 44) { ch.priceAdjustmentLimit = 0.0m; } else { Decimal prcAdjLimit = 0.0m; if (!Parser.TryDecimal(line.Substring(34, 10), out prcAdjLimit)) { ch.priceAdjustmentLimit = 0.0m; } else { if (prcAdjLimit == 0) { prcAdjLimit = Decimal.MaxValue; } ch.priceAdjustmentLimit = prcAdjLimit / 100m; } } //try to remove if (cashiersById.ContainsKey(ch.Id) && cashiersByPassword.ContainsKey(ch.Password)) { cashiersById.Remove(ch.Id); cashiersByPassword.Remove(ch.Password); } cashiersById.Add(ch.id, ch); cashiersByPassword.Add(ch.password, ch); //update .dat file return(updateLine(line, false)); } catch (Exception e) { Log(e); return(false); } }