Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (_tableType == SampleType.Patients)
            {
                _heandlerFlag = false;

                DialogResult dr = this.openFileDialog1.ShowDialog();
                if (dr == System.Windows.Forms.DialogResult.OK)
                {
                    Excel.Application xlApp = new Excel.Application();
                    DataRow newRow;
                    foreach (String file in openFileDialog1.FileNames)
                    {

                        Excel.Workbook xlWBook = xlApp.Workbooks.Open(file);
                        Excel.Worksheet xlWSheet = xlWBook.Sheets[1];
                        Excel.Range xlRange = xlWSheet.UsedRange;

                        _table = (DataTable)dataGridViewNew.DataSource;
                        newRow = _table.NewRow();
                        for (int i = 2; i < 8; i++)
                        {
                            String name = (String)(xlRange.Cells[i, 1] as Excel.Range).Value;
                            var value = (xlRange.Cells[i, 2] as Excel.Range).Value;
                            if (value == null)
                            {
                                MessageBox.Show("Не введены обязательные данные: " + name, "Ошибка загрузки данных!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            else
                            {
                                newRow[_table.Columns[name]] = value;
                            }
                        }
                        _table.Rows.Add(newRow);
                        _table = (DataTable)dataGridViewMil.DataSource;
                        newRow = _table.NewRow();
                        for (int i = 2; i < 10; i++)
                        {
                            String name = (String)(xlRange.Cells[i, 3] as Excel.Range).Value;

                            var value = (xlRange.Cells[i, 4] as Excel.Range).Value;
                            newRow[_table.Columns[name]] = value;
                        }
                        _table.Rows.Add(newRow);
                        _table = (DataTable)dataGridViewPsy.DataSource;
                        newRow = _table.NewRow();
                        for (int i = 2; i < 14; i++)
                        {
                            String name = (String)(xlRange.Cells[i, 5] as Excel.Range).Value;
                            var value = (xlRange.Cells[i, 6] as Excel.Range).Value;
                            newRow[_table.Columns[name]] = value;
                        }
                        _table.Rows.Add(newRow);
                        _table = (DataTable)dataGridViewMed.DataSource;
                        newRow = _table.NewRow();
                        for (int i = 2; i < 3; i++)
                        {
                            String name = (String)(xlRange.Cells[i, 7] as Excel.Range).Value;
                            var value = (xlRange.Cells[i, 8] as Excel.Range).Value;
                            newRow[_table.Columns[name]] = value;
                        }
                        _table.Rows.Add(newRow);
                        _table = (DataTable)dataGridViewFamily.DataSource;
                        newRow = _table.NewRow();
                        for (int i = 20; i < 28; i++)
                        {
                            String name = (String)(xlRange.Cells[i, 1] as Excel.Range).Value;
                            var value = (xlRange.Cells[i, 2] as Excel.Range).Value;
                            newRow[_table.Columns[name]] = value;
                        }
                        _table.Rows.Add(newRow);
                        _table = (DataTable)dataGridViewSocial.DataSource;
                        newRow = _table.NewRow();
                        for (int i = 20; i < 22; i++)
                        {
                            String name = (String)(xlRange.Cells[i, 3] as Excel.Range).Value;
                            var value = (xlRange.Cells[i, 4] as Excel.Range).Value;
                            newRow[_table.Columns[name]] = value;
                        }
                        _table.Rows.Add(newRow);
                        _table = (DataTable)dataGridViewStudy.DataSource;
                        newRow = _table.NewRow();
                        for (int i = 20; i < 22; i++)
                        {
                            String name = (String)(xlRange.Cells[i, 5] as Excel.Range).Value;
                            var value = (xlRange.Cells[i, 6] as Excel.Range).Value;
                            newRow[_table.Columns[name]] = value;
                        }
                        _table.Rows.Add(newRow);
                        _table = (DataTable)dataGridViewWork.DataSource;
                        newRow = _table.NewRow();
                        for (int i = 20; i < 22; i++)
                        {
                            String name = (String)(xlRange.Cells[i, 7] as Excel.Range).Value;
                            var value = (xlRange.Cells[i, 8] as Excel.Range).Value;
                            newRow[_table.Columns[name]] = value;
                        }
                        _table.Rows.Add(newRow);

                        int index = 5;
                        _illnesses.Add(new List<Illness>());
                        while ((xlRange.Cells[index, 7] as Excel.Range).Value != null && index < 15)
                        {
                            Illness newIll = new Illness();
                            newIll.Disease = (xlRange.Cells[index, 7] as Excel.Range).Value;
                            _illnesses[_illnesses.Count - 1].Add(newIll);
                            index++;
                        }
                        index = 29;
                        _relatives.Add(new List<Relative>());
                        while ((xlRange.Cells[index, 1] as Excel.Range).Value != null && index < 40)
                        {
                            Relative newRel = new Relative();
                            newRel.Kinsman = (xlRange.Cells[index, 1] as Excel.Range).Value;
                            newRel.Relations = (xlRange.Cells[index, 2] as Excel.Range).Value;
                            _relatives[_relatives.Count - 1].Add(newRel);
                            index++;
                        }
                        index = 23;
                        _events.Add(new List<PoliceEvent>());
                        while ((xlRange.Cells[index, 3] as Excel.Range).Value != null && index < 40)
                        {
                            PoliceEvent newEvent = new PoliceEvent();
                            newEvent.Reason = (xlRange.Cells[index, 3] as Excel.Range).Value;
                            newEvent.DateEvent = (xlRange.Cells[index, 4] as Excel.Range).Value;
                            _events[_events.Count - 1].Add(newEvent);
                            index++;
                        }
                    }
                    xlApp.Quit();
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlApp);
                }

                _heandlerFlag = true;
            }
            else
                MessageBox.Show("Данные можно загрузить только о новых служащих!", "Ошибка загрузки данных", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Пример #2
0
 partial void DeleteRelative(Relative instance);
Пример #3
0
 partial void UpdateRelative(Relative instance);
Пример #4
0
 partial void InsertRelative(Relative instance);
Пример #5
0
		private void detach_Relatives(Relative entity)
		{
			this.SendPropertyChanging();
			entity.Patient = null;
		}
Пример #6
0
		private void attach_Relatives(Relative entity)
		{
			this.SendPropertyChanging();
			entity.Patient = this;
		}