Exemplo n.º 1
0
        private void импортИзФайлаToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                int p = 25;
                string[] ch = { " " };
                bool noadres = false;
                StreamReader sr = File.OpenText(openFileDialog1.FileName);
                List<ImportOchered> io = new List<ImportOchered>();
                ImportOchered ioo = new ImportOchered();
                while (!sr.EndOfStream)
                {

                    ioo = new ImportOchered();
                    ioo.m_rab = "";
                    ioo.tel = "";
                    string buf = sr.ReadLine();
                    if (buf.Trim().Length > 0)
                    {
                        p++;
                        int num;
                        if (int.TryParse(buf, out num))
                        {
                            ioo.kod = num;
                            if (num == 185)
                            {
                                int ppp = 1;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Ошибка в строке:\n" + buf+"\nКод записи:"+ioo.kod);
                            continue;
                        }
                        if (DateTime.TryParse(sr.ReadLine().Trim(), out ioo.dat_reg))
                        {
                            string[] fio = sr.ReadLine().Trim().Split(ch, StringSplitOptions.RemoveEmptyEntries);
                            ioo.fam = fio[0];
                            ioo.ima = fio[1];
                            ioo.otch = fio[2];
                            /*if(fio.Length>2)
                            ioo.m_rab = string.Join(" ", fio, 3);*/

                            if (DateTime.TryParse(sr.ReadLine().Trim(), out ioo.dat_rozh))
                            {
                                string adr = sr.ReadLine().Trim();
                                if (!char.IsDigit(adr[2]) && adr[2] != '-')
                                {
                                    ioo.adres = adr;
                                }
                                else
                                {
                                    ioo.tel = adr;
                                    noadres = true;
                                }
                                if (!noadres)
                                {
                                    string tel = sr.ReadLine().Trim();
                                    if (char.IsDigit(tel[2]) || tel[2] == '-')
                                    {
                                        ioo.tel = tel;
                                        string[] p_fio = sr.ReadLine().Trim().Split(' ');
                                        ioo.p_fam = p_fio[0];
                                        ioo.p_ima = p_fio[1];
                                        ioo.p_otch = p_fio[2];
                                        if (p_fio.Length > 3)
                                        {
                                            for (int j = 3; j < p_fio.Length; j++)
                                            {
                                                ioo.m_rab = ioo.m_rab + p_fio[j] + " ";

                                            }
                                            ioo.m_rab = ioo.m_rab.Trim();
                                        }

                                        string[] ser_nom = sr.ReadLine().Trim().Split(ch, StringSplitOptions.RemoveEmptyEntries);
                                        try
                                        {
                                            ioo.ser = ser_nom[0].Remove(ser_nom[0].IndexOf('-'));
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show("Ошибка в преобразовании серии:\n" + ser_nom[0]);
                                        }
                                        ioo.nom = ser_nom[1];
                                        string comment = sr.ReadLine();
                                        if (comment != null)
                                        {
                                            if (comment.Length > 0)
                                            {
                                                ioo.comment = comment;
                                                io.Add(ioo);
                                                continue;
                                            }
                                            else
                                            {
                                                io.Add(ioo);
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            io.Add(ioo);
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        string[] p_fio = tel.Split(ch, StringSplitOptions.RemoveEmptyEntries);
                                        ioo.p_fam = p_fio[0];
                                        ioo.p_ima = p_fio[1];
                                        ioo.p_otch = p_fio[2];
                                        if (p_fio.Length > 3)
                                        {
                                            for (int j = 3; j < p_fio.Length; j++)
                                            {
                                                ioo.m_rab = ioo.m_rab + p_fio[j] + " ";

                                            }
                                            ioo.m_rab = ioo.m_rab.Trim();
                                        }

                                        string[] ser_nom = sr.ReadLine().Trim().Split(ch,StringSplitOptions.RemoveEmptyEntries);
                                        try
                                        {
                                            ioo.ser = ser_nom[0].Remove(ser_nom[0].IndexOf('-'));
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show("Ошибка в преобразовании серии:\n" + ser_nom[0]);
                                        }
                                        ioo.nom = ser_nom[1];
                                        string comment = sr.ReadLine();
                                        if (comment.Length > 0)
                                        {
                                            ioo.comment = comment;
                                            io.Add(ioo);
                                            continue;
                                        }
                                        else
                                        {
                                            io.Add(ioo);
                                            continue;
                                        }
                                    }
                                }

                            }
                        }
                        else
                        {
                            MessageBox.Show("Ошибка в строке:\n" + buf+"\nКод записи:"+ioo.kod);
                            continue;
                        }
                    }
                }
                for (int i = 0; i < io.Count; i++)
                {
                    int kod_predst=-1;
                    //Добавление представителя
                    try
                    {
                        kod_predst = Convert.ToInt32(info_predstavitelTableAdapter.GetKodPredstavitel(io[i].p_fam, io[i].p_ima, io[i].p_otch, io[i].tel, io[i].adres));
                        if (!(kod_predst > 0))
                        {
                            int ind = info_predstavitelTableAdapter.Insert(io[i].p_fam, io[i].p_ima, io[i].p_otch, io[i].m_rab, io[i].tel, io[i].adres);
                            this.info_predstavitelTableAdapter.Fill(this.electronOcheredDataSet.info_predstavitel);
                            kod_predst = Convert.ToInt32(info_predstavitelTableAdapter.GetKodPredstavitel(io[i].p_fam, io[i].p_ima, io[i].p_otch, io[i].tel, io[i].adres));
                        }

                    //END добавление представителя
                    //Добавление ребенк
                    info_rebenokTableAdapter.Insert(io[i].fam, io[i].ima, io[i].otch, io[i].dat_rozh, kod_predst, 2, "", true, false, io[i].comment, io[i].ser, io[i].nom,0);
                    //int kod_r = (int)info_rebenokTableAdapter.GetKodRebenok(textBox1.Text, textBox2.Text, textBox3.Text, Convert.ToInt32(textBox_kod_pred.Text));
                    int kod_r = (int)info_rebenokTableAdapter.GetLastId();
                    info_registrationTableAdapter.Insert(kod_r, io[i].dat_reg, 1);
                    }
                    catch (Exception ex)
                    {
                        of.ErrorInfoToFile(ex);
                    }
                    //END Добавление ребенка
                }
            }
        }
Exemplo n.º 2
0
        private void импортИзФайла2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                int p = 25;
                int pp = 0;
                string[] ch = { "\t" };
                string[] ch2 = { " " };
                string[] ch3 = { " ", "-" };
                bool noadres = false;
                StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.UTF8);
                List<ImportOchered> io = new List<ImportOchered>();
                ImportOchered ioo = new ImportOchered();
                while (!sr.EndOfStream)
                {
                    try
                    {
                        ioo = new ImportOchered();
                        ioo.m_rab = "";
                        ioo.tel = "";
                        string line = sr.ReadLine();
                        string[] sub_line = line.Split(ch, StringSplitOptions.None);
                        if (sub_line[0] != "")
                        {
                            ioo.kod = Convert.ToInt32(sub_line[0]);
                            if (ioo.kod == 117)
                            {
                                int o = 1;
                            }
                            ioo.dat_reg = DateTime.Parse(sub_line[1]);
                            string[] fio = sub_line[2].Split(ch2, StringSplitOptions.RemoveEmptyEntries);
                            ioo.fam = fio[0];
                            ioo.ima = fio[1];
                            ioo.otch = fio[2];
                            ioo.dat_rozh = DateTime.Parse(sub_line[3]);
                            if (sub_line[4] != "")
                            {
                                string[] sernom = sub_line[4].Split(ch3, StringSplitOptions.RemoveEmptyEntries);
                                ioo.ser = sernom[0];
                                for (int i = 1; i < sernom.Length; i++)
                                {
                                    if (int.TryParse(sernom[i][0].ToString(), out pp))
                                    {
                                        ioo.nom = sernom[i];
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                ioo.ser = "I";
                                ioo.nom = "нет";
                            }

                            string[] fio_p = sub_line[5].Split(ch2, StringSplitOptions.RemoveEmptyEntries);
                            if (fio_p.Length > 2)
                            {
                                ioo.p_fam = fio_p[0];
                                ioo.p_ima = fio_p[1];
                                ioo.p_otch = fio_p[2];
                            }
                            ioo.adres = sub_line[6];
                            if (sub_line.Length > 36)
                            {
                                ioo.tel = sub_line[36];
                            }
                            if (sub_line[7] != "")
                            {
                                ioo.comment = sub_line[7];
                            }
                        }
                        io.Add(ioo);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка в строке:\nКод записи:" + ioo.kod);
                    }

                }
                for (int i = 0; i < io.Count; i++)
                {
                    int kod_predst = -1;
                    //Добавление представителя
                    try
                    {
                        kod_predst = Convert.ToInt32(info_predstavitelTableAdapter.GetKodPredstavitel(io[i].p_fam, io[i].p_ima, io[i].p_otch, io[i].tel, io[i].adres));
                        if (!(kod_predst > 0))
                        {
                            int ind = info_predstavitelTableAdapter.Insert(io[i].p_fam, io[i].p_ima, io[i].p_otch, io[i].m_rab, io[i].tel, io[i].adres);
                            this.info_predstavitelTableAdapter.Fill(this.electronOcheredDataSet.info_predstavitel);
                            kod_predst = Convert.ToInt32(info_predstavitelTableAdapter.GetKodPredstavitel(io[i].p_fam, io[i].p_ima, io[i].p_otch, io[i].tel, io[i].adres));
                        }

                        //END добавление представителя
                        //Добавление ребенк
                        info_rebenokTableAdapter.Insert(io[i].fam, io[i].ima, io[i].otch, io[i].dat_rozh, kod_predst, 2, "", true, false, io[i].comment, io[i].ser, io[i].nom,0);
                        //int kod_r = (int)info_rebenokTableAdapter.GetKodRebenok(textBox1.Text, textBox2.Text, textBox3.Text, Convert.ToInt32(textBox_kod_pred.Text));
                        int kod_r = (int)info_rebenokTableAdapter.GetLastId();
                        info_registrationTableAdapter.Insert(kod_r, io[i].dat_reg, 3);
                    }
                    catch (Exception ex)
                    {
                        of.ErrorInfoToFile(ex);
                    }
                    //END Добавление ребенка
                }
            }
        }