Пример #1
0
        internal static bool Add(String line)
        {
            try
            {
                string[] keyvalue = line.Split(',');
                if (keyvalue.Length < 3)
                {
                    throw new Exception("Currency.Add : Invalid Line");
                }

                Currency currency = new Currency();
                currency.id   = (int)keyvalue[0][0];
                currency.name = keyvalue[1].TrimEnd();
                string temp = keyvalue[2].Replace(".", Number.DecimalSeperator);
                currency.exchangeRate = Decimal.Parse(temp) / 100;

                if (currencies.ContainsKey(currency.id))
                {
                    throw new Exception("Currency.Add : Id (" + currency.id + ") Exists");
                }
                currencies.Add(currency.id, currency);

                return(true);
            }
            catch (Exception e)
            {
                PosException lastException = new PosException(e.Message, e);
                lastException.Data.Add("ErrorLine", line);
                EZLogger.Log.Warning(lastException);
                return(false);
            }
        }
Пример #2
0
        internal static bool Add(String line)
        {
            try
            {
                Credit   credit   = new Credit();
                string[] keyvalue = line.Split('=');
                if (keyvalue.Length < 2)
                {
                    return(false);
                }

                Parser.TryInt(keyvalue[0], out credit.id);
                if (keyvalue[1].StartsWith("#T"))
                {
                    credit.name     = keyvalue[1].Substring(2);
                    credit.isTicket = true;
                }
                else if (keyvalue[1].StartsWith("#E"))
                {
                    credit.name      = keyvalue[1].Substring(2);
                    credit.payViaEft = true;
                }
                else if (keyvalue[1].StartsWith("#P"))
                {
                    credit.name           = keyvalue[1].Substring(2);
                    credit.isPointPayment = true;
                }
                else
                {
                    credit.name     = keyvalue[1];
                    credit.isTicket = false;
                }

                if (credit.name.Length > 20)
                {
                    credit.name = credit.name.Substring(0, 20);
                }

                if (credits.ContainsKey(credit.Id))
                {
                    throw new Exception("Credit.Add : Id (" + credit.id + ") Exists");
                }
                credits.Add(credit.Id, credit);

                return(true);
            }
            catch (Exception e)
            {
                PosException lastException = new PosException(e.Message, e);
                lastException.Data.Add("ErrorLine", line);
                EZLogger.Log.Warning(lastException);
                return(false);
            }
        }
Пример #3
0
        internal static bool Add(String line)
        {
            try
            {
                serialNumbers.Add(line);

                return(true);
            }
            catch (Exception e)
            {
                PosException lastException = new PosException(e.Message, e);
                lastException.Data.Add("ErrorLine", line);
                EZLogger.Log.Warning(lastException);
                return(false);
            }
        }
Пример #4
0
        private bool WriteLogMsg(Level level, Exception e)
        {
            lock (this)
            {
                // Fail if logger hasn't been started
                if (LoggerState == State.Stopped)
                {
                    return(false);
                }

                // Ignore message logging is paused or it doesn't pass the filter
                if ((LoggerState == State.Paused) || ((_levels & (uint)level) != (uint)level))
                {
                    return(true);
                }

                // Write log message
                WriteLogMsg(level, String.Format("{0} occured. {1}", e.GetType(), e.Message));

#if WindowsCE
                if (e is PosException)
                {
                    PosException pe = (PosException)e;

                    foreach (String key in pe.Data.Keys)
                    {
                        WriteLogMsg(level, String.Format("{0}: {1}", key, pe.Data[key]));
                    }
                }
#else
                foreach (Object o in e.Data.Keys)
                {
                    WriteLogMsg(level, String.Format("{0}: {1}", o, e.Data[o]));
                }
#endif
                if (e.StackTrace != null)
                {
                    foreach (String stackTraceLine in e.StackTrace.Split('\r'))
                    {
                        WriteLogMsg(level, stackTraceLine);
                    }
                }
                return(true);
            }
        }
