コード例 #1
0
ファイル: Form1.cs プロジェクト: Facchin-Sedp/CPImport
        private string insert_Anagrafica(Row_CpAnagra r_anag)
        {
            MySqlConnection cn      = new MySqlConnection(CString);
            MySqlCommand    command = new MySqlCommand();

            cn.Open();
            command.Connection = cn;

            string query = @"insert into cpanagra(cpa_cpgid,cpa_rifter,cpa_rifpra,cpa_nome,cpa_numpty,cpa_calsts,cpa_calcnt,cpa_numpho,cpa_curpho) 
                                               VALUES(@CPA_CPGID,@CPA_RIFTER,@CPA_RIFPRA,@CPA_NOME,@CPA_NUMPTY,@CPA_CALSTS,@CPA_CALCNT,@CPA_NUMPHO,@CPA_CURPHO)
";

            try
            {
                command.CommandText = query;
                command.Parameters.Add("@CPA_CPGID", MySqlDbType.Int64).Value    = r_anag.cpa_cpgid;
                command.Parameters.Add("@CPA_RIFTER", MySqlDbType.VarChar).Value = r_anag.cpa_rifter;
                command.Parameters.Add("@CPA_RIFPRA", MySqlDbType.VarChar).Value = r_anag.cpa_rifpra;
                command.Parameters.Add("@CPA_NOME", MySqlDbType.VarChar).Value   = r_anag.cpa_nome;
                command.Parameters.Add("@CPA_NUMPTY", MySqlDbType.Int32).Value   = r_anag.cpa_numpty;
                command.Parameters.Add("@CPA_CALSTS", MySqlDbType.Int32).Value   = 1;
                command.Parameters.Add("@CPA_CALCNT", MySqlDbType.Int32).Value   = 0;
                command.Parameters.Add("@CPA_NUMPHO", MySqlDbType.Int32).Value   = r_anag.cpa_numpho;
                command.Parameters.Add("@CPA_CURPHO", MySqlDbType.Int32).Value   = 0;


                command.ExecuteNonQuery();

                // estraggo il max id ovvero l'ultimo inserito
                query = "select max(cpa_id) from cpanagra  ";
                command.CommandText = query;

                Int64 res = (Int64)command.ExecuteScalar();



                cn.Close();


                return(res.ToString());
            }
            catch (Exception e)
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }

                MessageBox.Show("Errore: " + e.Message + "\n" + e.InnerException, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return("Errore: " + e.Message + "\n" + e.InnerException);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Facchin-Sedp/CPImport
        private void read_CSV()
        {
            Application.DoEvents();
            lblWait.Visible = true;
            Application.DoEvents();


            List <Row_CpAnagra> ls_Anag   = new List <Row_CpAnagra> {
            };
            List <Row_CpPhones> ls_Phones = new List <Row_CpPhones> {
            };

            listBox1.Items.Clear();


            StreamReader sr    = new StreamReader(CompleteFileName);
            int          count = 0;
            String       l     = String.Empty;

            var file      = sr.ReadToEnd();                  // big string
            var lines     = file.Split(new char[] { '\n' }); // big array
            int lineCount = lines.Count();



            progressBar1.Maximum = lineCount - 1;
            progressBar1.Minimum = 0;
            progressBar1.Value   = 0;

            sr.Close();

            sr = new StreamReader(CompleteFileName);

            while (!sr.EndOfStream)
            {
                if (riga_Colonne && count == 0)
                {
                    sr.ReadLine();
                }

                l = sr.ReadLine();
                List <String> line_split = l.Split(';').ToList();


                if (line_split[0].Trim() != String.Empty)
                {
                    count++;
                    Row_CpAnagra r_anag = new Row_CpAnagra {
                        cpa_cpgid  = Id_Campagna,
                        cpa_rifter = line_split[0],
                        cpa_rifpra = line_split[1],
                        cpa_nome   = line_split[2].Trim(),
                        cpa_numpty = line_split[3],
                        cpa_numpho = line_split[4]
                    };
                    String cpa_id = insert_Anagrafica(r_anag);

                    // per tutti i teleono che partono dalla colonna 6
                    int    cnt = 0;
                    String res = String.Empty;
                    for (int i = 5; i < line_split.Count; i++)
                    {
                        if (line_split[i] != string.Empty)
                        {
                            String tel = line_split[i].Replace(" ", string.Empty);

                            cnt++;
                            Row_CpPhones ph = new Row_CpPhones
                            {
                                cpp_cpaid  = cpa_id,
                                cpp_numpho = cnt.ToString(),
                                cpp_phonum = tel,
                                cpp_calsts = "1",
                                cpp_censts = "0",
                                cpp_calcnt = "0"
                            };


                            res += insert_Phones(ph);
                        }
                    }


                    if (res != String.Empty)
                    {
                        MessageBox.Show(res);
                    }



                    #region CONTROLLO
                    String comp = String.Empty;
                    foreach (String campi in line_split)
                    {
                        comp += campi + "\t";
                    }
                    listBox1.Items.Add(comp);

                    Application.DoEvents();
                    #endregion
                }

                progressBar1.Value++;
            }

            sr.Close();
            progressBar1.Value = progressBar1.Maximum;
            MessageBox.Show("Importazione terminata!\nSono stati caricati "
                            + listBox1.Items.Count.ToString() + " Contatti");

            Application.DoEvents();
            lblWait.Visible = false;
            // resetto gli elementi
            Campagna              = String.Empty;
            Id_Campagna           = String.Empty;
            lblIDCampagna.Visible = false;
            txtSearch.Text        = String.Empty;
            lblCampagna.Visible   = false;
            lblCampagna.Text      = "Nome Campagna";
            btnDelCampag.Visible  = false;
            btnAttivaCamp.Visible = false;
            ///
            Application.DoEvents();
        }