public static string ClearTextSign(string strMessage, SecretKeyRing skrKeyRing) { SignaturePacket spSign = new SignaturePacket(); strMessage = Radix64.TrimMessage(strMessage); QueryPassphrase qpPassphrase = new QueryPassphrase(); qpPassphrase.ShowMyDialog(skrKeyRing); string strPassphrase = qpPassphrase.Passphrase; TransportableSecretKey tskKey = qpPassphrase.SelectedKey; SecretKeyPacket skpKey = tskKey.FindKey(AsymActions.Sign); Working wWorking = new Working(); wWorking.Show(); spSign.HashAlgorithm = HashAlgorithms.SHA1; spSign.Format = PacketFormats.New; wWorking.Progress(10); SignatureSubPacket sspCreator = new SignatureSubPacket(); sspCreator.Type = SignatureSubPacketTypes.IssuerKeyID; sspCreator.KeyID = skpKey.PublicKey.KeyID; SignatureSubPacket sspCreationTime = new SignatureSubPacket(); sspCreationTime.Type = SignatureSubPacketTypes.SignatureCreationTime; sspCreationTime.TimeCreated = DateTime.Now; spSign.HashedSubPackets = new SignatureSubPacket[2]; spSign.HashedSubPackets[0] = sspCreator; spSign.HashedSubPackets[1] = sspCreationTime; wWorking.Progress(20); //spSign.KeyID = skpKey.PublicKey.KeyID; //spSign.TimeCreated = DateTime.Now; spSign.SignatureAlgorithm = skpKey.PublicKey.Algorithm; spSign.SignatureType = SignatureTypes.TextSignature; spSign.Version = SignaturePacketVersionNumbers.v4; wWorking.Progress(10); byte[] bMessage = System.Text.Encoding.UTF8.GetBytes(strMessage); spSign.Sign(bMessage, skpKey, strPassphrase); wWorking.Progress(40); byte[] bSignature = spSign.Generate(); string strSignature = Radix64.Encode(bSignature, true); wWorking.Progress(20); string strFinal = Armor.WrapCleartextSignature(strMessage, strSignature); wWorking.Hide(); return strFinal; }
public AcceptanceWorkingInfo(Working working, string operation) { if (working == null) { return; } try { SuspendNotifications(); Copy(working, this); Operation = operation; AcceptChanges(); } finally { ResumeNotifications(); } }
private bool ValidatePaths() { if (Directory.Exists(SolutionDirPath) == false) { Working.ShowMessage("Source files directory doesn't exists!\nCheck the path again."); return(false); } if (Directory.Exists(InstallDirPath) == false) { Working.ShowMessage("InstallDir directory doesn't exists!\nCheck the path again."); return(false); } if (Working.IsSubdirectory(SolutionDirPath, InstallDirPath) == false) { Working.ShowMessage("INSTALLDIR is not inside source files dir!\nCheck your paths again."); return(false); } return(true); }
public AppointmentModel(Working working, OperationModel operationModel, ResourceModel resourceModel, LabelModel label) { Working = working; StartTime = working.WORKINGFROM.Value; WorkerId = Convert.ToInt32(working.WORKERID_R); OperationId = operationModel.Id; ResourceId = string.Format("<ResourceIds>\r\n<ResourceId Type=\"System.Int32\" Value=\"{0}\" />\r\n</ResourceIds>", WorkerId); if (working.WORKINGTILL.HasValue) { EndTime = working.WORKINGTILL.Value; IsCompleted = true; } else { EndTime = DateTime.Now; } Status = IsCompleted ? 1 : 0; Label = label.Id; Subject = string.Format("{0} ({1})", operationModel.Name, EndTime - StartTime); }
private bool AddMe() { var workerId = WMSEnvironment.Instance.WorkerId; try { if (!ValidateWorkingByWorkerId(workerId)) { return(false); } if (!CheckMe(workerId)) { return(false); } var w = new Working { WORKERID_R = workerId, WORKID_R = CurrentWork.GetKey <decimal>(), WORKINGFROM = GetCorrectDate(), TruckCode = WMSEnvironment.Instance.TruckCode, WORKINGADDL = false }; using (var mgr = IoC.Instance.Resolve <IBaseManager <Working> >()) mgr.Insert(ref w); } catch (Exception ex) { var message = ExceptionHelper.GetErrorMessage(ex); _log.Warn(message, ex); ShowMessage(message, "Ошибка при добавлении сотрудника"); return(false); } return(true); }
public static void EncryptFiles(String[] strFiles, PublicKeyRing pkrPublicKeyRing, SecretKeyRing skrSecretKeyRing, bool bEncrypt, bool bSign) { PublicKeySelector pksSelectKeys = new PublicKeySelector(pkrPublicKeyRing); if (bEncrypt) { pksSelectKeys.ShowDialog(); if (pksSelectKeys.SelectedKeys.Count == 0) { MessageBox.Show("You did not select a public key to encrypt to. Doing nothing...", "Nothing Done..."); return; } } TransportableSecretKey tskKey = new TransportableSecretKey(); string strPassphrase = ""; if (bSign) { QueryPassphrase qpPassphrase = new QueryPassphrase(); qpPassphrase.ShowMyDialog(skrSecretKeyRing); tskKey = qpPassphrase.SelectedKey; strPassphrase = qpPassphrase.Passphrase; } Working wWorking = new Working(); wWorking.Show(); for (int i=0; i<strFiles.Length; i++) { byte[] bFileContent = new byte[0]; try { System.IO.FileStream fsFile = new FileStream(strFiles[i], FileMode.Open); BinaryReader brReader = new BinaryReader(fsFile); bFileContent = brReader.ReadBytes((int)fsFile.Length); brReader.Close(); fsFile.Close(); } catch (Exception e) { wWorking.Hide(); MessageBox.Show("An error occured while opening the file " + strFiles[i] + ": " + e.Message, "Error..."); return; } LiteralMessage lmMessage = new LiteralMessage(DataFormatTypes.Binary); lmMessage.Binary = bFileContent; lmMessage.TimeCreated = DateTime.Now; int iLastBackslash = strFiles[i].LastIndexOf("\\"); lmMessage.Filename = strFiles[i].Substring(iLastBackslash + 1, strFiles[i].Length - iLastBackslash - 1); SharpPrivacy.OpenPGP.Messages.Message mEncryptionMessage = lmMessage; if (bSign) { SignedMessage smMessage = new SignedMessage(); smMessage.MessageSigned = lmMessage; SignaturePacket spPacket = new SignaturePacket(); spPacket.Version = SignaturePacketVersionNumbers.v3; SecretKeyPacket skpKey = tskKey.FindKey(AsymActions.Sign); spPacket.KeyID = skpKey.PublicKey.KeyID; spPacket.HashAlgorithm = HashAlgorithms.SHA1; spPacket.SignatureAlgorithm = skpKey.PublicKey.Algorithm; spPacket.TimeCreated = DateTime.Now; spPacket.SignatureType = SignatureTypes.TextSignature; spPacket.Sign(lmMessage.Binary, skpKey, strPassphrase); smMessage.Signature = spPacket; mEncryptionMessage = smMessage; } CompressedMessage cmMessage = new CompressedMessage(); cmMessage.Compress(mEncryptionMessage); wWorking.Progress(20/strFiles.Length); SymAlgorithms saAlgo = GetSymAlgorithmPreferences(pksSelectKeys.SelectedKeys); wWorking.Progress(10/strFiles.Length); byte[] bReturn = new byte[0]; if (bEncrypt) { SymmetricallyEncryptedDataPacket sedpEncrypted = new SymmetricallyEncryptedDataPacket(); SymmetricAlgorithm saEncrypt = CipherHelper.CreateSymAlgorithm(saAlgo); saEncrypt.Mode = CipherMode.OpenPGP_CFB; saEncrypt.GenerateKey(); byte[] bKey = saEncrypt.Key; ESKSequence esksKeys = new ESKSequence(); try { esksKeys = CreateESKSequence(pksSelectKeys.SelectedKeys, AsymActions.Encrypt, saAlgo, bKey); } catch (Exception e) { wWorking.Hide(); MessageBox.Show("The following error occured: " + e.Message, "Error..."); return; } wWorking.Progress(50/strFiles.Length); ICryptoTransform ictEncryptor = saEncrypt.CreateEncryptor(); byte[] bMessage = cmMessage.GetEncoded(); byte[] bOutput = new byte[bMessage.Length]; ictEncryptor.TransformBlock(bMessage, 0, bMessage.Length, ref bOutput, 0); bKey.Initialize(); wWorking.Progress(10/strFiles.Length); int iOutLength = (saEncrypt.BlockSize >> 3) + 2 + bMessage.Length; sedpEncrypted.Body = new byte[iOutLength]; Array.Copy(bOutput, 0, sedpEncrypted.Body, 0, iOutLength); byte[] bESK = esksKeys.GetEncoded(); byte[] bEncrypted = sedpEncrypted.Generate(); bReturn = new byte[bESK.Length + bEncrypted.Length]; bESK.CopyTo(bReturn, 0); bEncrypted.CopyTo(bReturn, bESK.Length); } else { wWorking.Progress(60/strFiles.Length); bReturn = cmMessage.GetEncoded(); } wWorking.Progress(10/strFiles.Length); try { FileStream fsOut = new FileStream(strFiles[i] + ".asc", FileMode.CreateNew); BinaryWriter bwWrite = new BinaryWriter(fsOut); bwWrite.Write(bReturn); bwWrite.Close(); fsOut.Close(); } catch (IOException io) { MessageBox.Show("Could not write to file. The following error occured: " + io.Message, "Error..."); } } wWorking.Hide(); }
public override void FillByGroup(decimal workId, decimal groupId) { // получаем бригаду WorkerGroup wg; using (var mgr = GetManager <WorkerGroup>()) wg = mgr.Get(groupId); if (wg == null) { throw new OperationException("Не найдена бригада с кодом " + groupId); } // получаем работы var work = Get(workId); if (work == null) { throw new OperationException("Не найдена работа с кодом " + workId); } var addingWorkings = new List <Working>(); if (wg.Worker2GroupL == null) { wg.Worker2GroupL = new WMSBusinessCollection <Worker2Group>(); } if (work.WORKINGL == null) { work.WORKINGL = new WMSBusinessCollection <Working>(); } // идем по все членам бригады foreach (var item in wg.Worker2GroupL) { // проверяем внесен ли уже данный работник в работу var exitsWorker = work.WORKINGL.FirstOrDefault(i => i.WORKERID_R.Equals(item.WORKER2GROUPWORKERID)); // нашли - переходим дальше if (exitsWorker != null) { continue; } var newWorking = new Working { WORKID_R = work.GetKey <decimal>(), WORKERID_R = item.WORKER2GROUPWORKERID, WORKERGROUPID_R = groupId, WORKINGFROM = DateTime.Now, WORKINGADDL = true }; // TODO: перейти на API-шную функцию addingWorkings.Add(newWorking); } // ничего не добавили if (addingWorkings.Count == 0) { return; } // добавляем работников using (var mgr = GetManager <Working>()) { IEnumerable <Working> res = addingWorkings; mgr.Insert(ref res); } }
private void Compute() { var tableAttributes = Schema.Attributes.Where(a => !a.IsQueryable).Concat(DecidableAttributes); Working.Print("Current data subset:"); Working.Print(""); Working.Printf(@"\begin{{tabular}}{{{0}l}}", "l ".Repeat(tableAttributes.Count())); Working.Printf(@" {0}{1} \\", String.Join(" & ", tableAttributes .Select(a => String.Format(@"\textbf{{{0}}}", a.Name))), @" & \textbf{Answer}"); foreach (var datum in Data) { Working.Printf(@" {0} & \textbf{{{1}}} \\", String.Join(" & ", tableAttributes .Select(a => datum[a])), datum.Answer); } Working.Print(@"\end{tabular}"); Working.Print(""); var entropyData = Data .GroupBy(d => d.Answer) .Select(g => new { Answer = g.Key, Count = (double)g.Count() }); Working.Printf("Entropy calculation: {0}.", String.Join(", ", entropyData .Select(i => String.Format(@"\texttt{{{0}}} occurs $ {1} $ time{2}", i.Answer, i.Count, i.Count == 1 ? "" : "s")))); var entropy = Entropy(entropyData .Select(ans => ans.Count)); Working.Printf("$$ {0}={1:0.######} $$", EntropyWorking(entropyData.Select(e => (int)e.Count), (int)entropyData.Sum(d => d.Count)), entropy); Dictionary <Attribute, double> attributeGains = new Dictionary <Attribute, double>(); foreach (Attribute attribute in DecidableAttributes) { double remainder = Remainder(Data, attribute), gain = entropy - remainder; var remainderData = Data .GroupBy(d => d[attribute]) .Select(g => new { Value = g.Key, Count = g.Count() }); Working.Printf(@"Remainder calculation for \texttt{{{1}}} as follows. " + @"Number of occurrences for each value of \texttt{{{1}}}: {0}.", String.Join(", ", remainderData .Select(i => String.Format(@"\texttt{{{0}}} occurs $ {1} $ time{2}", i.Value, i.Count, i.Count == 1 ? "" : "s"))), attribute.Name); Working.Printf("$$ Remainder({2})={0}={1:0.######} $$", String.Join("+", remainderData .Select(g => String.Format(@"\frac{{{0}}}{{{1}}}\left({2}\right)", g.Count, Data.Count(), EntropyWorking( Data .Where(d => d[attribute] == g.Value) .GroupBy(d => d.Answer) .Select(g2 => g2.Count()), g.Count)))), remainder, attribute.Name); Working.Printf("Hence, $ Gain({0}) = H - Remainder({0}) = {1:0.######} $.", attribute.Name, gain); Working.Print(""); attributeGains.Add(attribute, gain); } var questionAttributeGain = attributeGains .OrderByDescending(kvp => kvp.Value) .First(); Working.Printf(@"The information gain from \texttt{{{0}}} is the largest, at $ {1:0.######} $ bits - " + @"therefore, this attribute should form the next decision.", questionAttributeGain.Key, questionAttributeGain.Value); QuestionAttribute = questionAttributeGain.Key; Children = new Dictionary <string, ITreeNode>(); var byBest = Data .GroupBy(d => d[QuestionAttribute]); Answers = byBest .Select(g => g.Key) .ToArray(); foreach (var group in byBest) { /* for (int i = 0; i < Level; i++) * Console.Write(" |"); * Console.WriteLine(" If {0} = {1}:", QuestionAttribute, group.Key); */ Working.Print(""); Working.Printf(@"Assume \texttt{{{0}}} was chosen for the attribute \texttt{{{1}}}.", group.Key, QuestionAttribute); Children.Add(group.Key, group.Count() == 1 || group.AllEqual(v => v.Answer) ? (ITreeNode)(new AnswerTreeNode(Schema, group.First().Answer, group, Level + 1)) : (ITreeNode)(new QuestionTreeNode(Schema, group, DecidableAttributes.Where(a => a != QuestionAttribute).ToArray(), Level + 1, KnownValues.Add(QuestionAttribute, group.Key)))); } Working.Print(""); Working.Printf(@"This accounts for every possibility of the attribute \texttt{{{0}}} " + "at this level of the decision tree.", QuestionAttribute); }
static void Main(string[] args) { while (true) { int userInput = menu.StartMenu(); while (true) { if (userInput == 1) { user = userService.Login(); if (user == null) { Environment.Exit(0); } break; } else if (userInput == 2) { user = userService.Register(); if (user == null) { continue; } break; } } Console.Clear(); bool main = false; while (!main) { int mainMenu = menu.MainMenu(); switch (mainMenu) { case 1: bool track = false; while (!track) { int trackMenu = menu.TrackMenu(); switch (trackMenu) { case 1: Reading reading = new Reading(); reading.Stopwatch = activityService.TrackActivity("reading"); Console.WriteLine("Enter the number of page you read"); reading.Pages = int.Parse(Console.ReadLine()); int readingMenu = menu.ReadingMenu(); switch (readingMenu) { case 1: reading.Type = Db.Enums.ReadingType.BellesLettras; break; case 2: reading.Type = Db.Enums.ReadingType.Fiction; break; case 3: reading.Type = Db.Enums.ReadingType.ProffesionalLiterature; break; } readingService.AddReadingActivity(reading); Console.WriteLine($"{user.Username} you read total of {reading.Pages}, from {reading.Type} type of book, for {reading.Stopwatch.Elapsed.TotalMinutes} minutes"); break; case 2: Exercising exercise = new Exercising(); exercise.Stopwatch = activityService.TrackActivity("exercising"); int exerciseMenu = menu.ExercisingMenu(); switch (exerciseMenu) { case 1: exercise.Type = Db.Enums.ExercisingType.General; break; case 2: exercise.Type = Db.Enums.ExercisingType.Running; break; case 3: exercise.Type = Db.Enums.ExercisingType.Sport; break; } exercisingService.AddExercisingActivity(exercise); Console.WriteLine($"{user.Username} you did {exercise.Type} for {exercise.Stopwatch.Elapsed.TotalMinutes} minutes"); break; case 3: Working working = new Working(); working.Stopwatch = activityService.TrackActivity("working"); int workingMenu = menu.WorkingMenu(); switch (workingMenu) { case 1: working.WorkFrom = Db.Enums.WorkingType.Home; break; case 2: working.WorkFrom = Db.Enums.WorkingType.Office; break; } workingService.AddWorkingActivity(working); Console.WriteLine($"{user.Username} you worked from {working.WorkFrom} for {working.Stopwatch.Elapsed.TotalMinutes} minutes"); break; case 4: Console.WriteLine("Tell me what did you do today:"); OtherHobby otherHobby = new OtherHobby(); otherHobby.HobbyName = Console.ReadLine(); otherHobby.Stopwatch = activityService.TrackActivity(otherHobby.HobbyName); otherHobbyService.AddOtherHobbyActivity(otherHobby); Console.WriteLine($"{user.Username}, you've been doing {otherHobby.HobbyName} for {otherHobby.Stopwatch.Elapsed.TotalMinutes} minutes"); break; case 5: track = true; break; } } break; } } Console.ReadLine(); } }
public DraftManager() { this.working = new Working(); this.mode = "Full"; }
static void Main(string[] args) { Working working = new Working(); working.Initialize(); }
public void InsertWork(Working working) { _workingDb.InsertActivity(working); }
private async Task <bool> GetWorkAsync(decimal workerId) { var workOperation = BillOperationCode.OP_INPUT_REG.ToString(); var workhelper = new WorkHelper(); Func <DataRow[], string, string> dialogMessageHandler = (rows, workername) => { return(string.Format(StringResources.YouHaveWorkingsMessageFormat, Environment.NewLine, string.Join(Environment.NewLine, rows.Select(p => string.Format("'{0}' ('{1}').", p["operationname"], p["workid"]))))); }; var result = workhelper.ClosingWorking(workerId: workerId, filter: null, dialogTitle: StringResources.Confirmation, workername: null, dialogMessageHandler: dialogMessageHandler); if (!result) { return(false); } //Создаем работу List <Work> workList; using (var mgr = IoC.Instance.Resolve <IBaseManager <Work> >()) { var filter = string.Format( "operationcode_r = '{1}' and workid in (select w2e.workid_r from wmswork2entity w2e where w2e.work2entityentity = 'CARGOIWB' " + "and w2e.work2entitykey in (select to_char(min(i2c.cargoiwbid_r)) from wmsiwb2cargo i2c " + "left join wmsiwbpos ip on i2c.iwbid_r = ip.iwbid_r " + "where ip.iwbposid ={0}))", _posID, workOperation); workList = mgr.GetFiltered(filter, GetModeEnum.Partial).ToList(); } if (workList.Any()) { using (var mgr = IoC.Instance.Resolve <IBaseManager <Working> >()) { var working = new Working { WORKID_R = workList.First().GetKey <decimal>(), WORKERID_R = workerId, WORKINGFROM = BPH.GetSystemDate() }; mgr.Insert(ref working); } } else { List <CargoIWB> cargoIWBList; using (var mgr = IoC.Instance.Resolve <IBaseManager <CargoIWB> >()) { cargoIWBList = mgr.GetFiltered(string.Format("cargoiwbid in (select min(i2c.cargoiwbid_r) from wmsiwb2cargo i2c join wmsiwbpos ip on ip.iwbid_r = i2c.iwbid_r where ip.iwbposid = {0} )", _posID), GetModeEnum.Partial).ToList(); } if (cargoIWBList.Any()) { var mgrBpProcessManager = IoC.Instance.Resolve <IBPProcessManager>(); Work mywork; mgrBpProcessManager.StartWorking("CARGOIWB", cargoIWBList.First().GetKey().ToString(), workOperation, workerId, cargoIWBList.First().MandantID, null, null, out mywork); } } Workings = RefreshWorking(); return(true); }
public bool ContainsKeyToSortedDictTKey(Working obj) { return(sortedDictTKey.ContainsKey(obj)); }
public static string EncryptText(string strMessage, PublicKeyRing pkrPublicKeyRing, SecretKeyRing skrSecretKeyRing, bool bSign) { PublicKeySelector pksSelectKeys = new PublicKeySelector(pkrPublicKeyRing); pksSelectKeys.ShowDialog(); TransportableSecretKey tskKey = new TransportableSecretKey(); string strPassphrase = ""; if (bSign) { QueryPassphrase qpPassphrase = new QueryPassphrase(); qpPassphrase.ShowMyDialog(skrSecretKeyRing); tskKey = qpPassphrase.SelectedKey; strPassphrase = qpPassphrase.Passphrase; } if (pksSelectKeys.SelectedKeys.Count == 0) { return(strMessage); } Working wWorking = new Working(); wWorking.Show(); LiteralMessage lmMessage = new LiteralMessage(DataFormatTypes.Text); lmMessage.Text = strMessage; lmMessage.TimeCreated = DateTime.Now; lmMessage.Filename = ""; SharpPrivacy.OpenPGP.Messages.Message mEncryptionMessage = lmMessage; if (bSign) { SignedMessage smMessage = new SignedMessage(); smMessage.MessageSigned = lmMessage; SignaturePacket spPacket = new SignaturePacket(); spPacket.Version = SignaturePacketVersionNumbers.v3; SecretKeyPacket skpKey = tskKey.FindKey(AsymActions.Sign); spPacket.KeyID = skpKey.PublicKey.KeyID; spPacket.HashAlgorithm = HashAlgorithms.SHA1; spPacket.SignatureAlgorithm = skpKey.PublicKey.Algorithm; spPacket.TimeCreated = DateTime.Now; spPacket.SignatureType = SignatureTypes.TextSignature; spPacket.Sign(lmMessage.Binary, skpKey, strPassphrase); smMessage.Signature = spPacket; mEncryptionMessage = smMessage; } CompressedMessage cmMessage = new CompressedMessage(); cmMessage.Compress(mEncryptionMessage); wWorking.Progress(20); SymAlgorithms saAlgo = GetSymAlgorithmPreferences(pksSelectKeys.SelectedKeys); SymmetricallyEncryptedDataPacket sedpEncrypted = new SymmetricallyEncryptedDataPacket(); SymmetricAlgorithm saEncrypt = CipherHelper.CreateSymAlgorithm(saAlgo); saEncrypt.Mode = CipherMode.OpenPGP_CFB; saEncrypt.GenerateKey(); byte[] bKey = saEncrypt.Key; wWorking.Progress(10); ESKSequence esksKeys = new ESKSequence(); try { esksKeys = CreateESKSequence(pksSelectKeys.SelectedKeys, AsymActions.Encrypt, saAlgo, bKey); } catch (Exception e) { wWorking.Hide(); MessageBox.Show("The following error occured: " + e.Message, "Error..."); return(strMessage); } wWorking.Progress(50); ICryptoTransform ictEncryptor = saEncrypt.CreateEncryptor(); byte[] bMessage = cmMessage.GetEncoded(); byte[] bOutput = new byte[bMessage.Length]; ictEncryptor.TransformBlock(bMessage, 0, bMessage.Length, ref bOutput, 0); bKey.Initialize(); wWorking.Progress(10); int iOutLength = (saEncrypt.BlockSize >> 3) + 2 + bMessage.Length; sedpEncrypted.Body = new byte[iOutLength]; Array.Copy(bOutput, 0, sedpEncrypted.Body, 0, iOutLength); byte[] bESK = esksKeys.GetEncoded(); byte[] bEncrypted = sedpEncrypted.Generate(); byte[] bReturn = new byte[bESK.Length + bEncrypted.Length]; bESK.CopyTo(bReturn, 0); bEncrypted.CopyTo(bReturn, bESK.Length); wWorking.Progress(10); string strReturn = Radix64.Encode(bReturn, true); strReturn = Armor.WrapMessage(strReturn); wWorking.Hide(); return(strReturn); }
/// <summary> /// Construtor com parametros /// </summary> /// <param name="job"></param> /// <param name="name"></param> /// <param name="contact"></param> /// <param name="birthday"></param> /// <param name="gender"></param> /// <param name="working"></param> /// <param name="address"></param> /// <param name="numberSNS"></param> public Staff(string job, string name, string contact, DateTime birthday, Gender gender, Working working, string address, int numberSNS) { this.IdStaff = Interlocked.Increment(ref globalID); this.job = job; this.working = working; base.Name = name; base.Contact = contact; base.Birthday = birthday; base.GenderP = gender; base.Address = address; base.GetActive = Active.Yes; base.NumberSNS = numberSNS; }
public Working Update(Working entity) { return(_WorkingDal.Update(entity)); }
public void Delete(Working entity) { _WorkingDal.Delete(entity); }
public Working Add(Working entity) { return(_WorkingDal.Add(entity)); }
public void TimeWorking(int i) { Time = Working.Invoke(i); Console.WriteLine($"Пользователь провел сегодня за компьютером: {Time} часов"); }
protected override void Execute(NativeActivityContext context) { var width = DialogWidth.Get(context); var height = DialogHeight.Get(context); var workings = WorkingProp.Get(context); if (workings == null) { workings = new List <Working>(); } var vm = (InputPlPosListViewModel)IoC.Instance.Resolve(typeof(InputPlPosListViewModel)); vm.PanelCaption = Title.Get(context); vm.ActionWorkflowCode = ActionWorkflowCode.Get(context); var source = Source.Get(context); if (source != null) { source.ForEach(p => p.AcceptChanges()); } ((IModelHandler)vm).SetSource(new ObservableCollection <InputPlPos>(source)); var viewService = IoC.Instance.Resolve <IViewService>(); var dialogResult = viewService.ShowDialogWindow(viewModel: vm, isRestoredLayout: true, isNotNeededClosingOnOkResult: true, width: width, height: height); if (dialogResult == true) { var result = ((IModelHandler)vm).GetSource() as IEnumerable <InputPlPos>; if (result == null) { throw new DeveloperException("Source type is not IEnumerable."); } Result.Set(context, result.ToList()); } DialogResult.Set(context, dialogResult); workings.Clear(); if (vm.Workings != null) { foreach (var w in vm.Workings) { var working = new Working(); try { working.SuspendNotifications(); WMSBusinessObject.Copy(w, working); working.AcceptChanges(); } finally { working.ResumeNotifications(); } workings.Add(working); } } WorkingProp.Set(context, workings); var disposable = vm as IDisposable; if (disposable != null) { disposable.Dispose(); } }
public static void EncryptFiles(String[] strFiles, PublicKeyRing pkrPublicKeyRing, SecretKeyRing skrSecretKeyRing, bool bEncrypt, bool bSign) { PublicKeySelector pksSelectKeys = new PublicKeySelector(pkrPublicKeyRing); if (bEncrypt) { pksSelectKeys.ShowDialog(); if (pksSelectKeys.SelectedKeys.Count == 0) { MessageBox.Show("You did not select a public key to encrypt to. Doing nothing...", "Nothing Done..."); return; } } TransportableSecretKey tskKey = new TransportableSecretKey(); string strPassphrase = ""; if (bSign) { QueryPassphrase qpPassphrase = new QueryPassphrase(); qpPassphrase.ShowMyDialog(skrSecretKeyRing); tskKey = qpPassphrase.SelectedKey; strPassphrase = qpPassphrase.Passphrase; } Working wWorking = new Working(); wWorking.Show(); for (int i = 0; i < strFiles.Length; i++) { byte[] bFileContent = new byte[0]; try { System.IO.FileStream fsFile = new FileStream(strFiles[i], FileMode.Open); BinaryReader brReader = new BinaryReader(fsFile); bFileContent = brReader.ReadBytes((int)fsFile.Length); brReader.Close(); fsFile.Close(); } catch (Exception e) { wWorking.Hide(); MessageBox.Show("An error occured while opening the file " + strFiles[i] + ": " + e.Message, "Error..."); return; } LiteralMessage lmMessage = new LiteralMessage(DataFormatTypes.Binary); lmMessage.Binary = bFileContent; lmMessage.TimeCreated = DateTime.Now; int iLastBackslash = strFiles[i].LastIndexOf("\\"); lmMessage.Filename = strFiles[i].Substring(iLastBackslash + 1, strFiles[i].Length - iLastBackslash - 1); SharpPrivacy.OpenPGP.Messages.Message mEncryptionMessage = lmMessage; if (bSign) { SignedMessage smMessage = new SignedMessage(); smMessage.MessageSigned = lmMessage; SignaturePacket spPacket = new SignaturePacket(); spPacket.Version = SignaturePacketVersionNumbers.v3; SecretKeyPacket skpKey = tskKey.FindKey(AsymActions.Sign); spPacket.KeyID = skpKey.PublicKey.KeyID; spPacket.HashAlgorithm = HashAlgorithms.SHA1; spPacket.SignatureAlgorithm = skpKey.PublicKey.Algorithm; spPacket.TimeCreated = DateTime.Now; spPacket.SignatureType = SignatureTypes.TextSignature; spPacket.Sign(lmMessage.Binary, skpKey, strPassphrase); smMessage.Signature = spPacket; mEncryptionMessage = smMessage; } CompressedMessage cmMessage = new CompressedMessage(); cmMessage.Compress(mEncryptionMessage); wWorking.Progress(20 / strFiles.Length); SymAlgorithms saAlgo = GetSymAlgorithmPreferences(pksSelectKeys.SelectedKeys); wWorking.Progress(10 / strFiles.Length); byte[] bReturn = new byte[0]; if (bEncrypt) { SymmetricallyEncryptedDataPacket sedpEncrypted = new SymmetricallyEncryptedDataPacket(); SymmetricAlgorithm saEncrypt = CipherHelper.CreateSymAlgorithm(saAlgo); saEncrypt.Mode = CipherMode.OpenPGP_CFB; saEncrypt.GenerateKey(); byte[] bKey = saEncrypt.Key; ESKSequence esksKeys = new ESKSequence(); try { esksKeys = CreateESKSequence(pksSelectKeys.SelectedKeys, AsymActions.Encrypt, saAlgo, bKey); } catch (Exception e) { wWorking.Hide(); MessageBox.Show("The following error occured: " + e.Message, "Error..."); return; } wWorking.Progress(50 / strFiles.Length); ICryptoTransform ictEncryptor = saEncrypt.CreateEncryptor(); byte[] bMessage = cmMessage.GetEncoded(); byte[] bOutput = new byte[bMessage.Length]; ictEncryptor.TransformBlock(bMessage, 0, bMessage.Length, ref bOutput, 0); bKey.Initialize(); wWorking.Progress(10 / strFiles.Length); int iOutLength = (saEncrypt.BlockSize >> 3) + 2 + bMessage.Length; sedpEncrypted.Body = new byte[iOutLength]; Array.Copy(bOutput, 0, sedpEncrypted.Body, 0, iOutLength); byte[] bESK = esksKeys.GetEncoded(); byte[] bEncrypted = sedpEncrypted.Generate(); bReturn = new byte[bESK.Length + bEncrypted.Length]; bESK.CopyTo(bReturn, 0); bEncrypted.CopyTo(bReturn, bESK.Length); } else { wWorking.Progress(60 / strFiles.Length); bReturn = cmMessage.GetEncoded(); } wWorking.Progress(10 / strFiles.Length); try { FileStream fsOut = new FileStream(strFiles[i] + ".asc", FileMode.CreateNew); BinaryWriter bwWrite = new BinaryWriter(fsOut); bwWrite.Write(bReturn); bwWrite.Close(); fsOut.Close(); } catch (IOException io) { MessageBox.Show("Could not write to file. The following error occured: " + io.Message, "Error..."); } } wWorking.Hide(); }
public static string EncryptText(string strMessage, PublicKeyRing pkrPublicKeyRing, SecretKeyRing skrSecretKeyRing, bool bSign) { PublicKeySelector pksSelectKeys = new PublicKeySelector(pkrPublicKeyRing); pksSelectKeys.ShowDialog(); TransportableSecretKey tskKey = new TransportableSecretKey(); string strPassphrase = ""; if (bSign) { QueryPassphrase qpPassphrase = new QueryPassphrase(); qpPassphrase.ShowMyDialog(skrSecretKeyRing); tskKey = qpPassphrase.SelectedKey; strPassphrase = qpPassphrase.Passphrase; } if (pksSelectKeys.SelectedKeys.Count == 0) return strMessage; Working wWorking = new Working(); wWorking.Show(); LiteralMessage lmMessage = new LiteralMessage(DataFormatTypes.Text); lmMessage.Text = strMessage; lmMessage.TimeCreated = DateTime.Now; lmMessage.Filename = ""; SharpPrivacy.OpenPGP.Messages.Message mEncryptionMessage = lmMessage; if (bSign) { SignedMessage smMessage = new SignedMessage(); smMessage.MessageSigned = lmMessage; SignaturePacket spPacket = new SignaturePacket(); spPacket.Version = SignaturePacketVersionNumbers.v3; SecretKeyPacket skpKey = tskKey.FindKey(AsymActions.Sign); spPacket.KeyID = skpKey.PublicKey.KeyID; spPacket.HashAlgorithm = HashAlgorithms.SHA1; spPacket.SignatureAlgorithm = skpKey.PublicKey.Algorithm; spPacket.TimeCreated = DateTime.Now; spPacket.SignatureType = SignatureTypes.TextSignature; spPacket.Sign(lmMessage.Binary, skpKey, strPassphrase); smMessage.Signature = spPacket; mEncryptionMessage = smMessage; } CompressedMessage cmMessage = new CompressedMessage(); cmMessage.Compress(mEncryptionMessage); wWorking.Progress(20); SymAlgorithms saAlgo = GetSymAlgorithmPreferences(pksSelectKeys.SelectedKeys); SymmetricallyEncryptedDataPacket sedpEncrypted = new SymmetricallyEncryptedDataPacket(); SymmetricAlgorithm saEncrypt = CipherHelper.CreateSymAlgorithm(saAlgo); saEncrypt.Mode = CipherMode.OpenPGP_CFB; saEncrypt.GenerateKey(); byte[] bKey = saEncrypt.Key; wWorking.Progress(10); ESKSequence esksKeys = new ESKSequence(); try { esksKeys = CreateESKSequence(pksSelectKeys.SelectedKeys, AsymActions.Encrypt, saAlgo, bKey); } catch (Exception e) { wWorking.Hide(); MessageBox.Show("The following error occured: " + e.Message, "Error..."); return strMessage; } wWorking.Progress(50); ICryptoTransform ictEncryptor = saEncrypt.CreateEncryptor(); byte[] bMessage = cmMessage.GetEncoded(); byte[] bOutput = new byte[bMessage.Length]; ictEncryptor.TransformBlock(bMessage, 0, bMessage.Length, ref bOutput, 0); bKey.Initialize(); wWorking.Progress(10); int iOutLength = (saEncrypt.BlockSize >> 3) + 2 + bMessage.Length; sedpEncrypted.Body = new byte[iOutLength]; Array.Copy(bOutput, 0, sedpEncrypted.Body, 0, iOutLength); byte[] bESK = esksKeys.GetEncoded(); byte[] bEncrypted = sedpEncrypted.Generate(); byte[] bReturn = new byte[bESK.Length + bEncrypted.Length]; bESK.CopyTo(bReturn, 0); bEncrypted.CopyTo(bReturn, bESK.Length); wWorking.Progress(10); string strReturn = Radix64.Encode(bReturn, true); strReturn = Armor.WrapMessage(strReturn); wWorking.Hide(); return strReturn; }
protected virtual void InvokeWorking(string e) => Working?.Invoke(this, e);
public IActionResult for14days() { string result = ""; List <Personel> calisanListe = new List <Personel>(); List <Working> isListesi = new List <Working>(); Personel per1 = new Personel() { AdSoyad = "Rıdvan Can Kıran", isYuku = 0 }; Personel per2 = new Personel() { AdSoyad = "Yunus Emre Gezer", isYuku = 0 }; Personel per3 = new Personel() { AdSoyad = "Mehmet Ali Uyar", isYuku = 0 }; Personel per4 = new Personel() { AdSoyad = "Şahin Tutarsız", isYuku = 0 }; Personel per5 = new Personel() { AdSoyad = "Hasan Ali Ayrık", isYuku = 0 }; Personel per6 = new Personel() { AdSoyad = "Numan Akdağ", isYuku = 0 }; calisanListe.Add(per1); calisanListe.Add(per2); calisanListe.Add(per3); calisanListe.Add(per4); calisanListe.Add(per5); calisanListe.Add(per6); Working work1 = new Working() { isAdi = "Lojistik", zorluk = 1 }; Working work2 = new Working() { isAdi = "Planlama", zorluk = 2 }; Working work3 = new Working() { isAdi = "Üretim", zorluk = 3 }; Working work4 = new Working() { isAdi = "Kalite", zorluk = 4 }; Working work5 = new Working() { isAdi = "İnsan Kaynakları", zorluk = 5 }; Working work6 = new Working() { isAdi = "İş Güvenliği", zorluk = 6 }; isListesi.Add(work1); isListesi.Add(work2); isListesi.Add(work3); isListesi.Add(work4); isListesi.Add(work5); isListesi.Add(work6); foreach (var iss in isListesi) { result += $"{iss.isAdi} Bölümünün Zorluk Derecesi : {iss.zorluk}\n"; } for (int i = 1; i < 14; i++) { if (i % 2 != 0) { result += $"{i}. Gün\n"; result += TekGunCalis(calisanListe, isListesi); } else { result += $"{i}. Gün\n"; result += CiftGunCalis(calisanListe, isListesi); } } foreach (var per in calisanListe) { result += $"\n{per.AdSoyad} Toplamda {per.toplamİsYuku} birimlik iş yaptı.\n"; } return(Content(result)); }
public bool ContainsToQueueTKey(Working obj) { return(queueTKey.Contains(obj)); }
static void Main(string[] args) { while (true) { Console.Clear(); int registerOrLoginChoise = _menus.LogInOrRegisterMenu(); while (true) { if (registerOrLoginChoise == 1) { _user = _userService.LogIn(); if (_user == null) { Environment.Exit(0); } break; } else { Console.Clear(); _user = _userService.Register(); if (_user == null) { continue; } break; } } Console.Clear(); bool mainMenu = true; while (mainMenu) { Console.Clear(); switch (_menus.MainMenu()) { case 1: //Track time bool breakTrackMenu = true; while (breakTrackMenu) { Console.Clear(); switch (_menus.TrackMenu()) { case 1: //Reading Reading reading = new Reading(); reading.Stopwatch = _activitiesService.ActivityTime("reading"); MessageHelper.Color("Please enter number of pages that you have read", ConsoleColor.Green); reading.Pages = ValidationHelper.ParsedNumber(Console.ReadLine()); switch (_menus.ReadingMenu()) { case 1: reading.Type = Db.Enums.ReadingType.BellesLettres; break; case 2: reading.Type = Db.Enums.ReadingType.Fiction; break; case 3: reading.Type = Db.Enums.ReadingType.ProfessionalLiterature; break; } _readingService.InsertReading(reading); MessageHelper.Color($"Mr.{_user.LastName} you have been reading for {reading.Stopwatch.Elapsed.Seconds} seconds and you read {reading.Pages} pages from the book that has genre {reading.Type}", ConsoleColor.Yellow); Thread.Sleep(3000); break; case 2: //Excercising Exercising exercise = new Exercising(); exercise.Stopwatch = _activitiesService.ActivityTime("exercising"); switch (_menus.ExerciseMenu()) { case 1: exercise.ExcercisingType = Db.Enums.ExcercisingType.General; break; case 2: exercise.ExcercisingType = Db.Enums.ExcercisingType.Running; break; case 3: exercise.ExcercisingType = Db.Enums.ExcercisingType.Sport; break; } _exercisingService.InsertExercise(exercise); MessageHelper.Color($"Mr.{_user.LastName} you have been doing {exercise.ExcercisingType} exercise for {exercise.Stopwatch.Elapsed.Seconds}seconds", ConsoleColor.Yellow); Thread.Sleep(3000); break; case 3: //Working Working working = new Working(); working.Stopwatch = _activitiesService.ActivityTime("working"); switch (_menus.WorkingMenu()) { case 1: working.WorkingFrom = Db.Enums.WorkingFrom.Office; break; case 2: working.WorkingFrom = Db.Enums.WorkingFrom.Home; break; } _workingService.InsertWork(working); MessageHelper.Color($"Mr.{_user.LastName} you have been working from {working.WorkingFrom} for {working.Stopwatch.Elapsed.Seconds} seconds", ConsoleColor.Yellow); Thread.Sleep(3000); break; case 4: //Other Hobbies OtherHobbies otherHobbie = new OtherHobbies(); MessageHelper.Color("It's nice to try something new. What's the name of the new Hobby?", ConsoleColor.Green); otherHobbie.Name = Console.ReadLine(); otherHobbie.Stopwatch = _activitiesService.ActivityTime(otherHobbie.Name); _otherHobbiesService.InsertOtherHobbies(otherHobbie); MessageHelper.Color($"Mr.{_user.LastName} you have been doing your new hobbie {otherHobbie.Name} for {otherHobbie.Stopwatch.Elapsed.Seconds} seconds", ConsoleColor.Yellow); Thread.Sleep(3000); break; case 5: MessageHelper.Color("Going back to Main Menu!", ConsoleColor.Green); Thread.Sleep(2000); breakTrackMenu = false; break; } } break; case 2: //Statistics bool breakStatsMenu = true; while (breakStatsMenu) { Console.Clear(); switch (_menus.StatsMenu()) { case 1: //Reading Stats _readingService.Statistics(); MessageHelper.Color("Press any key to go back", ConsoleColor.Red); Console.ReadLine(); break; case 2: //Exercising stats _exercisingService.Statistics(); MessageHelper.Color("Press any key to go back", ConsoleColor.Red); Console.ReadLine(); break; case 3: //Working stats _workingService.Statistics(); MessageHelper.Color("Press any key to go back", ConsoleColor.Red); Console.ReadLine(); break; case 4: //OtherHobbies stats _otherHobbiesService.Statistics(); MessageHelper.Color("Press any key to go back", ConsoleColor.Red); Console.ReadLine(); break; case 5: //Global stats List <int> globalList = new List <int> { _exercisingService.TotalSeconds(), _otherHobbiesService.TotalSeconds(), _readingService.TotalSeconds(), _workingService.TotalSeconds() }; int favoriteActivity = globalList.Max(); Console.WriteLine($"Total activity time: {_activitiesService.TotalActivityTime(globalList)}seconds"); if (favoriteActivity != 0) { if (favoriteActivity == _exercisingService.TotalSeconds()) { Console.WriteLine("Favorite activity: Exercise"); } else if (favoriteActivity == _otherHobbiesService.TotalSeconds()) { Console.WriteLine("Favorite activity: Hobbie"); } else if (favoriteActivity == _readingService.TotalSeconds()) { Console.WriteLine("Favorite activity: Reading"); } else { Console.WriteLine("Favorite activity: Working"); } } else { Console.WriteLine("You don't have favorite activity yet"); } MessageHelper.Color("Press any key to go back", ConsoleColor.Red); Console.ReadLine(); break; case 6: MessageHelper.Color("Going back to Main Menu!", ConsoleColor.Green); Thread.Sleep(2000); breakStatsMenu = false; break; } } break; case 3: //Acc Management bool accMng = true; while (accMng) { Console.Clear(); switch (_menus.AccManagement()) { case 1: //change password Console.Clear(); Console.WriteLine($"Mr. {_user.LastName}, please enter new password"); _userService.ChangePassword(_user.Id, _user.Password, Console.ReadLine()); break; case 2: //change First and Last Name Console.Clear(); Console.WriteLine("Please enter new First name"); string firstName = Console.ReadLine(); Console.WriteLine("Please enter new Last name"); string lastName = Console.ReadLine(); _userService.ChangeInfo(_user.Id, firstName, lastName); break; case 3: Console.Clear(); _userService.RemoveUser(_user.Id); Console.WriteLine("Deactivating the account. Thank you for using our service"); Styles.Spiner(); MessageHelper.Color("The account has been deactivated", ConsoleColor.Red); mainMenu = false; break; case 4: MessageHelper.Color("Going back to Main Menu!", ConsoleColor.Green); Thread.Sleep(2000); accMng = false; break; } } break; case 4: _user = null; MessageHelper.Color("Thank you for using our application! Have a good day!", ConsoleColor.Green); mainMenu = false; break; } } } }
private void DataTableView_Load(object sender, EventArgs args) { Dock = DockStyle.Fill; work = FindForm() as Working; DataTable info = DBControl.Schema("Tables", new[] { null, null, name }); if (info.Rows.Count == 0) { describe.Visible = false; return; } description.Text = info.Rows[0]["DESCRIPTION"] as string; foreach (DataGridViewColumn column in data.Columns) { var tool = new ToolStripMenuItem(column.HeaderText) { Checked = true, CheckOnClick = true }; tool.CheckedChanged += SelectColumn; selector.Items.Add(tool); if (column is DataGridViewImageColumn) { column.ContextMenuStrip = imageSelector; } } foreach (DataRow row in DBControl.ForeignKeys.Select("FK_TABLE_NAME = '" + name + "'")) { var column = data.Columns[row["FK_COLUMN_NAME"].ToString()]; var header = column.HeaderCell; var style = header.Style; style.Font = new Font(style.Font ?? Font, FontStyle.Underline); column.Tag = row["PK_TABLE_NAME"]; header.Tag = row["PK_COLUMN_NAME"]; } DataTable columns = DBControl.Schema("COLUMNS", new[] { null, null, name }); foreach (DataRow row in columns.Rows) { var column = data.Columns[row["COLUMN_NAME"] as string]; if ((bool)row["COLUMN_HASDEFAULT"]) { var def = row["COLUMN_DEFAULT"]; if (def is string) { def = def.ToString().Trim('"'); } if (column.ValueType == typeof(bool)) { if (def.Equals("No")) { def = false; } else if (def.Equals("Yes")) { def = true; } } column.DefaultCellStyle.NullValue = def; } column.ToolTipText = row["DESCRIPTION"] as string; } }
public void InsertWork(Working working) { _workingDb.InsertActivity(working); this.SaveWorking(); }
public void AddWorkingActivity(Working working) { _workingActivityDb.InsertActivity(working); }
static void Main(string[] args) { while (true) { Console.Clear(); int registerOrLoginChoise = _menus.LogInOrRegisterMenu(); while (true) { if (registerOrLoginChoise == 1) { _user = _userService.LogIn(); if (_user == null) { Environment.Exit(0); } break; } else { Console.Clear(); _user = _userService.Register(); if (_user == null) { continue; } break; } } Console.Clear(); bool mainMenu = true; while (mainMenu) { Console.Clear(); switch (_menus.MainMenu()) { case 1: //Track time bool trackMenu = true; while (trackMenu) { Console.Clear(); switch (_menus.TrackMenu()) { case 1: //Reading Reading reading = new Reading(); reading.User = _user; var timeSpentReading = _activitiesService.TimeSpentOnActivity("reading", _stopwatch); reading.TimeSpentInSeconds += timeSpentReading; MessageHelper.Color("Please enter number of pages that you have read", ConsoleColor.Green); int numberOfPages; var isNumber = int.TryParse(Console.ReadLine(), out numberOfPages); reading.Pages = numberOfPages; switch (_menus.ReadingMenu()) { case 1: reading.GenreOfBook = GenreOfBook.BellesLettres; break; case 2: reading.GenreOfBook = GenreOfBook.Fiction; break; case 3: reading.GenreOfBook = GenreOfBook.ProfessionalLiterature; break; } _readingService.InsertReading(reading); MessageHelper.Color($"{_user.LastName} you have been reading for {reading.TimeSpentInSeconds} seconds and you read {reading.Pages} pages from the book that has genre {reading.GenreOfBook}", ConsoleColor.Yellow); Thread.Sleep(3000); break; case 2: //Excercising Exercising exercise = new Exercising(); exercise.User = _user; var timeSpentExercising = _activitiesService.TimeSpentOnActivity("exercising", _stopwatch); exercise.TimeSpentInSeconds += timeSpentExercising; switch (_menus.ExerciseMenu()) { case 1: exercise.TypeOfExercise = TypeOfExercise.General; break; case 2: exercise.TypeOfExercise = TypeOfExercise.Running; break; case 3: exercise.TypeOfExercise = TypeOfExercise.Sport; break; } _exercisingService.StartExercise(exercise); MessageHelper.Color($"{_user.LastName} you have been doing {exercise.TypeOfExercise} exercise for {exercise.TimeSpentInSeconds} seconds", ConsoleColor.Yellow); Thread.Sleep(3000); break; case 3: //Working Working working = new Working(); working.User = _user; var timeSpentWorking = _activitiesService.TimeSpentOnActivity("working", _stopwatch); working.TimeSpentInSeconds += timeSpentWorking; switch (_menus.WorkingMenu()) { case 1: working.WorkingFrom = WorkingFrom.Office; break; case 2: working.WorkingFrom = WorkingFrom.Home; break; } _workingService.InsertWork(working); MessageHelper.Color($"{_user.LastName} you have been working from {working.WorkingFrom} for {working.TimeSpentInSeconds} seconds", ConsoleColor.Yellow); Thread.Sleep(3000); break; case 4: //Hobies MessageHelper.Color("What's the name of the new Hobby?", ConsoleColor.Green); var nameOfHobie = Console.ReadLine(); Hobie hobie = _hobiesService.GetHobie(nameOfHobie) ?? new Hobie(); hobie.User = _user; var timeSpentOnHobie = _activitiesService.TimeSpentOnActivity("hobie", _stopwatch); hobie.TimeSpentInSeconds += timeSpentOnHobie; _hobiesService.InsertHobies(hobie); MessageHelper.Color($"{_user.LastName} you have been doing your new hobbie {hobie.NameOfHobie} for {hobie.TimeSpentInSeconds} seconds", ConsoleColor.Yellow); Thread.Sleep(3000); break; case 5: MessageHelper.Color("Going back to Main Menu!", ConsoleColor.Green); Thread.Sleep(2000); trackMenu = false; break; } } break; case 2: //Statistics bool StatsMenu = true; while (StatsMenu) { Console.Clear(); switch (_menus.StatsMenu()) { case 1: //Reading Stats _readingService.Statistics(_user); MessageHelper.Color("Press any key to go back", ConsoleColor.Red); Console.ReadLine(); break; case 2: //Exercising stats _exercisingService.Statistics(_user); MessageHelper.Color("Press any key to go back", ConsoleColor.Red); Console.ReadLine(); break; case 3: //Working stats _workingService.Statistics(_user); MessageHelper.Color("Press any key to go back", ConsoleColor.Red); Console.ReadLine(); break; case 4: //OtherHobbies stats _hobiesService.Statistics(_user); MessageHelper.Color("Press any key to go back", ConsoleColor.Red); Console.ReadLine(); break; case 5: //Global stats Dictionary <string, int> dict = new Dictionary <string, int>(); dict.Add("Reading", _readingService.TotalSeconds()); dict.Add("Working", _workingService.TotalSeconds()); dict.Add("Hobies", _hobiesService.TotalSeconds()); dict.Add("Exercise", _exercisingService.TotalSeconds()); var favouriteActivity = dict.Aggregate((l, r) => l.Value > r.Value ? l : r); var totalActiviyTime = dict.Sum(x => x.Value); Console.WriteLine($"Total activity time: {totalActiviyTime / (double)3600 } hours"); if (favouriteActivity.Value == 0) { Console.WriteLine("You don't have favorite activity yet"); } else { Console.WriteLine("Favorite activity: " + favouriteActivity.Key); } MessageHelper.Color("Press any key to go back", ConsoleColor.Red); Console.ReadLine(); break; case 6: MessageHelper.Color("Going back to Main Menu!", ConsoleColor.Green); Thread.Sleep(2000); StatsMenu = false; break; } } break; case 3: //Acc Management bool manageAccaount = true; while (manageAccaount) { Console.Clear(); switch (_menus.AccManagement()) { case 1: //change password Console.Clear(); Console.WriteLine($"Mr. {_user.LastName}, please enter new password"); _userService.ChangePassword(_user.Id, _user.Password, Console.ReadLine()); break; case 2: //change First and Last Name Console.Clear(); Console.WriteLine("Please enter new First name"); string firstName = Console.ReadLine(); Console.WriteLine("Please enter new Last name"); string lastName = Console.ReadLine(); _userService.ChangeInfo(_user.Id, firstName, lastName); break; case 3: Console.Clear(); _userService.RemoveUser(_user.Id); Console.WriteLine("Deactivating the account. Thank you for using our service"); MessageHelper.Color("The account has been deactivated", ConsoleColor.Red); mainMenu = false; break; case 4: MessageHelper.Color("Going back to Main Menu!", ConsoleColor.Green); Thread.Sleep(2000); manageAccaount = false; break; } } break; case 4: _user = null; MessageHelper.Color("Thank you for using our application! Have a good day!", ConsoleColor.Green); mainMenu = false; break; } } } }