예제 #1
0
        private void buttonDiapasonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                FormDiapasonNew theFormDiapasonNew = new FormDiapasonNew(this._access);
                var             result             = theFormDiapasonNew.ShowDialog();
                if (result == DialogResult.OK)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    this.listBoxDiapason.Items.Clear();
                    this.listBoxDiapason.Items.Add("Обновление ...");
                    this.listBoxDiapason.Refresh();
                    var diapason = new Diapason
                    {
                        Access   = this._access,
                        ValueMin = Convert.ToInt64(theFormDiapasonNew.textBoxValueMin.Text),
                        ValueMax = Convert.ToInt64(theFormDiapasonNew.textBoxValueMax.Text)
                    };
                    diapason.Name = diapason.ValueMin.ToString("0000000000") + " ... " + diapason.ValueMax.ToString("0000000000");
                    diapason.Save();

                    int Total = 0;

                    var    results        = new List <int>();
                    string sqlInsertUsers = @"INSERT INTO [Telephone] ([Number], [NumberOrder], [Diapason_ID], [Access_ID]) VALUES (@Number, @NumberOrder, @Diapason_ID, @Access_ID);";

                    string _connectionString = NHibernateHelper.ConnectionString;

                    using (var cn = new SQLiteConnection(_connectionString))
                    {
                        cn.Open();

                        using (var transaction = cn.BeginTransaction())
                        {
                            using (var cmd = cn.CreateCommand())
                            {
                                cmd.CommandText = sqlInsertUsers;
                                cmd.Parameters.AddWithValue("@Number", "");
                                cmd.Parameters.AddWithValue("@NumberOrder", "");
                                cmd.Parameters.AddWithValue("@Diapason_ID", "");
                                cmd.Parameters.AddWithValue("@Access_ID", "");

                                for (long i = diapason.ValueMin; i <= diapason.ValueMax; i++)
                                {
                                    var rnd = new Random();
                                    cmd.Parameters["@Number"].Value      = i.ToString();
                                    cmd.Parameters["@NumberOrder"].Value = rnd.Next(0, Int32.MaxValue);
                                    cmd.Parameters["@Diapason_ID"].Value = diapason.ID;
                                    cmd.Parameters["@Access_ID"].Value   = _access.ID;
                                    try
                                    {
                                        results.Add(cmd.ExecuteNonQuery());
                                        Total++;
                                    }
                                    catch (Exception exc)
                                    {
                                    }
                                }
                            }
                            transaction.Commit();
                        }
                    }
                    int Sum = results.Sum();

                    diapason.Name += " = " + Total.ToString();
                    diapason.Update();

                    this.LoadDiapason();
                    Application.UseWaitCursor = false;
                }
            }
            catch (Exception ex)
            {
                this.listBoxDiapason.Items.Add(ex.Message);
            }
        }
예제 #2
0
        private void buttonDiapasonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                FormDiapasonNew theFormDiapasonNew = new FormDiapasonNew(this.theAccess);
                var             result             = theFormDiapasonNew.ShowDialog();
                if (result == DialogResult.OK)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    this.listBoxDiapason.Items.Clear();
                    this.listBoxDiapason.Items.Add("Обновление ...");
                    this.listBoxDiapason.Refresh();
                    Diapason theDiapason = new Diapason();
                    theDiapason.Access   = this.theAccess;
                    theDiapason.ValueMin = Convert.ToInt64(theFormDiapasonNew.textBoxValueMin.Text);
                    theDiapason.ValueMax = Convert.ToInt64(theFormDiapasonNew.textBoxValueMax.Text);
                    theDiapason.Save();

                    var    results           = new List <int>();
                    string sqlInsertUsers    = @"INSERT INTO [Telephone] ([Number], [Diapason_ID], [Access_ID]) VALUES (@Number, @Diapason_ID, @Access_ID);";
                    string _connectionString = "Data Source=IndexMobile.db";
                    using (var cn = new SQLiteConnection(_connectionString))
                    {
                        cn.Open();
                        using (var transaction = cn.BeginTransaction())
                        {
                            using (var cmd = cn.CreateCommand())
                            {
                                cmd.CommandText = sqlInsertUsers;
                                cmd.Parameters.AddWithValue("@Number", "");
                                cmd.Parameters.AddWithValue("@Diapason_ID", "");
                                cmd.Parameters.AddWithValue("@Access_ID", "");

                                for (long i = theDiapason.ValueMin; i <= theDiapason.ValueMax; i++)
                                {
                                    cmd.Parameters["@Number"].Value      = i.ToString();
                                    cmd.Parameters["@Diapason_ID"].Value = theDiapason.ID;
                                    cmd.Parameters["@Access_ID"].Value   = theAccess.ID;
                                    results.Add(cmd.ExecuteNonQuery());
                                }
                            }
                            transaction.Commit();
                        }
                    }
                    int Sum = results.Sum();

                    //string sqlQuery = "";
                    //for (long i = theDiapason.ValueMin; i <= theDiapason.ValueMax; i++)
                    //{
                    //    if (Telephone.CheckInAccess(i, theDiapason.Access))
                    //    {
                    //        continue;
                    //    }
                    //    sqlQuery += "INSERT INTO TELEPHONE(NUMBER, DIAPASON_ID, ACCESS_ID) VALUES(" + i.ToString() + ", " + theDiapason.ID + ", " + theAccess.ID + "); \n\r";

                    //    //Telephone theTelephone = new Telephone();
                    //    //theTelephone.Diapason = theDiapason;
                    //    //theTelephone.Access = theDiapason.Access;
                    //    //theTelephone.Number = i;
                    //    //theTelephone.Save();
                    //}
                    //DataClass theDataClass = new DataClass();
                    //theDataClass.selectQuery(sqlQuery);
                    this.LoadDiapason();
                    Application.UseWaitCursor = false;
                }
            }
            catch (Exception ex)
            {
                this.listBoxDiapason.Items.Add(ex.Message);
            }
        }