Здравствуйте, прошу помощи, это первый код по C#, после Hello World, который мне дали разобрать.Запускается все,а потом решения на консоль не выводит.Наверно в Main я должен делать вызов методов и вывод результатов, но у меня не получается.
Заранее спасибо.
Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
namespace KR
{
public class LoadAndSave
{
#region Метод LoadXML - загрузка данных из файла
public static ListShop LoadXML(string filename, ListShop listshop)
{
XmlSerializer Serializer = new XmlSerializer(typeof(ListShop));
try
{
using (StreamReader reader = new StreamReader(filename))
{
listshop = (ListShop)Serializer.Deserialize(reader);
}
}
catch (FileNotFoundException)
{
string newXML = @"<?xml version=""1.0"" encoding=""utf-8""?>" + '\n' + @"<ListKafe xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" + '\n' + "<AllKafe />" + '\n' + "</ListKafe>";
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(newXML);
}
}
return listshop;
}
#endregion
#region Save - сохранение экземляра класса Shop в файл
public static bool Save(ListShop listshop, string filename)
{
XmlSerializer sr = new XmlSerializer(listshop.GetType());
StringBuilder sb = new StringBuilder();
StreamWriter SW = new StreamWriter(filename);
sr.Serialize(SW, listshop);
SW.Close();
return true;
}
#endregion
}
public interface IFIOtoString
{
string FIOtoString();
}
#region классы (кафе, сотрудник,блюдо, заказ и др.) и интерфейсы
public class ListShop
{
public List<Worker> AllWorker = new List<Worker>();
public List<Food> AllFood = new List<Food>();
public List<Sale> AllSale = new List<Sale>();
public List<Check> AllCheck = new List<Check>();
}
public class Man
{
string name;
string surname;
string ot;
public string Name
{
get { return name; }
set { name = value; }
}
public string Ot
{
get { return ot; }
set { ot = value; }
}
public string Surname
{
get { return surname; }
set { surname = value; }
}
public Man()
{
name = "";
surname = "";
ot = "";
}
public Man(string Name, string Surname, string Ot)
{
name = Name;
surname = Surname;
ot = Ot;
}
}
[Serializable]
public class Worker : Man, IFIOtoString
{
DateTime ustrdate;
string twnumber;
string wmail;
public DateTime Ustrdate
{
get { return ustrdate; }
set { ustrdate = value; }
}
public string Twnumber
{
get { return twnumber; }
set { twnumber = value; }
}
public string Mail
{
get { return wmail; }
set { wmail = value; }
}
public string FIOtoString()
{
return Name + " " + Ot + " " + Surname;
}
}
[Serializable]
public class Food
{
int id;
string name;
string ingr;
int price;
int kol;
public int ID
{
get { return id; }
set { id = value; }
}
public int Kol
{
get { return kol; }
set { kol = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Ingr
{
get { return ingr; }
set { ingr = value; }
}
public int Price
{
get { return price; }
set { price = value; }
}
}
[Serializable]
public class Sale : Worker, IFIOtoString
{
Food foodsale;
DateTime date;
Worker worker;
int kolv;
public Food Food
{
get { return foodsale; }
set { foodsale = value; }
}
public DateTime Date
{
get { return date; }
set { date = value; }
}
public Worker Worker
{
get { return worker; }
set { worker = value; }
}
public int Kolv
{
get { return kolv; }
set { kolv = value; }
}
public Sale()
{
foodsale = new Food();
date = new DateTime();
worker = new Worker();
}
public Sale(Food Food, DateTime Date, Worker Worker)
{
foodsale = Food;
date = Date;
worker = Worker;
}
}
public class Check
{
private List<Sale> sales = new List<Sale>();
private DateTime printTime;
private double cost=0;
private string printText="";
public DateTime PrintTime
{
get { return printTime; }
}
public string PrintText
{
get { return printText; }
}
public Check( IEnumerable<Sale> newSales)
{
sales.AddRange(newSales);
foreach (Sale sale in sales)
{
cost += sale.Food.Price*sale.Kolv;
}
}
public Check(Sale newSale)
{
sales.Add(newSale);
cost += newSale.Food.Price*newSale.Kolv;
}
public static void Main(string[] args)
{
}
public void AddSale(IEnumerable<Sale> newSales)
{
sales.AddRange(newSales);
foreach (Sale sale in sales)
{
cost += sale.Food.Price * sale.Kolv;
}
}
public void AddSale(Sale newSale)
{
sales.Add(newSale);
cost += newSale.Food.Price * newSale.Kolv;
}
public double Cost
{
get { return cost; }
}
public string PrintCheck()
{
int temp=0;
printTime = DateTime.Now;
StringBuilder checkText = new StringBuilder();
checkText.AppendLine("*** Кафе ***");
checkText.AppendLine("Заказы :");
foreach (Sale sale in sales)
{
temp++;
checkText.AppendLine(String.Format("{0}: {1} - {2}*{3} = {4} этот заказ обслуживал {5} {6}", temp, sale.Food.Name,
sale.Food.Price, sale.Kolv, sale.Food.Price*sale.Kolv,sale.Worker.Name,sale.Worker.Surname));
}
checkText.AppendLine(string.Format("Итоговая стоимость {0}", cost));
checkText.AppendLine(string.Format("{0}",printTime));
checkText.AppendLine("***Спасибо за покупку****");
printText = checkText.ToString();
return checkText.ToString();
}
}
#endregion
}