/* Called by form1's wrapper function
         * Encapsulates an order with an OrderContainer, adds the order to the order list.
         * Then confirms the order
         */
        public void DoAddOrderToListAndConfirmOrder(Order order, bool isAdjustedOrder)
        {
            OrderContainer orderCon = new OrderContainer(order);

            if (isAdjustedOrder)
            {
                orderCon.Status = "Active(Adjusted)";
            }

            OrderList.Add(orderCon); //Add the OrderContainer to the OrderList to update the UI list

            //there seems to be a bug where an existing messageId tries to be inserted again
            try {
                OrderTableByMsgId.Add(order.MessageId, orderCon); //Insert the entry into the table for easily updating order status
            } catch (Exception e) {
                Debug.WriteLine(order.MessageId + " already inserted in OrderTable. " + e.Message);
            }

            if (order.Service == "GrubHub")
            {
                InsertToOrderNumTable(orderCon);                             //We insert the entry into the table with orderNum as the key
            }
            //Automatically confirm the order, if the URL was successfully parsed
            if (order.ConfirmURL != "Failed to parse")
            {
                ConfirmOrder(orderCon);
            }
            UpdateOrderUI();                          //Update the Item List in the GUI to match the selected row
            PlaySound(Program.NotificationSoundPath); //play the nofication sound
        }
Esempio n. 2
0
        private void ButtonSearch_Click(object sender, EventArgs e)
        {
            SectionController   scontroller = new SectionController();
            List <SectionModel> sectionList = scontroller.GetByFaculty(faculty);

            dataGridViewSerial.ScrollBars = ScrollBars.None;

            MySortableBindingList <ProperStudentUserModel> properStudentList = new MySortableBindingList <ProperStudentUserModel>();

            foreach (SectionModel model in sectionList)
            {
                UserController          ucontroller             = new UserController();
                List <StudentUserModel> studentListByAcademicId = ucontroller.SearchByAcademidIdAndSectionId(textBoxSearch.Text, model.Id);
                //Console.WriteLine(studentListByAcademicId.Count + " student found in " + model.SectionName);
                foreach (StudentUserModel smodel in studentListByAcademicId)
                {
                    ProperStudentUserModel properStudentModel = new ProperStudentUserModel();
                    properStudentModel.AcademicId = smodel.AcademicId;
                    properStudentModel.FirstName  = smodel.FirstName;
                    properStudentModel.Id         = smodel.Id;
                    properStudentModel.LastName   = smodel.LastName;

                    properStudentModel.SectionName = model.SectionName;

                    properStudentList.Add(properStudentModel);
                }
                List <StudentUserModel> studentListByName = ucontroller.SearchByNameAndSectionId(textBoxSearch.Text, model.Id);
                //Console.WriteLine(studentListByName.Count + " student found in " + model.SectionName);
                foreach (StudentUserModel smodel in studentListByName)
                {
                    ProperStudentUserModel properStudentModel = new ProperStudentUserModel();
                    properStudentModel.AcademicId = smodel.AcademicId;
                    properStudentModel.FirstName  = smodel.FirstName;
                    properStudentModel.Id         = smodel.Id;
                    properStudentModel.LastName   = smodel.LastName;

                    properStudentModel.SectionName = model.SectionName;

                    properStudentList.Add(properStudentModel);
                }
            }

            foreach (ProperStudentUserModel student in properStudentList)
            {
                dataGridViewSerial.Rows.Add();
            }

            dataGridViewStudentList.DataBindingComplete += (o, ev) =>
            {
                foreach (DataGridViewRow row in dataGridViewSerial.Rows)
                {
                    row.Cells["sln"].Value = (row.Index + 1).ToString();
                }
                foreach (DataGridViewColumn column in dataGridViewStudentList.Columns)
                {
                    column.SortMode = DataGridViewColumnSortMode.Programmatic;
                }
            };

            dataGridViewStudentList.AutoGenerateColumns = false;
            dataGridViewStudentList.DataSource          = properStudentList;

            dataGridViewStudentList.Update();
            dataGridViewStudentList.Refresh();

            dataGridViewSerial.Update();
            dataGridViewSerial.Refresh();

            foreach (DataGridViewColumn column in dataGridViewStudentList.Columns)
            {
                column.SortMode = DataGridViewColumnSortMode.Automatic;
            }
        }
