Beispiel #1
0
        private void MainWindow_KeyDown(object sender, KeyEventArgs e)
        {
            if (bEntryMode || e.Key != Key.Delete)
            {
                return;
            }

            Button but = sender as Button;

            if (selectedItem == null)
            {
                MessageBox.Show("please select a line first", "Form error");
                return;
            }
            using (var db = new EditorDb())
            {
                FormEntry item = selectedBlock.questions.Where(i => i.linenum == selectedItem.linenum).SingleOrDefault();
                selectedBlock.questions.Remove(selectedItem);
                db.Entry(selectedItem).State = System.Data.Entity.EntityState.Deleted;
                for (int line = selectedItem.linenum + 1; line <= lines.Count; line++)
                {
                    item                 = selectedBlock.questions.Where(i => i.linenum == line).SingleOrDefault();
                    item.linenum         = item.linenum - 1;
                    db.Entry(item).State = System.Data.Entity.EntityState.Modified;   //EF change tracking not working
                }
                db.SaveChanges();
                //   MessageBox.Show(string.Format("Line {0} removed", formRowSelected));
                Refresh();
            }
        }
Beispiel #2
0
        void removeline(FormEntry item)
        {
            itemResponse response = new itemResponse()
            {
                Name     = selectedBlock.Name,
                linenum  = item.linenum,
                start    = startBlock,
                userName = ((App)Application.Current).activeUser.Name,
                type     = item.type,
                var1     = item.Var1,
                var2     = item.Var2,
                var3     = item.Var3
            };

            FindType(item, typeof(Button));
            FindType(item, typeof(StackPanel));
            buts.ForEach(b => rootGrid.Children.Remove(b));
            stacks.ForEach(s => rootGrid.Children.Remove(s));
            selectedBlock.CurrentItem = item.linenum;
            responses.Add(response);

            using (var db = new EditorDb())
            {
                // db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                db.Responses.Add(response);
                db.SaveChanges();
            }
            lines.Remove(item);
            itemNumber = -1;
            CheckForFinish(selectedBlock);
        }
Beispiel #3
0
 public Login()
 {
     using (var db = new EditorDb())
     {
         users = db.Users.ToList();
     }
     InitializeComponent();
     Loaded += Login_Loaded;
 }
Beispiel #4
0
        public CreateUsers()
        {
            InitializeComponent();
            using (var db = new EditorDb())
            {
                users = db.Users.ToList();
            }

            users = users.Where(u => u.Level == 2).ToList();
            CarrierNames.Add("ATT");
            CarrierNames.Add("Verizon");
            CarrierNames.Add("TMobile");
            Carriers.ItemsSource   = CarrierNames;
            Carriers.SelectedIndex = 0;
        }
Beispiel #5
0
        private void Admin_Loaded(object sender, RoutedEventArgs e)
        {
            db = new EditorDb();

            BlockNames = new List <string>();
            blocks.ForEach(b => BlockNames.Add(b.Name));
            Blocks.ItemsSource    = BlockNames;
            Blocks.SelectedIndex  = 0;
            Blocks2.ItemsSource   = BlockNames;
            Blocks2.SelectedIndex = 0;

            selectedBlock = blocks[0];

            startTimeBlock1.Value = Convert.ToDateTime(selectedBlock.ExpectedStart.ToString());
        }
Beispiel #6
0
        void TextManager(Block blok, string messagein)
        {
            List <User> admins = null;

            using (var db = new EditorDb())
            {
                admins = db.Users.Where(u => u.Level == 1).ToList();
            }

            string message = string.Format("Block{0} ", blok.Name) + messagein;

            foreach (User user in admins)
            {
                var carrierEmail = ConfigurationManager.AppSettings[user.carrier];
                sendText(user.phoneNumber + "@" + carrierEmail, message);
            }
        }
