Beispiel #1
0
        private string insert_Phones(Row_CpPhones ph)
        {
            String          res     = String.Empty;
            MySqlConnection cn      = new MySqlConnection(CString);
            MySqlCommand    command = new MySqlCommand();

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

            string query = @"insert into cpphones(cpp_cpaid,cpp_numpho,cpp_phonum,cpp_calsts,cpp_censts,cpp_calcnt) 
                             VALUES(@CPP_CPAID,@CPP_NUMPHO,@CPP_PHONUM,@CPP_CALSTS,@CPP_CENSTS,@CPP_CALCNT)
                            ";

            try
            {
                command.CommandText = query;
                command.Parameters.Add("@CPP_CPAID", MySqlDbType.Int64).Value    = ph.cpp_cpaid;
                command.Parameters.Add("@CPP_NUMPHO", MySqlDbType.VarChar).Value = ph.cpp_numpho;
                command.Parameters.Add("@CPP_PHONUM", MySqlDbType.VarChar).Value = ph.cpp_phonum;
                command.Parameters.Add("@CPP_CALSTS", MySqlDbType.Int32).Value   = 1;
                command.Parameters.Add("@CPP_CENSTS", MySqlDbType.Int32).Value   = 0;
                command.Parameters.Add("@CPP_CALCNT", MySqlDbType.Int32).Value   = 0;


                command.ExecuteNonQuery();


                cn.Close();


                return(String.Empty);
            }
            catch (Exception e)
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
                return("Errore: " + e.Message + "\n" + e.InnerException);
            }
        }
Beispiel #2
0
        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();
        }