Пример #5
0
        internal static Product LineToProduct(string line)
        {
            Product p = new Product();

            try
            {
                int nameLength = 20;
#if WindowsCE
                nameLength = 19;
#endif
                p.valid     = Int32.Parse(line.Substring(0, 1)) == 1;
                p.id        = Int32.Parse(line.Substring(1, 6));
                p.barcode   = line.Substring(7, 20).Trim().ToUpper();
                p.name      = line.Substring(27, nameLength).ToUpper();
                p.unitPrice = Decimal.Parse(line.Substring(47, 9)) / 100;
                if (p.unitPrice > MAX_UNITPRICE)
                {
                    throw new Exception("Birim fiyat " + MAX_UNITPRICE + "'dan büyük olamaz");
                }
                if (p.unitPrice < MIN_UNITPRICE)
                {
                    throw new Exception("Birim fiyat " + MIN_UNITPRICE + "'dan küçük olamaz");
                }
                int departmentNo = Int32.Parse(line.Substring(56, 2));
                if (Department.Departments[departmentNo - 1] == null)
                {
                    throw new DataInvalidException("Gecersiz departman");
                }
                p.department = Department.Departments[departmentNo - 1];

                if (!p.Department.Valid)
                {
                    throw new DataInvalidException("Departman aktif deðil");
                }

#if WindowsCE
                p.unit = line.Substring(58, 2);
#else
                p.unit = line.Substring(58, 4);
#endif

                ((Product)p).SetProperties(line[62]);

                //category is optional
                if (line.Trim().Length < 69 || line.Substring(63, 6).Trim() == String.Empty)
                {
                    p.category = "0";
                }
                else
                {
                    p.category = line.Substring(63, 6);
                }

                //2. unit price is optional
                if (line.Trim().Length < 79 || line.Substring(69, 10).Trim() == String.Empty)
                {
                    p.secondaryUnitPrice = p.unitPrice;
                }
                else
                {
                    p.secondaryUnitPrice = Decimal.Parse(line.Substring(69, 10)) / 100;
                }

                return(p);
            }
            catch (Exception e)
            {
                PosException lastException = new PosException(e.Message, e);
                lastException.Data.Add("ErrorLine", line);
                EZLogger.Log.Warning(lastException);
                return(new Product());
            }
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        internal static bool Add(String line)
        {
            try
            {
                ICustomer customer = Parse(line);

                // If customer placed current
                ICustomer result = null;
                if (customers != null && customers.Count > 0)
                {
                    var query = from c in customers
                                where c.Code == customer.Code
                                select c;
                    if (query != null && query.Count() > 0)
                    {
                        result = query.First();
                    }
                }

                if (result != null)
                {
                    // Update current customer info
                    customers[customers.IndexOf(result)] = customer;
                }
                else
                {
                    customers.Add(customer);
                    string code = customer.Code.Trim();
                    if (code[code.Length - 1] == '*')
                    {
                        if (!discountCards.Contains(customer.Code))
                        {
                            discountCards.Add(customer.Code);
                        }
                    }
                }

                return(true);
                //if (customersByCardNo.ContainsKey(customer.Code))
                //{
                //    customersByCardNo[customer.Code] = customer;

                //    Dictionary<string, ICustomer> tempDic = new Dictionary<string, ICustomer>(customersByCode);
                //    foreach(KeyValuePair<string,ICustomer> kvp in tempDic)
                //    {
                //        if(kvp.Value.Code == customer.Code)
                //        {
                //            customersByCode.Remove(kvp.Key);
                //            customersByCode.Add(customer.Number, customer);
                //        }
                //    }

                //    tempDic = new Dictionary<string, ICustomer>(customersByTcknVkn);
                //    foreach(KeyValuePair<string,ICustomer> kvp in tempDic)
                //    {
                //        if(kvp.Value.Code == customer.Code)
                //        {
                //            customersByTcknVkn.Remove(kvp.Key);
                //            customersByTcknVkn.Add(customer.Contact[4], customer);
                //        }
                //    }

                //    tempDic = new Dictionary<string, ICustomer>(customersByName);
                //    foreach (KeyValuePair<string, ICustomer> kvp in tempDic)
                //    {
                //        if (kvp.Value.Code == customer.Code)
                //        {
                //            customersByName.Remove(kvp.Key);
                //            customersByName.Add(customer.Name, customer);
                //        }
                //    }
                //}
                //else
                //{
                //customersByCode.Add(customer.Number, customer);
                //customersByCardNo.Add(customer.Code, customer);
                //customersByTcknVkn.Add(customer.Contact[4], customer);
                //if (!customersByName.ContainsKey(customer.Name))
                //    customersByName.Add(customer.Name, customer);

                //}
            }
            catch (Exception e)
            {
                PosException lastException = new PosException(e.Message, e);
                lastException.Data.Add("ErrorLine", line);
                EZLogger.Log.Warning(lastException);
                return(false);
            }
        }
Пример #8
0
        internal static bool Add(string line)
        {
            try
            {
                int nameLength = 20;
#if WindowsCE
                nameLength = 19;
#endif
                Product p = new Product();
                p.valid     = Int32.Parse(line.Substring(0, 1)) == 1;
                p.id        = Int32.Parse(line.Substring(1, 6));
                p.barcode   = line.Substring(7, 20).Trim().ToUpper();
                p.name      = line.Substring(27, nameLength).ToUpper();
                p.unitPrice = Decimal.Parse(line.Substring(47, 9)) / 100;
                if (p.unitPrice > MAX_UNITPRICE)
                {
                    throw new Exception("Birim fiyat " + MAX_UNITPRICE + "'dan büyük olamaz");
                }
                if (p.unitPrice < MIN_UNITPRICE)
                {
                    throw new Exception("Birim fiyat " + MIN_UNITPRICE + "'dan küçük olamaz");
                }
                int departmentNo = Int32.Parse(line.Substring(56, 2));
                if (Department.Departments[departmentNo - 1] == null)
                {
                    throw new DataInvalidException("Gecersiz departman");
                }
                p.department = Department.Departments[departmentNo - 1];

                if (departmentNameOnly)
                {
                    p.name = p.department.Name;
                }

                if (!p.Department.Valid)
                {
                    throw new DataInvalidException("Departman aktif deðil");
                }

#if WindowsCE
                p.unit = line.Substring(58, 2);
#else
                p.unit = line.Substring(58, 4);
#endif

                ((Product)p).SetProperties(line[62]);


                //category is optional
                if (line.Trim().Length < 69 || line.Substring(63, 6).Trim() == String.Empty)
                {
                    p.category = "0";
                }
                else
                {
                    p.category = line.Substring(63, 6);
                }

                //2. unit price is optional
                if (line.Trim().Length < 79 || line.Substring(69, 10).Trim() == String.Empty)
                {
                    p.secondaryUnitPrice = p.unitPrice;
                }
                else
                {
                    p.secondaryUnitPrice = Decimal.Parse(line.Substring(69, 10)) / 100;
                }

                if (p.secondaryUnitPrice == 0 && p.UnitPrice > 0)
                {
                    p.secondaryUnitPrice = p.unitPrice;
                }
                //id is key word for product
                //if product with same pluno exists then remove old product, and put new product
                //and assign the old barcode to new product in barcode dictionary
                //and assign the old name to new product in name dictionary
                if (productsByLabel.IndexOfKey(p.id) >= 0)
                {
                    IProduct pOld = productsByLabel[p.id];

                    productsByLabel.Remove(pOld.Id);
                    //productsByBarcode.Remove(pOld.Barcode);
                    //productsByName.Remove(pOld.Name);
                }
                productsByLabel.Add(p.id, p);

                if (productsByBarcode.ContainsKey(p.barcode))
                {
                    productsByBarcode.Remove(p.barcode);
                }
                productsByBarcode.Add(p.barcode, p);

                if (productsByName.ContainsKey(p.name))
                {
                    productsByName.Remove(p.name);
                }
                productsByName.Add(p.name, p);

                return(true);
            }
            catch (Exception e)
            {
                PosException lastException = new PosException(e.Message, e);
                lastException.Data.Add("ErrorLine", line);
                EZLogger.Log.Warning(lastException);
                return(false);
            }
        }