Пример #1
0
        private void ExtractPaddies()
        {
            var nameIndex = 0;
            var codeIndex = 0;

            foreach (DataGridViewColumn column in NamesGrid.Columns)
            {
                if (!column.HeaderText.Equals("DPName", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                nameIndex = column.DisplayIndex;
                break;
            }

            foreach (DataGridViewColumn column in NamesGrid.Columns)
            {
                if (!column.HeaderText.Equals("BranchCode", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                codeIndex = column.DisplayIndex;
                break;
            }
            foreach (DataGridViewRow row in NamesGrid.Rows)
            {
                try
                {
                    var value = row.Cells[nameIndex].Value;
                    if (value != null)
                    {
                        var paddie = new Paddie
                        {
                            Name       = value.ToString(),
                            BranchCode = row.Cells[codeIndex]?.Value?.ToString()
                        };

                        if (paddies.All(o => o.Name != paddie.Name))
                        {
                            paddies.Add(paddie);
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
            using (var context = new DalexDbContext())
            {
                context.Paddies.AddRange(paddies);
                context.SaveChanges();
                //MessageBox.Show(@"Success");
            }
        }
Пример #2
0
        private void ExtractBranches()
        {
            int branchIndex = 0;
            int codeIndex   = 0;

            foreach (DataGridViewColumn column in NamesGrid.Columns)
            {
                if (!column.HeaderText.Equals("Branch", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                branchIndex = column.DisplayIndex;
                break;
            }
            foreach (DataGridViewColumn column in NamesGrid.Columns)
            {
                if (!column.HeaderText.Equals("BranchCode", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                codeIndex = column.DisplayIndex;
                break;
            }
            foreach (DataGridViewRow row in NamesGrid.Rows)
            {
                try
                {
                    var value = row.Cells[branchIndex].Value;
                    if (value != null)
                    {
                        var branch = new Branch
                        {
                            Name = value.ToString(),
                            Code = row.Cells[codeIndex].Value?.ToString()
                        };


                        if (branches.All(o => o.Code != branch.Code))
                        {
                            branches.Add(branch);
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
            using (var context = new DalexDbContext())
            {
                context.Branches.AddRange(branches);
                context.SaveChanges();
                //MessageBox.Show(@"Success");
            }
        }
Пример #3
0
        private void ExtractTickets()
        {
            var nameIndex       = 0;
            var branchNameIndex = 0;
            var phoneIndex      = 0;

            foreach (DataGridViewColumn column in AttendantGrid.Columns)
            {
                if (!column.HeaderText.Equals("Name", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                nameIndex = column.DisplayIndex;
                break;
            }

            foreach (DataGridViewColumn column in AttendantGrid.Columns)
            {
                if (!column.HeaderText.Equals("BranchName", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                branchNameIndex = column.DisplayIndex;
                break;
            }


            foreach (DataGridViewColumn column in AttendantGrid.Columns)
            {
                if (!column.HeaderText.Equals("Number", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                phoneIndex = column.DisplayIndex;
                break;
            }

            foreach (DataGridViewRow row in AttendantGrid.Rows)
            {
                try
                {
                    var value = row.Cells[nameIndex].Value.ToString();
                    if (!string.IsNullOrWhiteSpace(value))
                    {
                        var ticket = new Attendant
                        {
                            Phone      = row.Cells[phoneIndex]?.Value?.ToString(),
                            Name       = row.Cells[branchNameIndex]?.Value?.ToString(),
                            BranchName = row.Cells[phoneIndex]?.Value?.ToString()
                        };

                        if (_attendants.All(o => o.Phone != ticket.Phone))
                        {
                            _attendants.Add(ticket);
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
            using (var context = new DalexDbContext())
            {
                context.Attendants.AddRange(_attendants);
                context.SaveChanges();
                //MessageBox.Show(@"Success");
            }
        }
Пример #4
0
        private void ExtractTickets()
        {
            var nameIndex   = 0;
            var codeIndex   = 0;
            var ticketIndex = 0;

            foreach (DataGridViewColumn column in NamesGrid.Columns)
            {
                if (!column.HeaderText.Equals("DPName", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                nameIndex = column.DisplayIndex;
                break;
            }

            foreach (DataGridViewColumn column in NamesGrid.Columns)
            {
                if (!column.HeaderText.Equals("BranchCode", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                codeIndex = column.DisplayIndex;
                break;
            }


            foreach (DataGridViewColumn column in NamesGrid.Columns)
            {
                if (!column.HeaderText.Equals("TicketNo", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                ticketIndex = column.DisplayIndex;
                break;
            }
            foreach (DataGridViewRow row in NamesGrid.Rows)
            {
                try
                {
                    var value = row.Cells[nameIndex].Value.ToString();
                    if (!string.IsNullOrWhiteSpace(value))
                    {
                        var ticket = new Ticket
                        {
                            PaddieId   = GetPaddiesId(value),
                            BranchCode = row.Cells[codeIndex]?.Value?.ToString(),
                            Number     = row.Cells[ticketIndex]?.Value?.ToString()
                        };

                        if (tickets.All(o => o.Number != ticket.Number))
                        {
                            tickets.Add(ticket);
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
            using (var context = new DalexDbContext())
            {
                context.Tickets.AddRange(tickets);
                context.SaveChanges();
                //MessageBox.Show(@"Success");
            }
        }