Esempio n. 3
0
        public static bool UpdateAuthorInfo(string page, Author author)
        {
            Match match = Regex.Match(page, @"Обновлялось:</font></a></b>\s*(.*?)\s*$", RegexOptions.Multiline);
            DateTime date = DateTime.MinValue;
            bool retValue = false;
            if (match.Success)
            {
                string[] newDateStr = match.Groups[1].Value.Split('/');
                date = new DateTime(int.Parse(newDateStr[2]), int.Parse(newDateStr[1]), int.Parse(newDateStr[0]));
            }

            if (author != null)
            {
                #region проанализируем данные на страничке. если раньше их не загружали, то в любом случае не показываем, что есть обновления, просто заполняем данные
                MySortableBindingList<AuthorText> texts_temp = new MySortableBindingList<AuthorText>();
                MatchCollection matches = Regex.Matches(page, "<DL><DT><li>(?:<font.*?>.*?</font>)?\\s*(<b>(?<Authors>.*?)\\s*</b>\\s*)?<A HREF=(?<LinkToText>.*?)><b>\\s*(?<NameOfText>.*?)\\s*</b></A>.*?<b>(?<SizeOfText>\\d+)k</b>.*?<small>(?:Оценка:<b>(?<DescriptionOfRating>(?<rating>\\d+(?:\\.\\d+)?).*?)</b>.*?)?\\s*\"(?<Section>.*?)\"\\s*(?<Genres>.*?)?\\s*(?:<A HREF=\"(?<LinkToComments>.*?)\">Комментарии:\\s*(?<CommentsDescription>(?<CommentCount>\\d+).*?)</A>\\s*)?</small>.*?(?:<br><DD>(?<Description>.*?))?</DL>");
                if (matches.Count > 0)
                {
                    int cnt = 0;
                    foreach (Match m in matches)
                    {
                        AuthorText item = new AuthorText();
                        item.Description = NormalizeHTML(m.Groups["Description"].Value).Trim();
                        item.Genres = NormalizeHTML(m.Groups["Genres"].Value);
                        item.Link = m.Groups["LinkToText"].Value;
                        item.Name = NormalizeHTML(m.Groups["NameOfText"].Value);
                        item.Order = cnt;
                        item.SectionName = NormalizeHTML(m.Groups["Section"].Value).Replace("@","");
                        item.Size = int.Parse(m.Groups["SizeOfText"].Value);
                        texts_temp.Add(item);
                        cnt++;
                    }
                }
                if (author.Texts.Count > 0) // если раньше загружали проводим стравнение
                {
                    foreach (AuthorText txt in texts_temp)
                    {
                        bool bFound = false;
                        for (int i = 0; i < author.Texts.Count; i++)
                        {
                            if (txt.Description == author.Texts[i].Description
                                && txt.Name == author.Texts[i].Name
                                && txt.Size == author.Texts[i].Size)
                            {
                                bFound = true;
                                txt.IsNew = author.Texts[i].IsNew;// переносим значение isNew в новый массив, чтобы не потерять непрочитанные новые тексты
                                break;
                            }
                        }
                        if (!bFound)
                        {
                            txt.IsNew = author.IsNew = retValue = true;// да, автор обновился
                            if (date <= author.UpdateDate) // поменяем дату на сегодняшнюю, если дата обновления на страничке старее, чем зарегистрированная у нас
                                author.UpdateDate = DateTime.Today;
                            else // иначе ставим дату, указанную автором
                                author.UpdateDate = date;
                        }
                    }
                    // доп проверка по количеству произведений
                    if (texts_temp.Count != author.Texts.Count)
                    {
                        retValue = true;
                        if (date <= author.UpdateDate) // поменяем дату на сегодняшнюю, если дата обновления на страничке старее, чем зарегистрированная у нас
                            author.UpdateDate = DateTime.Today;
                        else// иначе ставим дату, указанную автором
                            author.UpdateDate = date;
                    }

                    // запоминаем новые данные
                }
                author.Texts = texts_temp;
                #endregion
            }
            return retValue;
        }