Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            _OrderEntry order = new _OrderEntry();

            order.MeterId = int.Parse(MeterDataGridView[Program.FindTitle(MeterDataGridView, "Идентификационный номер"), MeterDataGridView.SelectedRows[0].Index].Value.ToString());
            OrderEntryList.Add(order);

            OrderEntryDataGridView.Refresh();
        }
Exemple #2
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Excel.Worksheet worksheet = null;
                Excel.Range     range     = null;
                try
                {
                    application         = new Excel.Application();
                    workbook            = application.Workbooks.Open(openFileDialog1.FileName);
                    application.Visible = true;
                    worksheet           = workbook.Worksheets[1];
                    range = worksheet.UsedRange;
                    string CityName       = range.Cells[1, 2].Value2.ToString();
                    string StreetName     = range.Cells[2, 2].Value2.ToString();
                    string HouseNumber    = range.Cells[3, 2].Value2.ToString();
                    string FlatNumber     = range.Cells[4, 2].Value2.ToString();
                    string FIO            = range.Cells[5, 2].Value2.ToString();
                    string PassportNumber = range.Cells[6, 2].Value2.ToString();
                    string PhoneNumber    = range.Cells[7, 2].Value2.ToString();
                    string CompanyName    = range.Cells[8, 2].Value2.ToString();
                    string INN            = range.Cells[9, 2].Value2.ToString();
                    string ErrorMsg       = string.Empty;
                    bool   NotCompany     = CompanyName.Length == 0 && INN.Length == 0;
                    if (!Checker.IsName(CityName))
                    {
                        ErrorMsg += "Неверная строка в названии города\n";
                    }
                    if (!Checker.IsName(StreetName))
                    {
                        ErrorMsg += "Неверная строка в названии улицы\n";
                    }
                    if (!Checker.IsHouseNumber(HouseNumber))
                    {
                        ErrorMsg += "Неверная строка в номере дома\n";
                    }
                    if (!Checker.IsNumber(FlatNumber))
                    {
                        ErrorMsg += "Неверная строка в номере квартиры\n";
                    }
                    if (!Checker.IsFIO(FIO))
                    {
                        ErrorMsg += "Неверная строка в ФИО\n";
                    }
                    if (!Checker.IsPassportNumber(PassportNumber))
                    {
                        ErrorMsg += "Неверная строка в номере паспорта\n";
                    }
                    if (!Checker.IsPhoneNumber(PhoneNumber))
                    {
                        ErrorMsg += "Неверная строка в номере телефона\n";
                    }
                    if (!Checker.IsName(CompanyName) && !NotCompany)
                    {
                        ErrorMsg += "Неверная строка в названии организации\n";
                    }
                    if (!Checker.IsINN(INN) && !NotCompany)
                    {
                        ErrorMsg += "Неверная строка в ИНН\n";
                    }
                    if (ErrorMsg.Length == 0)
                    {
                        _City _City = new _City {
                            Name = CityName
                        };
                        _Street _Street = new _Street {
                            Name = StreetName
                        };
                        _House _House = new _House {
                            Number = HouseNumber
                        };
                        _Address _Address = new _Address {
                            Flat = int.Parse(FlatNumber)
                        };
                        _Customer _Customer;
                        if (NotCompany)
                        {
                            _Customer = new _Customer()
                            {
                                FIO = FIO, Passport = PassportNumber, PhoneNumber = PhoneNumber
                            };
                        }
                        else
                        {
                            _Customer = new _Company()
                            {
                                FIO = FIO, Passport = PassportNumber, PhoneNumber = PhoneNumber, CompanyName = CompanyName, INN = INN
                            }
                        };
                        List <_OrderEntry> list = new List <_OrderEntry>();
                        int row = 2;
                        while (range[row, 4] != null && range[row, 4].Value2 != null && range[row, 4].Value2.ToString().Length > 0 && ErrorMsg.Length == 0)
                        {
                            string MeterId = range[row, 4].Value2.ToString();
                            if (!Checker.IsNumber(MeterId))
                            {
                                ErrorMsg += "Неверная строка в номере счётчика\n";
                            }
                            DateTime StartTime = default(DateTime), EndTime = default(DateTime);
                            if (range[row, 5] != null && range[row, 5].Value2 != null)
                            {
                                string sStartTime = range[row, 5].Value2.ToString();
                                if (sStartTime.Length > 0 && double.TryParse(sStartTime, out double dstart))
                                {
                                    StartTime = DateTime.FromOADate(dstart);
                                }
                                else
                                {
                                    ErrorMsg += "Неверная строка во времени начала\n";
                                }
                            }

                            if (range[row, 6] != null && range[row, 6].Value2 != null)
                            {
                                string sEndTime = range[row, 6].Value2.ToString();
                                if (sEndTime.Length > 0 && double.TryParse(sEndTime, out double dend))
                                {
                                    EndTime = DateTime.FromOADate(dend);
                                }
                                else
                                {
                                    ErrorMsg += "Неверная строка во времени конца\n";
                                }
                            }
                            if (StartTime != default(DateTime) && EndTime != default(DateTime) && StartTime > EndTime)
                            {
                                ErrorMsg += "Дата начала позже даты конца\n";
                            }
                            if (ErrorMsg.Length == 0)
                            {
                                var ord = new _OrderEntry {
                                    MeterId = int.Parse(MeterId)
                                };
                                if (StartTime != default(DateTime))
                                {
                                    ord.startTime = StartTime;
                                }
                                if (EndTime != default(DateTime))
                                {
                                    ord.endTime = EndTime;
                                }
                                list.Add(ord);
                                ++row;
                            }
                        }
                        if (ErrorMsg.Length == 0)
                        {
                            try
                            {
                                dataGridView1.DataSource = list;
                                Program.HideColumns(ref dataGridView1, EntityTypes.OrderEntry, CurrentUser);
                                Program.HidaColumns(ref dataGridView1, new List <string> {
                                    "Id", "OrderId", "StatusId", "RegNum"
                                });
                                Program.Rename(ref dataGridView1);
                                address1  = _Address;
                                house1    = _House;
                                street1   = _Street;
                                city1     = _City;
                                customer1 = _Customer;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show(ErrorMsg);
                        }
                    }
                    else
                    {
                        MessageBox.Show(ErrorMsg);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (range != null)
                    {
                        Marshal.ReleaseComObject(range);
                    }
                    if (worksheet != null)
                    {
                        Marshal.ReleaseComObject(worksheet);
                    }
                }
            }
        }