private void AddActivity(DevExpress.Spreadsheet.Cell cellTempActivity) { try { if (!cellTempActivity.Value.IsEmpty) { DateTime date; String[] splitCellActivity = cellTempActivity.Value.ToString().Split(new char[] { '-', '=' }); string strActivity = ""; string strActivityShortcut = ""; if (!DateTime.TryParseExact(cellTempActivity.Value.ToString(), "MMMM", new CultureInfo("en-US"), DateTimeStyles.None, out date)) { if (splitCellActivity.Count() == 1) { splitCellActivity = cellTempActivity.Value.ToString().Split(' '); strActivityShortcut = splitCellActivity.Last().Trim(); strActivity = cellTempActivity.Value.ToString().Replace(cellTempActivity.Value.ToString(), "").Trim(); } else { strActivityShortcut = splitCellActivity[1].Trim(); strActivity = splitCellActivity[0].Trim(); } if (strActivity.Equals("") || strActivityShortcut.Equals("")) { } else { using (var context = new LorikeetAppEntities()) { var checkIfActivityExists = (from l in context.Labels where l.Shortcut == strActivityShortcut select l).DefaultIfEmpty().First(); if (checkIfActivityExists == null) { var activityLabel = new Lorikeet.Data.Label(); activityLabel.DisplayName = strActivity; activityLabel.MenuCaption = strActivity; activityLabel.Shortcut = strActivityShortcut; Random r = new Random(DateTime.Now.Millisecond); Color randomColor = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255)); activityLabel.Color = randomColor.ToArgb(); context.Labels.Add(activityLabel); context.SaveChanges(); } } } } } } catch (Exception ex) { MessageBox.Show(MiscStuff.GetAllMessages(ex)); return; } }
private string addActivity(string activityShortcut, ref Cell cellToEdit) { try { var formGetInput = new FormAddActivity(activityShortcut); DialogResult dr = new DialogResult(); dr = formGetInput.ShowDialog(); if (dr == DialogResult.OK) { using (var context = new LorikeetAppEntities()) { var activityLabel = new Lorikeet.Data.Label { DisplayName = formGetInput.activity, MenuCaption = formGetInput.activity, Shortcut = activityShortcut }; Random r = new Random(DateTime.Now.Millisecond); Color randomColor = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255)); activityLabel.Color = randomColor.ToArgb(); context.Labels.Add(activityLabel); context.SaveChanges(); } return(formGetInput.activity); } else { string cellString = cellToEdit.Value.ToString(); cellString.Replace(activityShortcut, formGetInput.shortcut); cellToEdit.SetValueFromText(formGetInput.shortcut); using (var context = new LorikeetAppEntities()) { var getActivityLabel = (from l in context.Labels where l.Shortcut == activityShortcut select l).FirstOrDefault(); if (getActivityLabel != null) { return(getActivityLabel.DisplayName); } else { return(null); } } } } catch (Exception ex) { MessageBox.Show(MiscStuff.GetAllMessages(ex)); DialogResult = DialogResult.Abort; return(null); } }