Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Hotel
- {
- [Serializable]
- public class Camera
- {
- private int nr;
- public enum TipuriCamera {single, doubla, tripla};
- private DateTime checkout;
- private string tipCamera;
- public int Nr { get => nr; set => nr = value; }
- public bool Ocupata
- {
- get
- {
- if (checkout < DateTime.Now)
- return false;
- return true;
- }
- }
- public string TipCamera { get => tipCamera; set => tipCamera = value; }
- public DateTime Checkout { get => checkout; set => checkout = value; }
- public Camera(int nr, DateTime checkout, TipuriCamera tipCamera)
- {
- this.nr = nr;
- this.checkout = checkout;
- this.tipCamera = tipCamera.ToString();
- }
- public override string ToString()
- {
- return "" + nr + ": " + checkout.ToShortDateString() + " " + tipCamera;
- }
- public int getNrCamere()
- {
- if (tipCamera == "single")
- return 1;
- else if (tipCamera == "doubla")
- return 2;
- return 3;
- }
- public static int operator + (Camera c1, Camera c2)
- {
- return c1.getNrCamere() + c2.getNrCamere();
- }
- public static bool operator < (Camera c1, Camera c2)
- {
- if (c1.getNrCamere() < c2.getNrCamere())
- return true;
- return false;
- }
- public static bool operator > (Camera c1, Camera c2)
- {
- if (c1.getNrCamere() > c2.getNrCamere())
- return true;
- return false;
- }
- }
- }
- namespace Hotel
- {
- public class Hotel
- {
- private List<Camera> camere;
- public List<Camera> Camere { get => camere; set => camere = value; }
- public int nrCamereLibere()
- {
- int sum = 0;
- foreach(Camera c in camere)
- {
- if (c.Ocupata == false)
- sum++;
- }
- return sum;
- }
- }
- }
- namespace Hotel
- {
- static class Program
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Camera c1 = new Camera(1, DateTime.Now, Camera.TipuriCamera.doubla);
- Console.WriteLine(c1);
- List<Camera> list = new List<Camera>();
- StreamReader stream = new StreamReader("camere.txt");
- string line;
- while ((line = stream.ReadLine()) != null)
- {
- string[] sir = line.Split(',');
- Camera.TipuriCamera tip;
- if (sir[2] == "dubla")
- {
- tip = Camera.TipuriCamera.doubla;
- }
- else if (sir[2] == "tripla")
- {
- tip = Camera.TipuriCamera.tripla;
- }
- else
- tip = Camera.TipuriCamera.single;
- Camera c = new Camera(int.Parse(sir[0]), DateTime.ParseExact(sir[1], "dd-MM-yyyy", null), tip);
- list.Add(c);
- }
- foreach (Camera c in list)
- {
- Console.WriteLine(c);
- }
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1(list));
- }
- }
- }
- namespace Hotel
- {
- public partial class Form2 : Form
- {
- Camera camera;
- public Form2(Camera c)
- {
- InitializeComponent();
- camera = c;
- textBoxNr.Text = c.Nr.ToString();
- if (c.TipCamera == "dubla")
- comboBoxTip.Text = comboBoxTip.Items[1].ToString();
- else if (c.TipCamera == "single")
- comboBoxTip.Text = comboBoxTip.Items[0].ToString();
- else
- comboBoxTip.Text = comboBoxTip.Items[2].ToString();
- textBoxData.Text = c.Checkout.ToShortDateString();
- }
- private void btnOk_Click(object sender, EventArgs e)
- {
- errorProvider1.SetError(textBoxNr, string.Empty);
- try
- {
- int nr = int.Parse(textBoxNr.Text);
- if (nr < 0)
- throw new Exception("negativ");
- if (nr > 400 || nr < 100)
- throw new Exception("inexistent");
- camera.Nr = nr;
- Camera.TipuriCamera tip;
- if (comboBoxTip.SelectedItem.ToString() == "single")
- tip = Camera.TipuriCamera.single;
- else if (comboBoxTip.SelectedItem.ToString() == "doubla")
- tip = Camera.TipuriCamera.doubla;
- else
- tip = Camera.TipuriCamera.tripla;
- DateTime data = DateTime.Parse(textBoxData.Text);
- camera.Checkout = data;
- camera.TipCamera = tip.ToString();
- Close();
- }
- catch(FormatException)
- {
- MessageBox.Show("here");
- errorProvider1.SetError(textBoxNr, "Numarul camerei este doar numeric!");
- }
- catch(Exception ex)
- {
- if (ex.Message == "negativ")
- {
- errorProvider1.SetError(textBoxNr, "Numarul camerei este pozitiv");
- }
- else if (ex.Message == "inexistent")
- {
- errorProvider1.SetError(textBoxNr, "Aceasta camera nu exista!");
- }
- }
- }
- }
- }
- namespace Hotel
- {
- public partial class Form1 : Form
- {
- public List<Camera> lstCamere;
- public Form1(List<Camera> list)
- {
- InitializeComponent();
- lstCamere = new List<Camera>();
- lstCamere = list;
- listView1.View = View.Details;
- listView1.Columns.Add("Numar camera", 100);
- listView1.Columns.Add("Tip camera", 100);
- listView1.Columns.Add("Checkout", 80);
- listView1.Columns.Add("Ocupata", 80);
- listView1.MultiSelect = false;
- listView1.FullRowSelect = true;
- populareListView();
- listView1.DoubleClick += ListView1_DoubleClick;
- listView1.MouseClick += ListView1_MouseClick;
- panel1.Paint += Panel1_Paint;
- panel1.Hide();
- FormClosing += Form1_FormClosing;
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- Stream stream = new FileStream("camere.dat", FileMode.Create);
- BinaryFormatter formatter = new BinaryFormatter();
- foreach (Camera c in lstCamere)
- {
- formatter.Serialize(stream, c);
- }
- stream.Close();
- }
- private void Panel1_Paint(object sender, PaintEventArgs e)
- {
- Pen pen = new Pen(Color.Black, 3);
- Graphics g = e.Graphics;
- int i = 2;
- foreach (Camera c in lstCamere)
- {
- int nr = c.getNrCamere();
- int space = 0;
- while (nr != 0)
- {
- g.DrawLine(pen, new Point(space, 20 * i), new Point(space + 30 , 20 * i));
- nr--;
- space += 60;
- }
- i++;
- }
- g.Dispose();
- }
- private void ListView1_MouseClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Right)
- {
- colorDialog1.ShowDialog();
- listView1.SelectedItems[0].BackColor = colorDialog1.Color;
- }
- }
- private void ListView1_DoubleClick(object sender, EventArgs e)
- {
- Camera c = (Camera)(listView1.SelectedItems[0].Tag);
- Form2 form2 = new Form2(c);
- form2.ShowDialog();
- populareListView();
- }
- public void populareListView()
- {
- listView1.Items.Clear();
- foreach(Camera c in lstCamere.OrderBy(c => c.Checkout))
- {
- ListViewItem rand = new ListViewItem();
- rand.Text = c.Nr.ToString();
- rand.SubItems.Add(c.TipCamera.ToString());
- rand.SubItems.Add(c.Checkout.ToShortDateString());
- if (c.Ocupata)
- {
- rand.SubItems.Add("Da");
- }
- else
- {
- rand.SubItems.Add("Nu");
- }
- rand.Tag = c;
- listView1.Items.Add(rand);
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- panel1.Show();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment