Exemplo n.º 1
0
 // Function to save the result of simulation
 public void saveSimulation(Model.Simulation simulation)
 {
     if (this.View.isSimulate == true)
     {
         using (var context = new Model.Context())
         {
             Cursor.Current = Cursors.WaitCursor;        // waiting animation cursor
             context.Database.Initialize(force: false);  // connect to db
             context.Simulations.Add(simulation);
             try
             {
                 context.SaveChanges();  // save change
                 VMMain.UIMainForm.genMsgBox("Simulation saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             catch (Exception e)
             {
                 VMMain.HandleException(e, this.VMMain.UIMainForm);
                 VMMain.UIMainForm.genMsgBox("Fail to save the simulation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 Cursor.Current = Cursors.Arrow;             // get back to normal cursor
             }
         }
     }
     else
     {
         VMMain.UIMainForm.genMsgBox("You haven't simulated yet.", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 2
0
        public VMDashboard(VMMain VMMain, UIDashboard View)
        {
            this.View           = View;
            this.View.ViewModel = this;
            this.VMMain         = VMMain;

            loadDataInDashboard();
        }
Exemplo n.º 3
0
        /**
         * Functions for 3 buttons, add, modify and choose client
         */
        public bool addClient(string firstName, string lastName, string idCardNumber)
        {
            bool isSuccess = true;

            if (firstName == "" || lastName == "" || idCardNumber == "")
            {
                VMMain.UIMainForm.genMsgBox("Please enter all 3 textboxes.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else if (firstName.Length > 20 || lastName.Length > 20)
            {
                VMMain.UIMainForm.genMsgBox("First name and last name should less than 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else if (idCardNumber.Length > 20)
            {
                VMMain.UIMainForm.genMsgBox("ID card number should less than 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else
            {
                // creaete a client by input
                Client clt = new Client(firstName, lastName, idCardNumber);

                // create a default account
                Account acc = new Account();
                acc.Client      = clt;
                acc.Number      = DateTime.Now.ToString("yyyyMMddHHmmssf"); // use time of now , a unique number
                acc.status      = 1;
                acc.Balance     = 0M;
                clt.AccountList = new List <Account>();
                clt.AccountList.Add(acc);


                using (var context = new Model.Context())
                {
                    Cursor.Current = Cursors.WaitCursor;        // waiting animation cursor
                    context.Database.Initialize(force: false);  // connect to db
                    context.Clients.Add(clt);
                    try
                    {
                        context.SaveChanges();  // save change
                        getDataFromDb();        // refresh the list
                    }
                    catch (Exception e)
                    {
                        VMMain.HandleException(e, this.VMMain.UIMainForm);
                        isSuccess = false;
                    }
                    Cursor.Current = Cursors.Arrow;             // get back to normal cursor
                }
            }
            return(isSuccess);
        }
Exemplo n.º 4
0
        public VMClient(VMMain VMMain, UIClient View)
        {
            this.View           = View;
            this.View.ViewModel = this;
            this.VMMain         = VMMain;

            // load clients and products in lists
            getDataFromDb();

            // load selected client detail to listView and textboxes
            loadClientDetail((Client)View.getLBoxClient().SelectedValue);
        }
Exemplo n.º 5
0
        public VMProduct(VMMain VMMain, UIProduct View)
        {
            this.View           = View;
            this.View.ViewModel = this;
            this.VMMain         = VMMain;


            // load products in lists
            getDataFromDb();

            // load selected client detail to listView and textboxes
            loadProductDetail((Product)View.getLboxProduct().SelectedValue);
        }
Exemplo n.º 6
0
        public bool modifyClient(Client clt, string firstName, string lastName, string idCardNumber)
        {
            bool isSuccess = true;

            if (firstName == "" || lastName == "" || idCardNumber == "")
            {
                VMMain.UIMainForm.genMsgBox("Please enter all 3 textboxes.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else if (firstName.Length > 20 || lastName.Length > 20)
            {
                VMMain.UIMainForm.genMsgBox("First name and last name should less than 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else if (idCardNumber.Length > 20)
            {
                VMMain.UIMainForm.genMsgBox("ID card number should less than 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else
            {
                using (var context = new Model.Context())
                {
                    Cursor.Current = Cursors.WaitCursor;        // waiting animation cursor
                    context.Database.Initialize(force: false);  // connect to db
                    Client oldClt = context.Clients.Find(clt.Id);
                    oldClt.FirstName    = firstName;
                    oldClt.LastName     = lastName;
                    oldClt.IdCardNumber = idCardNumber;
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        VMMain.HandleException(e, this.VMMain.UIMainForm);
                        isSuccess = false;
                    }
                    Cursor.Current = Cursors.Arrow;             // get back to normal cursor
                }
            }

            return(isSuccess);
        }
Exemplo n.º 7
0
 public VMLogin(VMMain VMMain, UILogin View)
 {
     this.View           = View;
     this.View.ViewModel = this;
     this.VMMain         = VMMain;
 }
Exemplo n.º 8
0
        }                                                         // Binding list

        // Constructor
        public VMSimulation(VMMain VMMain, UISimulation View)
        {
            this.View           = View;
            this.View.ViewModel = this;
            this.VMMain         = VMMain;
        }
Exemplo n.º 9
0
        // Function to execute a simulation and save into the bdd
        public void ExecuteSimulation(Model.Simulation Sim)
        {
            if (this.VMMain.Client.AccountList[0].Balance >= Sim.Price)
            {
                Model.BoughtProduct boughtP = new Model.BoughtProduct();
                //Enter infomations of simulation
                boughtP.BoughtStatus = 1;
                boughtP.Price        = Sim.Price;

                //boughtP.Product = Sim.Product;
                boughtP.ProductId = Sim.ProductId;

                boughtP.SettlementPrice = Sim.SettlementPrice;

                boughtP.StartDate  = Sim.StartDate;
                boughtP.EndDate    = Sim.EndDate;
                boughtP.BuyingDate = DateTime.Today.Date;

                //boughtP.Client = this.VMMain.Client;
                boughtP.ClientId = this.VMMain.Client.Id;

                boughtP.FinalInterest = Sim.SettlementPrice - Sim.Price;

                //Save bought product
                using (var context = new Model.Context())
                {
                    Cursor.Current = Cursors.WaitCursor;                 // waiting animation cursor
                    context.Database.Initialize(force: false);           // connect to db
                    List <Client> clients = context.Clients
                                            .Include(c => c.AccountList) // get related entities
                                            .Include(bpl => bpl.BoughtProductList)
                                            .Include("BoughtProductList.Product")
                                            .Include("BoughtProductList.Product.TimeInterests")
                                            .Include("BoughtProductList.Product.SillInterests")
                                            .ToList();
                    Client clientSim = clients.Where(c => c.Id == VMMain.Client.Id).SingleOrDefault();
                    //context.BoughtProducts.Add(boughtP);
                    clientSim.BoughtProductList.Add(boughtP);
                    clientSim.AccountList[0].Balance = clientSim.AccountList[0].Balance - Sim.Price;
                    //Console.Write(context.Clients.Find(VMMain.Client.Id).FirstName);

                    VMMain.Client.BoughtProductList.Add(boughtP);

                    try
                    {
                        context.SaveChanges();  // save change
                        VMMain.UIMainForm.genMsgBox("Simulation executed!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.VMMain.Client.AccountList[0].Balance = this.VMMain.Client.AccountList[0].Balance - Sim.Price;
                        this.VMMain.VMClient.loadClientDetail(VMMain.Client);
                        printBalance();
                    }
                    catch (Exception e)
                    {
                        VMMain.HandleException(e, this.VMMain.UIMainForm);
                        VMMain.UIMainForm.genMsgBox("Fail to execute the simulation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Cursor.Current = Cursors.Arrow;             // get back to normal cursor
                    }
                    //context.SaveChanges();
                }
            }
            else
            {
                VMMain.UIMainForm.genMsgBox("Balance not enough!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }