//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(); } } }
//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; } }