Пример #1
0
        public static void UpdateStock(TicketSaleRq ticketSaleRq)
        {
            StringBuilder sb = new StringBuilder("");

            string[] lines = File.ReadAllLines(festivalsFile);
            string   oldValue, newValue, output = "";

            foreach (string _line in lines)
            {
                if (!_line.Contains(ticketSaleRq.FestivalName))
                {
                    sb.Append("\r" + _line);
                }
                else
                {
                    oldValue = _line.Split(',').Last();

                    newValue = (Int32.Parse(oldValue) + Int32.Parse(ticketSaleRq.TicketNumber)).ToString();
                    output   = _line.Replace(oldValue.ToString(), newValue + "\r");

                    sb.Append("\r" + output);
                }
            }
            if (File.Exists(festivalsFile))
            {
                File.Delete(festivalsFile);
            }
            using (FileStream fs = new FileStream(festivalsFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
            {
                StreamWriter sw = new StreamWriter(fs);
                sw.BaseStream.Seek(0, SeekOrigin.Begin);
                sw.Write(sb.ToString());
                sw.Flush();
                sw.Close();
            }

            /*
             * while ((line = file.ReadLine()) != null)
             * {
             *  if (line.Contains(ticketSaleRq.FestivalName))
             *  {
             *      oldValue = int.Parse(line.Split(',').Last());
             *      newValue = (oldValue + int.Parse(ticketSaleRq.TicketNumber)).ToString();
             *      string output = "\r" + line.Replace(oldValue.ToString(), newValue + "\r");
             *
             *      line.Remove(0);
             *      file.Close();
             *      using (StreamWriter writer = new StreamWriter(festivalsFile, true))
             *      {
             *          {
             *              writer.Write(output);
             *          }
             *          writer.Close();
             *          break;
             *      }
             *  }
             * }
             */
        }
        public static int CalculateTicketPrice(TicketSaleRq ticketSaleRq)
        {
            string actualTicketPrice = DataAccess.GetFestivalTicketPrice(ticketSaleRq.FestivalName);
            int    totalPrice;

            try
            {
                totalPrice = int.Parse(actualTicketPrice) * int.Parse(ticketSaleRq.TicketNumber);
            }
            catch (Exception)
            {
                throw;
            }
            return(totalPrice);
        }