Example #1
0
        //Save order
        private void metroTileOrdSav_Click(object sender, EventArgs e)
        {
            Order aOrder = createOrd();

            if (aOrder == null)
            {
                return;
            }
            //If is an edition, edit current order
            if (isEdit)
            {
                int ordIndex = HiTechForm.ordList.FindIndex(t => t.OrdId.Equals(currentOrder.OrdId));
                if (aOrder.OrdCost <= aOrder.OrdClient.ClientCredit)
                {
                    HiTechForm.ordList[ordIndex] = aOrder;
                    OperatorDA.SaveList <Order>(HiTechForm.ordList, filePaths.orderPath);
                    //Update client's credit
                    int clIndex = HiTechForm.clientList.FindIndex(t => t.ClientId.Equals(selClient.ClientId));
                    if (HiTechForm.clientList.Find(t => t.ClientId.Equals(selClient.ClientId)) != null)
                    {
                        HiTechForm.clientList[clIndex].ClientCredit = HiTechForm.clientList[clIndex].ClientCredit + currentOrder.OrdCost - aOrder.OrdCost;
                        OperatorDA.SaveList <Client>(HiTechForm.clientList, filePaths.clientPath);
                    }
                    this.Close();
                }
            }
            //If is a new order, save
            else
            {
                aOrder.OrdId = OperatorDA.uniqueID(HiTechForm.ordList, metroComboBoxOrdCl.Text, metroDateTimeOrd.Text);
                if (aOrder.OrdCost <= aOrder.OrdClient.ClientCredit)
                {
                    HiTechForm.ordList.Add(aOrder);
                    OperatorDA.SaveList <Order>(HiTechForm.ordList, filePaths.orderPath);
                    //Update client's credit
                    Client updateCl = HiTechForm.clientList.Find(t => t.ClientName.Equals(metroComboBoxOrdCl.Text));
                    int    clIndex  = HiTechForm.clientList.FindIndex(t => t.ClientId.Equals(updateCl.ClientId));
                    if (HiTechForm.clientList.Find(t => t.ClientId.Equals(updateCl.ClientId)) != null)
                    {
                        HiTechForm.clientList[clIndex].ClientCredit = updateCl.ClientCredit - aOrder.OrdCost;
                        OperatorDA.SaveList <Client>(HiTechForm.clientList, filePaths.clientPath);
                    }

                    this.Close();
                }
            }
        }
Example #2
0
 //Edit Password
 private void metroTileEditPsw_Click(object sender, EventArgs e)
 {
     //Check if inforation entered matches database
     if (HiTechForm.loggeduser.Password == metroTextBoxOldPwsd.Text && HiTechForm.loggeduser.Password != metroTextBoxNewPswd.Text)
     {
         int userIndex = HiTechForm.userList.FindIndex(t => t.Employee.ID.Equals(HiTechForm.loggeduser.Employee.ID));
         MessageBox.Show(userIndex.ToString());
         HiTechForm.userList[userIndex].Password = metroTextBoxNewPswd.Text;
         OperatorDA.SaveList(HiTechForm.userList, filePaths.userPath);
         MetroMessageBox.Show(ActiveForm, "Password updated successfully!", "Update Successful", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return;
     }
     //If info does not match, erro message is displayed
     else
     {
         MetroMessageBox.Show(ActiveForm, "Current password provided is incorrect, please try again!", "Update Successful", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return;
     }
 }
Example #3
0
        //Create object order item
        private OrdItem createOrdItem()
        {
            MetroTextBox[]  textBoxes  = { metroTextBoxOrdQt };
            MetroComboBox[] comboBoxes = { metroComboBoxOrdProd };
            MetroTextBox[]  textboxInt = { metroTextBoxOrdQt };
            if (!(Validator.isNotnull(textBoxes) && Validator.isNotnull(comboBoxes) && Validator.isNumberInt(textboxInt)))
            {
                return(null);
            }
            OrdItem aitem = new OrdItem();

            aitem.OrdItId = OperatorDA.uniqueID(orderItemsList, metroComboBoxOrdProd.Text, metroComboBoxOrdProd.Text);
            if (metroComboBoxOrdProdType.SelectedIndex.Equals(0))
            {
                aitem.OrdProd = HiTechForm.bookList.Find(t => t.Title.Equals(metroComboBoxOrdProd.Text));
            }
            if (metroComboBoxOrdProdType.SelectedIndex.Equals(1))
            {
                aitem.OrdProd = HiTechForm.softwareList.Find(t => t.Title.Equals(metroComboBoxOrdProd.Text));
            }
            aitem.OrdItQt = Convert.ToInt32(metroTextBoxOrdQt.Text);
            return(aitem);
        }