Beispiel #7
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            if (Name.Text.Count() == 0)
            {
                MessageBox.Show("Name must be filled in");
                return;
            }
            if (Password.Password.Count() == 0)
            {
                MessageBox.Show("Password must be filled in");
                return;
            }
            //use regex to remove all the non-numerics
            StringBuilder sb = new StringBuilder();

            foreach (Match m in Regex.Matches(Phonenum.Text, pattern))
            {
                sb.Append(m);
            }
            User user = new User()
            {
                carrier     = CarrierNames[Carriers.SelectedIndex],
                Level       = 2,
                Name        = Name.Text,
                phoneNumber = sb.ToString(),
                Password    = Password.Password
            };

            using (var db = new EditorDb())
            {
                User test = db.Users.Where(u => u.Name == Name.Text).SingleOrDefault();
                if (test != null)
                {
                    MessageBox.Show("user already exists");
                    return;
                }
                db.Users.Add(user);
                db.SaveChanges();
            }
            Userstuff.Visibility = Visibility.Collapsed;
        }
Beispiel #8
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (((App)Application.Current).activeUser != null)
            {
                IdleTime += 1;
                //logout idle users
                if (IdleTime > idletimeout * 60)
                {
                    Login.Content        = "Login";
                    Add.Visibility       = Visibility.Collapsed;
                    Configure.Visibility = Visibility.Collapsed;
                    UserAdmin.Visibility = Visibility.Collapsed;
                    ((App)Application.Current).activeUser = null;
                    rootGrid.IsEnabled = false;
                    Start.IsEnabled    = false;
                    IdleTime           = 0;
                }
            }
            persistTimeout += 1;
            if (persistTimeout > 30)
            {
                persistTimeout = 0;
                using (var db = new EditorDb())
                {
                    blocks.ForEach(b => db.Entry(b).State = System.Data.Entity.EntityState.Modified);
                    db.SaveChanges();
                }
            }
            //look for first block that did not start in time
            foreach (Block blok in blocks)
            {
                //each block of work has an expected start time and if it is passed then imform the managers
                TimeSpan expected = blok.ExpectedStart;
                DateTime now      = DateTime.Now;
                DateTime eTime    = new DateTime(now.Year, now.Month, now.Day, expected.Hours, expected.Minutes, 0);
                //if (instanceStart < eTime)  //should never need this check as program should not be stopped
                //{
                if (DateTime.Now > eTime && !blok.bExpectedMessageSent && blok.State != (int)states.done)
                {
                    TextManager(blok, "did not start in time");
                    blok.bExpectedMessageSent = true;
                    return;
                }
                //}
            }
            //now look for blocks that did not complate in time
            foreach (Block blok in blocks)
            {
                if (blok.State == (int)states.active)
                {
                    //clock ran out tell manager
                    if (blok.TimeLefttoComplete == 0 && !blok.bWorkNotFinishedinTime)
                    {
                        blok.Warning  = false;
                        blok.TimedOut = true;
                        MessageBox.Show("work was not completed in time, manager notified", "Severe Error", MessageBoxButton.OK, MessageBoxImage.Stop);

                        blok.bWorkNotFinishedinTime = true;
                        //did not complete in time so tell managers that and the unfinished questions
                        string[] unfinished = blok.questions.Where(q => q.linenum > blok.CurrentItem).OrderBy(l => l.linenum).Select(l => l.label1).ToArray();


                        string someString = String.Join(
                            Environment.NewLine, unfinished);
                        TextManager(blok, someString);
                        return;
                    }
                    if (blok.TimeLefttoComplete == 0)   //message was shown but still allow the user to finish block
                    {
                        return;
                    }
                    blok.TimeLefttoComplete -= 1;
                    if (blok.TimeLefttoComplete < 120)    //2 minute warning
                    {
                        blok.Warning = true;
                        return;
                    }
                    if (blok.TimeLefttoComplete < 300 && !blok.bnMinuteWarningSent)    //5 minute warningtext the user
                    {
                        string message            = string.Format("5 minutes left to complete block {0}", selectedBlock.Name);
                        var    carrierEmailServer = ConfigurationManager.AppSettings[((App)Application.Current).activeUser.carrier];

                        sendText(((App)Application.Current).activeUser.phoneNumber + "@" + carrierEmailServer, message);
                        blok.bnMinuteWarningSent = true;
                        return;
                    }
                    //  CheckForFinish(blok);
                }
            }
        }
Beispiel #9
0
        public MainWindow()
        {
            InitializeComponent();

            KeyDown += MainWindow_KeyDown;
            Closing += MainWindow_Closing;
            using (var db = new EditorDb())
            {
                blocks = db.Blocks
                         .Include(b => b.questions).ToList();
                DateTime ruleData = Convert.ToDateTime(DateTime.Now).Date;
                responses = db.Responses.Where(r => DbFunctions.TruncateTime(r.start) == ruleData).OrderBy(r => r.Name).ThenBy(r => r.linenum).ToList();
            }
            // blocks = db.Blocks.ToList();
            blockinfo.ItemsSource = blocks;
            blockinfo.DataContext = blocks;

            // testing selectedBlock = blocks[0];
            BlockNames = new List <string>();
            foreach (Block blok in blocks)
            {
                if (blok.TimeLefttoComplete == 0)   //completed last time
                {
                    blok.TimeLefttoComplete = blok.timer * 60;
                }

                BlockNames.Add(blok.Name);

                CheckforCompletion(blok);
            }
            //find the first block that is not done and make it active
            List <Block> activeblocks = blocks.Where(b => b.State != (int)states.done).ToList();

            if (activeblocks.Count == 0)
            {
                selectedBlock = blocks[0];
            }
            else
            {
                selectedBlock = activeblocks[0];
            }
            int index = 0;

            foreach (Block blok in blocks)
            {
                if (blok.State != (int)states.done)
                {
                    blockinfo.SelectedIndex = index;
                    break;
                }
                index++;
            }

            itemNumber = -1;
            Refresh();
            rootGrid.IsEnabled = false;
            timer          = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(60);
            timer.Tick    += Timer_Tick;
            timer.Start();
        }
Beispiel #10
0
        private void Next_Click(object sender, RoutedEventArgs e)
        {
            int  newLineNum         = 1;
            bool insertingAfterLine = false;
            bool bchecked           = false;
            var  selected           = Types.SelectedItem as TabItem;

            using (var db = new EditorDb())
            {
                if (top.IsChecked == true)
                {
                    bchecked = true;
                    for (int line = 0; line < lines.Count; line++)
                    {
                        int oldLineNumber = lines[line].linenum++;
                        db.Entry(lines[line]).State = System.Data.Entity.EntityState.Modified;
                    }
                }
                if (Bottom.IsChecked == true)
                {
                    bchecked = true;

                    newLineNum = lines[lines.Count - 1].linenum + 1;
                }
                if (bchecked == false)
                {
                    if (Int32.TryParse(Linenum.Text, out newLineNum))
                    {
                        //note reverse order to avoid duplicate line numbers
                        for (int line = lines.Count; line > newLineNum; line--)
                        {
                            FormEntry item = block.questions.Where(i => i.linenum == line).SingleOrDefault();

                            item.linenum         = item.linenum + 1;
                            db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        }
                    }
                    newLineNum++;
                }
                FormEntry form = new FormEntry();
                if ((String)selected.Header == "Type 1")
                {
                    form = new FormEntry()
                    {
                        type      = 1,
                        linenum   = newLineNum,
                        label1    = Label1.Text,
                        label2    = Label2.Text,
                        checkbox1 = Check1.Text,
                        checkbox2 = Check2.Text
                    };
                    Label1.Text = "";

                    Check1.Text = "Yes";
                    Check2.Text = "No";
                }
                if ((String)selected.Header == "Type 2")
                {
                    form = new FormEntry()
                    {
                        type    = 2,
                        linenum = newLineNum,
                        label1  = T2Label1.Text,
                        label2  = T2Label2.Text,
                        label3  = T2Label3.Text,
                        label4  = T2Label4.Text
                    };
                    form.var1Type = choices.SelectedIndex;
                    form.var2Type = choices1.SelectedIndex;
                    form.var3Type = choices2.SelectedIndex;
                    T2Label1.Text = "";
                    T2Label2.Text = "";
                    T2Label3.Text = "";
                    T2Label4.Text = "";
                }
                if ((String)selected.Header == "Type 3")
                {
                    form = new FormEntry()
                    {
                        type    = 3,
                        linenum = newLineNum,
                        label1  = T3Label1.Text
                    };
                    if (MakeBold.IsChecked == true)
                    {
                        form.isBold = true;
                    }
                }



                lines.Add(form);
                block.questions.Add(form);
                db.Entry(form).State  = System.Data.Entity.EntityState.Added;
                db.Entry(block).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            Linenum.Text = newLineNum.ToString();
        }
 public EditoresController()
 {
     _EditorBd = new EditorDb();
 }