Example #1
0
        static void Main(string[] args)
        {
            DataContext dc = new DataContext(@"Data Source=.\sqlexpress;Initial Catalog=vs2010;Integrated Security=True");

            dc.Log = Console.Out;

            var pessoas = dc.GetTable<Pessoa>();
            var filhos = dc.GetTable<Filho>();

            var todosANSI82 = from p in pessoas
                              from f in filhos
                              where p.CodigoPessoa == f.CodigoPessoa
                              select new { p.NomePessoa, f.NomeFilho };

            ObjectDumper.Write(todosANSI82);

            Console.WriteLine();

            var todosANSI92 = from p in pessoas
                              join f in filhos
                              on p.CodigoPessoa equals f.CodigoPessoa
                              select new { p.NomePessoa, f.NomeFilho };

            ObjectDumper.Write(todosANSI92);

            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            DataContext dc = new DataContext(@"Data Source=.\sqlexpress;Initial Catalog=vs2010;Integrated Security=True");

            dc.Log = Console.Out;

            Table<Filho> filhosDoAdao = dc.GetTable<Filho>();

            ObjectDumper.Write(filhosDoAdao);
            Console.WriteLine();

            Filho ooops = new Filho() { NomeFilho = "TIANA", CodigoPessoa = 1 };

            filhosDoAdao.InsertOnSubmit(ooops);
            dc.SubmitChanges();

            ObjectDumper.Write(dc.GetTable<Filho>());
            Console.WriteLine();

            filhosDoAdao.DeleteOnSubmit(ooops);
            dc.SubmitChanges();

            ObjectDumper.Write(dc.GetTable<Filho>());

            Console.ReadKey();
        }
 public FeedRepository(string connectionString)
 {
     _context = new DataContext(connectionString);
     _feedTable = _context.GetTable<Feed>();
     _itemTable = _context.GetTable<Item>();
     _optionTable = _context.GetTable<Option>();
 }
 public SqlBookmarkRepository(string connectionString)
 {
     _context = new DataContext(connectionString);
     _bookmarkTable = _context.GetTable<Bookmark>();
     _bookmarkTagTable = _context.GetTable<BookmarkTag>();
     _tagTable = _context.GetTable<Tag>();
 }
Example #5
0
        static void Main(string[] args)
        {
            DataContext dc = new DataContext(@"Data Source=.\sqlexpress;Initial Catalog=vs2010;Integrated Security=True");

            dc.Log = Console.Out;

            var filhosDoAdao = from f in dc.GetTable<Filho>()
                                  where f.CodigoPessoa == 1
                                  select f;

            ObjectDumper.Write(filhosDoAdao);

            Console.WriteLine();

            foreach (Filho filho in filhosDoAdao)
            {
                filho.NomeFilho += "*";
            }

            dc.SubmitChanges();

            ObjectDumper.Write(dc.GetTable<Filho>());

            Console.ReadKey();
        }
Example #6
0
        static void Main(string[] args)
        {
            SqlConnection dataConnection = new SqlConnection();
            try
            {
                SqlConnectionStringBuilder SQLConnString = new SqlConnectionStringBuilder();
                SQLConnString.DataSource = ".\\";//连接本地数据库
                SQLConnString.InitialCatalog = "TXGPS_2011";
                SQLConnString.IntegratedSecurity = true;
                dataConnection.ConnectionString = SQLConnString.ConnectionString;
                dataConnection.Open();

                SqlCommand dataCommand = new SqlCommand();
                dataCommand.Connection = dataConnection;
                dataCommand.CommandType = CommandType.Text;
                dataCommand.CommandText = "select * from tUser";

                DataContext db = new DataContext(SQLConnString.ConnectionString);
                Table<tMapX> tMapxs = db.GetTable<tMapX>();            //已经获取数据集
               // var tm = (from t in tMapxs select t).Take(10);// from in select 都是C#关键字,必须小写
                IEnumerable<tMapX> tm = tMapxs.OrderByDescending(ad => ad.id).Take(1);         //降序排列
                Table<tMapxData> tmd=db.GetTable<tMapxData>();
               // Console.WriteLine(tm);
                //tMapX tmapx = tm.Single(t => t.id == 4); //查询单个数据
                //Console.WriteLine(tmapx.Geo);
                foreach (var p in tm)
                {
                    Console.WriteLine(p.id + "--" + p.la + "--" + p.lo + "--" + p.Geo);
                }
                #region LINQ连接表
                var Mapx = from p in tmd join s in tm on p.Lo.ToString() equals (s.lo.ToString()+"00") select new { s.Geo, s.id };
                
                foreach (var p in Mapx)
                {
                    Console.WriteLine(p.id + "--" + p.Geo);
                }
                #endregion
                #region 常规的数据库读取
                //SqlDataReader dataReader = dataCommand.ExecuteReader();
                //while (dataReader.Read())
                //{
                //    int orderid = dataReader.GetInt32(0);
                //    string name = dataReader.GetString(3);
                //    DateTime orderDate = dataReader.GetDateTime(19);
                //    Console.WriteLine(orderid + "--" + name + "--" + orderDate);
                //}
                //dataReader.Close();
                #endregion
            }
            catch (SqlException e)
            {
                Console.WriteLine("Error accessing the database: " + e.Message);
            }
            finally
            {
                dataConnection.Close();
            }

        }
        public SqlAccountRepository(string connectionString)
        {
            dataContext = new DataContext(connectionString);

            usersTable = dataContext.GetTable<User>();
            rolesTable = dataContext.GetTable<Role>();
            usersInRolesTable = dataContext.GetTable<UsersInRoles>();
        }
Example #8
0
        //Metodo para la comunicacion con la BD y llamar al SP
        public static void Agregar(int idvuelo, string origen, string destino, int millas, string fecha, int idavion, Decimal precioDolar)
        {
            DataContext dc = new DataContext(myConnection.getConnection());
            var Customers = dc.GetTable<tablaVuelo>();

            var insert = dc.GetTable<tablaVuelo>();

            tablaVuelo newInsert = new tablaVuelo { ID_VUELO = idvuelo, ORIGEN = origen, DESTINO = destino, MILLAS = millas, FECHA = fecha, ID_AVION = idavion, PRECIO_DOLARES = precioDolar,ID_TICKET=0 };
            insert.InsertOnSubmit(newInsert);
            dc.SubmitChanges();
        }
Example #9
0
        public void TestContextToString([IncludeDataContexts(ProviderName.SqlServer2008)] string context)
        {
            using (var ctx = new DataContext(context))
            {
                Console.WriteLine(ctx.GetTable<Person>().ToString());

                var q =
                    from s in ctx.GetTable<Person>()
                    select s.FirstName;

                Console.WriteLine(q.ToString());
            }
        }
Example #10
0
        public Conta obterConta(int numero)
        {


            Console.WriteLine("obter " + numero);

            DataContext dc = new DataContext(@"Data Source=MIRANDA-LAPTOP\SQL2012DEINST1;Initial Catalog=ASI;Integrated Security=true");//TODO: CONFIGURATION FILE!
            Table<Conta> tc = dc.GetTable<Conta>();
            var conta = (from c in dc.GetTable<Conta>()
                         where c.Numero == numero
                         select c).SingleOrDefault();
            return conta;
        }
Example #11
0
        public void TestContextToString(string context)
        {
            using (var ctx = new DataContext(context))
            {
                Console.WriteLine(ctx.GetTable<Person>().ToString());

                var q =
                    from s in ctx.GetTable<Person>()
                    select s.FirstName;

                Console.WriteLine(q.ToString());
            }
        }
Example #12
0
        public Conta obterConta(int numero)
        {


            Console.WriteLine("obter " + numero);

            DataContext dc = new DataContext(@"Data Source=wv-toshiba\instancia1;Initial Catalog=ASI;User ID=sa;Password=123");
            Table<Conta> tc = dc.GetTable<Conta>();
            var conta = (from c in dc.GetTable<Conta>()
                         where c.Numero == numero
                         select c).SingleOrDefault();
            return conta;
        }
Example #13
0
        static void Main(string[] args)
        {
            DataContext dc = new DataContext(@"Data Source=.\sqlexpress;Initial Catalog=VS2010;Integrated Security=True");

            dc.Log = Console.Out;

            foreach (Pessoa p in dc.GetTable<Pessoa>())
            {
                Console.WriteLine("Pessoa: {0}", p.NomePessoa);

                foreach (Filho f in p.Filhos)
                {
                    Console.WriteLine("   Filho: {0}", f.NomeFilho);
                }
            }

            Console.WriteLine();

            var comFilhos = from p in dc.GetTable<Pessoa>()
                            where p.Filhos.Any()
                            select p;

            ObjectDumper.Write(comFilhos);
            Console.WriteLine();

            var semFilhos = from p in dc.GetTable<Pessoa>()
                            where !p.Filhos.Any()
                            select p;

            ObjectDumper.Write(semFilhos, 1);
            Console.WriteLine();

            var comAlgumFilhoIniciadoPorA = from p in dc.GetTable<Pessoa>()
                                            where p.Filhos.Any(f => f.NomeFilho.StartsWith("A"))
                                            select p;

            ObjectDumper.Write(comAlgumFilhoIniciadoPorA);
            Console.WriteLine();

            var seOsFilhosChamamCHICO = from p in dc.GetTable<Pessoa>()
                                        where p.Filhos.Any()
                                        where p.Filhos.All(f => f.NomeFilho.Equals("CHICO"))
                                        select p;

            ObjectDumper.Write(seOsFilhosChamamCHICO);
            Console.WriteLine();

            Console.ReadKey();
        }
Example #14
0
 public void inserirConta(Conta c)
 {
     DataContext dc = new DataContext(@"Data Source=wv-toshiba\instancia1;Initial Catalog=ASI;User ID=sa;Password=123");
     Table<Conta> tc = dc.GetTable<Conta>();
     tc.InsertOnSubmit(c);
     dc.SubmitChanges();
 }
Example #15
0
        //Metodo para llenar el campo de origen y destino con los paises
        public void llenarComboBox()
        {
            try
            {

                DataContext dc = new DataContext(myConnection.getConnection());
                var tabla = dc.GetTable<tablaPaises>();
                var paises = from p in tabla
                             select p;

                foreach (var pais in paises)
                {
                    cbOrigenVuelo.Items.Add(pais.DESCRIPCION);
                    cbDestinoVuelo.Items.Add(pais.DESCRIPCION);
                }

                cbOrigenVuelo.SelectedIndex = 0;//Para que aparezca de una vez el nombre de un pais
                cbDestinoVuelo.SelectedIndex = 0;//Para que aparezca de una vez el nombre de un pais
            } //Fin del try

            //Captura las excepciones
            catch (Exception ex)
            {
                MessageBox.Show("El campo no posee valores en lla base de datos. " + ex.ToString());
            } //Fin del Catch
        }
Example #16
0
        public int LinkInsert(DataContext Context)
        {
            var Links = Context.GetTable<CRdsAttributeLink>();
            Links.InsertOnSubmit(this);

            return -1;
        }
Example #17
0
        public override void Save()
        {
            base.Save();

            DataContext dc = new DataContext("(localdb)\v11.0");
            Table<DataControler> tableDC = dc.GetTable<DataControler>();
        }
        static void Main(string[] args)
        {
            // Use a connection string.
            DataContext db = new DataContext
                (@"c:\linqtest5\northwnd.mdf");

            // Get a typed table to run queries.
            Table<Customer> Customers = db.GetTable<Customer>();

            // Attach the log to show generated SQL.
            db.Log = Console.Out;

            // Query for customers in London.
            IQueryable<Customer> custQuery =
                from cust in Customers
                where cust.City == "London"
                select cust;

            foreach (Customer cust in custQuery)
            {
                Console.WriteLine("ID={0}, City={1}", cust.CustomerID,
                    cust.City);
            }

            // Prevent console window from closing.
            Console.ReadLine();
        }
Example #19
0
        static void Main(string[] args)
        {
            DataContext dc = new DataContext(@"Data Source=.\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True");

            dc.Log = Console.Out;

            //Table<Pessoa> pessoas = dc.GetTable<Pessoa>();

            var pessoas = from p in dc.GetTable<Pessoa>()
                          select p;

            //ObjectDumper.Write(pessoas);

            //Console.WriteLine();

            var nomes = from p in pessoas
                        select p.Nome;

            nomes = from p in nomes
                    where p.Equals("ABEL")
                    select p;

            ObjectDumper.Write(nomes);

            Console.ReadKey();
        }
        public int AmountInsert(DataContext Context)
        {
            var Amounts = Context.GetTable<CMenuServiceOrderAmount>();
            Amounts.InsertOnSubmit(this);

            return CErrors.ERR_SUC;
        }
Example #21
0
 public bool IsInstallationComplete()
 {
     var dataContext = new DataContext(ApplicationDomainConfiguration.ConnectionString);
     var settings = dataContext.GetTable<SettingsEntity>();
     var singleOrDefault = settings.SingleOrDefault(k => k.KeyName == "InstallationComplete");
     return singleOrDefault != null && bool.Parse(singleOrDefault.KeyValue);
 }
Example #22
0
        static void Main(string[] args)
        {
            DataContext dc = new DataContext(@"Data Source=.\sqlexpress;Initial Catalog=vs2010;Integrated Security=True");

            dc.Log = Console.Out;

            List<Pessoa> pessoas = dc.GetTable<Pessoa>().ToList<Pessoa>();

            var mulheres = from p in pessoas
                           where p.SexoPessoa == 'F'
                           select p;

            ObjectDumper.Write(mulheres);

            Console.WriteLine();

            var contemA = from p in pessoas
                          where p.NomePessoa.Contains("A")
                          select p;

            ObjectDumper.Write(contemA);

            Console.WriteLine();

            var comecaComA = from p in pessoas
                             where p.NomePessoa.StartsWith("A")
                             select p;

            ObjectDumper.Write(comecaComA);

            Console.ReadKey();
        }
Example #23
0
 public void inserirConta(Conta c)
 {
     DataContext dc = new DataContext(@"Data Source=MIRANDA-LAPTOP\SQL2012DEINST1;Initial Catalog=ASI;Integrated Security=true");//TODO: CONFIGURATION FILE!
     Table<Conta> tc = dc.GetTable<Conta>();
     tc.InsertOnSubmit(c);
     dc.SubmitChanges();
 }
        //cambBuscar
        //*creavuelo
        public Vuelo buscarporId(int idVuelo)
        {
            Vuelo vuelo = new Vuelo();
            MyConnection myConnection = new MyConnection();

            DataContext datacontext = new DataContext(myConnection.SQLConnection);

            var Table = datacontext.GetTable<Vuelo>();

            try
            {
                var buscarPorIdVuelo = from vueloId in Table
                                       where vueloId.IdVuelo == idVuelo
                                       select vueloId;
                foreach (Vuelo v in buscarPorIdVuelo)
                {
                    vuelo = v;
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return vuelo;
        }
Example #25
0
        static void Main(string[] args)
        {
            DataContext dc = new DataContext(@"Data Source=.\sqlexpress;Initial Catalog=vs2010;Integrated Security=True");

            dc.Log = Console.Out;

            var dados = from p in dc.GetTable<Pessoa>()
                        group p by p.SexoPessoa into agrupados
                        orderby agrupados.Key
                        select new { Sexo = agrupados.Key, Pessoas = agrupados };

            ObjectDumper.Write(dados, 1);

            Console.WriteLine();

            foreach (var agrupado in dados)
            {
                Console.WriteLine("Sexo: {0}", agrupado.Sexo);

                foreach (Pessoa p in agrupado.Pessoas)
                {
                    Console.WriteLine("\tpessoa: {0}", p.NomePessoa);
                }
            }

            Console.ReadKey();
        }
Example #26
0
        private void LinqToSql_Load(object sender, EventArgs e)
        {
            // Conexión
            string connString = @"server = .\sqlexpress; integrated security = true; database = AdventureWorks2014";

            try
            {
                // Crear data para el contexto
                DataContext db = new DataContext(connString);

                // Crear un tipo de tabla
                Table<Contacto> contactos = db.GetTable<Contacto>();

                // Query
                var detallesContacto = from c in contactos
                                       where c.title == "Mr."
                                       orderby c.firstName
                                       select c;

                // Desplegar los detalles de los contactos
                foreach (var contacto in detallesContacto)
                {
                    txtLinqToSql.AppendText(contacto.title);
                    txtLinqToSql.AppendText("\t");
                    txtLinqToSql.AppendText(contacto.firstName);
                    txtLinqToSql.AppendText("\t");
                    txtLinqToSql.AppendText(contacto.lastName);
                    txtLinqToSql.AppendText("\n");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
Example #27
0
        static void Main(string[] args)
        {
            DataContext dc = new DataContext(@"Data Source=.\sqlexpress;Initial Catalog=vs2010;Integrated Security=True");

            dc.Log = Console.Out;

            //Table<Pessoa> pessoas = dc.GetTable<Pessoa>();

            var pessoas = from p in dc.GetTable<Pessoa>()
                          select p;

            //ObjectDumper.Write(pessoas);

            Console.WriteLine();

            var nomes = from p in pessoas
                        select p.NomePessoa;

            var lista = from p in nomes
                        where p.Equals("ABEL")
                        select p;

            ObjectDumper.Write(lista);

            Console.ReadKey();
        }
 //method to retrieve a user from our database by userid
 public VigilentPublicContracts.VigilentPublicUsers GetUser(string UserID)
 {
     int userID = Int32.Parse(UserID);
     DataContext vigilentPublicData = new DataContext(DataConnectionString);
     VigilentPublicContracts.VigilentPublicUsers vpUser = (from users in vigilentPublicData.GetTable<VigilentPublicContracts.VigilentPublicUsers>() where users.UserID == userID select users).First();
     return vpUser;
 }
Example #29
0
        private void button12_Click(object sender, EventArgs e)
        {
            var dc = new DataContext(@"server=localhost\sqlexpress;database=loja;integrated security=true");
            var produtos = dc.GetTable<ProdutoInfo>();

            //Obter uma instancia
            var produto = (from p in produtos
                           where p.Codigo == 2
                           select p).FirstOrDefault();

            if (produto == null)
            {
                MessageBox.Show("Produto não encontrado");
                return;
            }

            //marcar para excluir
            produtos.DeleteOnSubmit(produto);

            //Confirmar
            dc.SubmitChanges();
            MessageBox.Show("Produto excluido com sucesso");



        }
        private Table<Tag> GetAllTag()
        {
            DataContext context = new DataContext(_connection);

            Table<Tag> result = context.GetTable<Tag>();

            return result;
        }
        /// <summary>
        /// フォルダ参照ボタンクリックイベント.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fld_button_Click(object sender, RoutedEventArgs e)
        {
            // ダイアログ生成
            CommonOpenFileDialog dlg = new CommonOpenFileDialog();

            // パラメタ設定

            // タイトル
            dlg.Title = "フォルダ選択";
            // フォルダ選択かどうか
            dlg.IsFolderPicker = true;
            // 初期ディレクトリ
            dlg.InitialDirectory = @"c:\";
            // ファイルが存在するか確認する
            //dlg.EnsureFileExists = false;
            // パスが存在するか確認する
            //dlg.EnsurePathExists = false;
            // 読み取り専用フォルダは指定させない
            //dlg.EnsureReadOnly = false;
            // コンパネは指定させない
            //dlg.AllowNonFileSystemItems = false;

            //ダイアログ表示
            var Path = dlg.ShowDialog();

            if (Path == CommonFileDialogResult.Ok)
            {
                // 選択されたフォルダ名を取得、格納されているCSVを読み込む
                List <Cat> list = readFiles(dlg.FileName);

                // 接続
                int count = 0;
                using (var conn = new SQLiteConnection("Data Source=SampleDb.sqlite"))
                {
                    conn.Open();

                    // データを追加する
                    using (DataContext context = new DataContext(conn))
                    {
                        foreach (Cat cat in list)
                        {
                            // 対象のテーブルオブジェクトを取得
                            var table = context.GetTable <Cat>();
                            // データが存在するかどうか判定
                            if (table.SingleOrDefault(x => x.No == cat.No) == null)
                            {
                                // データ追加
                                table.InsertOnSubmit(cat);
                                // DBの変更を確定
                                context.SubmitChanges();
                                count++;
                            }
                        }
                    }
                    conn.Close();
                }

                MessageBox.Show(count + " / " + list.Count + " 件 のデータを取り込みました。");

                // データ再検索
                searchData();
            }
        }
Example #32
0
 public virtual IQueryable <T> GetAll()
 {
     return(context.GetTable <T>());
 }
Example #33
0
 private IQueryable <Administrator> GetAllWithName(string userName)
 {
     return(DataContext.GetTable <Administrator>()
            .Where(a => a.UserName.Equals(userName)));
 }
Example #34
0
        /// <summary>
        /// 下一流程
        /// </summary>
        /// <param name="handleProcess"></param>
        /// <param name="create"></param>
        public void HandleCreateRunProcess(Modules.OA_FlowRunProcess handleProcess, Modules.OA_FlowRunProcess create)
        {
            using (DataContext cxt = ContextFactory.CreateContext())
            {
                cxt.Connection.Open();
                using (DbTransaction tran = cxt.Connection.BeginTransaction())
                {
                    cxt.Transaction = tran;
                    Table <FineOffice.Entity.OA_FlowRunProcess>  runProcess = cxt.GetTable <FineOffice.Entity.OA_FlowRunProcess>();
                    Table <FineOffice.Entity.OA_FlowRunTransmit> transmit   = cxt.GetTable <FineOffice.Entity.OA_FlowRunTransmit>();

                    try
                    {
                        FineOffice.Entity.OA_FlowRunProcess createProcess = new Entity.OA_FlowRunProcess
                        {
                            ID             = create.ID,
                            ProcessID      = create.ProcessID,
                            Remark         = create.Remark,
                            AcceptID       = create.AcceptID,
                            AcceptTime     = create.AcceptTime,
                            HandleTime     = create.HandleTime,
                            Pattern        = create.Pattern,
                            IsEntrance     = create.IsEntrance,
                            PreviousID     = create.PreviousID,
                            SendID         = create.SendID,
                            Version        = create.Version,
                            TransmitAdvice = create.TransmitAdvice,
                            RunID          = create.RunID,
                            State          = create.State,
                            TransmitFrom   = handleProcess.TransmitFrom,
                        };
                        runProcess.InsertOnSubmit(createProcess);
                        cxt.SubmitChanges();

                        runProcess.Attach(new Entity.OA_FlowRunProcess
                        {
                            ID             = handleProcess.ID,
                            ProcessID      = handleProcess.ProcessID,
                            Remark         = handleProcess.Remark,
                            AcceptID       = handleProcess.AcceptID,
                            AcceptTime     = handleProcess.AcceptTime,
                            HandleTime     = handleProcess.HandleTime,
                            Pattern        = handleProcess.Pattern,
                            PreviousID     = handleProcess.PreviousID,
                            SendID         = handleProcess.SendID,
                            Version        = handleProcess.Version,
                            IsEntrance     = handleProcess.IsEntrance,
                            TransmitAdvice = handleProcess.TransmitAdvice,
                            RunID          = handleProcess.RunID,
                            State          = handleProcess.State,
                            TransmitFrom   = handleProcess.TransmitFrom,
                        }, true);

                        transmit.InsertOnSubmit(new Entity.OA_FlowRunTransmit
                        {
                            Pattern      = 1,
                            RunProcessID = handleProcess.ID,
                            TransmitTo   = createProcess.ID
                        });

                        transmit.InsertOnSubmit(new Entity.OA_FlowRunTransmit
                        {
                            Pattern      = 2,
                            RunProcessID = handleProcess.ID,
                            TransmitTo   = createProcess.ID
                        });
                        cxt.SubmitChanges();
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
Example #35
0
 /// <summary>
 /// Gets the <see cref="Table{TEntity}"/> of <see cref="EventData"/>.
 /// </summary>
 /// <param name="dbDataContext">The <see cref="DataContext"/> to use.</param>
 protected virtual Table <EventData> GetEventStoreTable(DataContext dbDataContext)
 {
     // Get a typed table to run queries.
     return(dbDataContext.GetTable <EventData>());
 }
Example #36
0
 protected virtual ITable GetTable()
 {
     _db = new DataContext(configManager.GetStringConnexion());
     return(_db.GetTable <T>());
 }
Example #37
0
        /// <summary>
        /// 退回流程
        /// </summary>
        /// <param name="handleProcess"></param>
        /// <param name="backProcess"></param>
        public void SendBackRunProcess(Modules.OA_FlowRunProcess handleProcess, Modules.OA_FlowRunProcess backProcess)
        {
            using (DataContext cxt = ContextFactory.CreateContext())
            {
                cxt.Connection.Open();
                using (DbTransaction tran = cxt.Connection.BeginTransaction())
                {
                    cxt.Transaction = tran;
                    Table <FineOffice.Entity.OA_FlowRunProcess>  runProcess = cxt.GetTable <FineOffice.Entity.OA_FlowRunProcess>();
                    Table <FineOffice.Entity.OA_FlowRunTransmit> transmit   = cxt.GetTable <FineOffice.Entity.OA_FlowRunTransmit>();

                    try
                    {
                        FineOffice.Entity.OA_FlowRunProcess createProcess = new Entity.OA_FlowRunProcess
                        {
                            ID             = backProcess.ID,
                            ProcessID      = backProcess.ProcessID,
                            Remark         = backProcess.Remark,
                            AcceptID       = backProcess.AcceptID,
                            AcceptTime     = backProcess.AcceptTime,
                            HandleTime     = backProcess.HandleTime,
                            Pattern        = backProcess.Pattern,
                            PreviousID     = backProcess.PreviousID,
                            SendID         = backProcess.SendID,
                            IsEntrance     = backProcess.IsEntrance,
                            Version        = backProcess.Version,
                            TransmitFrom   = handleProcess.ID,
                            TransmitAdvice = backProcess.TransmitAdvice,
                            RunID          = backProcess.RunID,
                            State          = backProcess.State,
                        };
                        runProcess.InsertOnSubmit(createProcess);
                        cxt.SubmitChanges();

                        bool isEntrance = false;
                        if (handleProcess.IsEntrance != null && handleProcess.IsEntrance.Value)
                        {
                            isEntrance = true;
                            handleProcess.IsEntrance = false;
                        }

                        if (backProcess.IsEntrance == null || !backProcess.IsEntrance.Value)
                        {
                            FineOffice.Entity.OA_FlowRunTransmit previous = transmit.Where(p => p.RunProcessID == createProcess.PreviousID &&
                                                                                           p.TransmitTo == handleProcess.PreviousID && p.Pattern == 1).FirstOrDefault();
                        }
                        else if (!isEntrance)
                        {
                            FineOffice.Entity.OA_FlowRunProcess tempProcess = runProcess.Where(p => p.RunID == backProcess.RunID && p.IsEntrance == true).FirstOrDefault();
                            tempProcess.IsEntrance = null;
                        }

                        runProcess.Attach(new Entity.OA_FlowRunProcess
                        {
                            ID             = handleProcess.ID,
                            ProcessID      = handleProcess.ProcessID,
                            Remark         = handleProcess.Remark,
                            AcceptID       = handleProcess.AcceptID,
                            AcceptTime     = handleProcess.AcceptTime,
                            HandleTime     = handleProcess.HandleTime,
                            Pattern        = handleProcess.Pattern,
                            PreviousID     = handleProcess.PreviousID,
                            SendID         = handleProcess.SendID,
                            IsEntrance     = handleProcess.IsEntrance,
                            Version        = handleProcess.Version,
                            TransmitAdvice = handleProcess.TransmitAdvice,
                            RunID          = handleProcess.RunID,
                            State          = handleProcess.State
                        }, true);

                        transmit.InsertOnSubmit(new Entity.OA_FlowRunTransmit
                        {
                            Pattern      = 2,
                            RunProcessID = handleProcess.ID,
                            TransmitTo   = createProcess.ID
                        });

                        cxt.SubmitChanges();
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
        public MainWindow()
        {
            InitializeComponent();
            // SampleDb.sqlite を作成(存在しなければ)
            using (var conn = new SQLiteConnection("Data Source=SampleDb.sqlite"))
            {
                // データベースに接続
                conn.Open();
                // コマンドの実行
                using (var command = conn.CreateCommand())
                {
                    // テーブルが存在しなければ作成する
                    // 種別マスタ
                    StringBuilder sb = new StringBuilder();
                    sb.Append("CREATE TABLE IF NOT EXISTS MSTKIND (");
                    sb.Append("  KIND_CD NCHAR NOT NULL");
                    sb.Append("  , KIND_NAME NVARCHAR");
                    sb.Append("  , primary key (KIND_CD)");
                    sb.Append(")");

                    command.CommandText = sb.ToString();
                    command.ExecuteNonQuery();

                    // 猫テーブル
                    sb.Clear();
                    sb.Append("CREATE TABLE IF NOT EXISTS TBLCAT (");
                    sb.Append("  NO INT NOT NULL");
                    sb.Append("  , NAME NVARCHAR NOT NULL");
                    sb.Append("  , SEX NVARCHAR NOT NULL");
                    sb.Append("  , AGE INT DEFAULT 0 NOT NULL");
                    sb.Append("  , KIND_CD NCHAR DEFAULT 0 NOT NULL");
                    sb.Append("  , FAVORITE NVARCHAR");
                    sb.Append("  , primary key (NO)");
                    sb.Append(")");

                    command.CommandText = sb.ToString();
                    command.ExecuteNonQuery();

                    // 種別マスタを取得してコンボボックスに設定する
                    using (DataContext con = new DataContext(conn))
                    {
                        // データを取得
                        Table <Kind>      mstKind = con.GetTable <Kind>();
                        IQueryable <Kind> result  = from x in mstKind orderby x.KindCd select x;

                        // 最初の要素は「指定なし」とする
                        Kind empty = new Kind();
                        empty.KindCd   = "";
                        empty.KindName = "指定なし";
                        var list = result.ToList();
                        list.Insert(0, empty);

                        // コンボボックスに設定
                        this.search_kind.ItemsSource       = list;
                        this.search_kind.DisplayMemberPath = "KindName";
                    }
                }
                // 切断
                conn.Close();
            }
        }
Example #39
0
        internal void Select_coffee_in_BD()
        {
            using (DataContext db = new DataContext(Resources.ConectString))
            {
                /*А ЭТУ ХУЙНЮ Я НАПИСАЛ В 2 СТРОЧКИ  ПОСЛЕ ТОГО ЧТО НИЖЕ В КОММЕНТАХ !!!*/
                Table <Model_Coffee> coffees = db.GetTable <Model_Coffee>();
                coffees.ToList <Model_Coffee>().ForEach(i => Coffee_list.coffee_list.Add(i));
            }

            /*НА ЭТУ ХУЙНЮ Я УБИЛ СУКА ЧАС!!!!!!*/

            /*using (SqlConnection connection = new SqlConnection(Resources.ConectString))
             * {
             *  connection.Open(); // открываем соидинение
             *  SqlCommand SQL_SELECT = new SqlCommand(Resources.SQL_Select_ALL, connection);
             *  SqlDataAdapter adapter = new SqlDataAdapter(SQL_SELECT.CommandText, connection);
             *  DataSet data = new DataSet();
             *  adapter.Fill(data);
             *  for (int i = 0; i < data.Tables[0].Rows.Count; i++) // бежим по строкам таблицы
             *  {
             *      Model_Coffee model_Coffe = new Model_Coffee(); // временная переменная для листа
             *      for (int q = 1; q < data.Tables[0].Columns.Count; q++) // бежим по колонкам таблица
             *      {
             *          string row_name = data.Tables[0].Columns[q].ToString(); // название колонки для свич
             *          switch (row_name)
             *          {
             *              case "Name":
             *                  model_Coffe.name = data.Tables[0].Rows[i].ItemArray[q].ToString();
             *                  break;
             *              case "Cost_price":
             *                  model_Coffe.cost_price = Convert.ToDouble(data.Tables[0].Rows[i].ItemArray[q].ToString());
             *                  break;
             *              case "Price":
             *                  model_Coffe.price = Convert.ToDouble(data.Tables[0].Rows[i].ItemArray[q].ToString());
             *                  break;
             *              case "Gram_per_serving":
             *                  model_Coffe.gram_per_serving = Convert.ToInt32(data.Tables[0].Rows[i].ItemArray[q].ToString());
             *                  break;
             *              case "Grain_type":
             *                  model_Coffe.grain_type = data.Tables[0].Rows[i].ItemArray[q].ToString();
             *                  break;
             *              case "Country_of_origin":
             *                  model_Coffe.country_of_origin = data.Tables[0].Rows[i].ItemArray[q].ToString();
             *                  break;
             *              case "Info":
             *                  model_Coffe.info = data.Tables[0].Rows[i].ItemArray[q].ToString();
             *                  break;
             *              default:
             *                  break;
             *          }
             *      }
             *      // убераем лишнии пробелы
             *      model_Coffe.name = model_Coffe.name.Trim();
             *      model_Coffe.grain_type = model_Coffe.grain_type.Trim();
             *      model_Coffe.country_of_origin = model_Coffe.country_of_origin.Trim();
             *      model_Coffe.info = model_Coffe.info.Trim();
             *      // чистим память за временной переменной
             *      Coffee_list.coffee_list.Add(model_Coffe);
             *      GC.Collect(GC.GetGeneration(model_Coffe));
             *  }
             *      data.Clear();
             *      connection.Close(); // закрываем соединение
             *
             * }*/
        }
Example #40
0
 public ConnectionWithDataBase()
 {
     db             = new DataContext("C:\\lessons\\lessonsdatabaseee.mdf");
     Lessons        = db.GetTable <Lesson>();
     HomeworkPoints = db.GetTable <HomeworkPoint>();
 }
Example #41
0
 public List <DateSum> getForDataGrid1()
 {
     return((from d in datacontext.GetTable <DateSum>()
             select d).ToList());
 }
Example #42
0
        public void TestHalls()
        {
            string expected = "Blue";

            string actual = datacontext.GetTable <Halls>().First().Title;

            Assert.AreEqual(expected, actual);

            expected = "Green";

            var hall = new Halls {
                Title = "Green", Lines = 10, Seats = 10
            };

            datacontext.GetTable <Halls>().InsertOnSubmit(hall);

            datacontext.SubmitChanges();

            int max = (from h in datacontext.GetTable <Halls>() select h.ID).Max();

            actual = (from h in datacontext.GetTable <Halls>() where h.ID == max select h.Title).First();

            Assert.AreEqual(expected, actual);

            Halls hall2 = (from h in datacontext.GetTable <Halls>() where h.ID == max select h).First();

            datacontext.GetTable <Halls>().DeleteOnSubmit(hall2);
            datacontext.SubmitChanges();

            int exp     = 2;
            int actuall = (from h in datacontext.GetTable <Halls>() select h.ID).Max();

            Assert.AreEqual(exp, actuall);
        }
Example #43
0
 /// <summary>
 /// 根据班级、年级查找对应资源
 /// </summary>
 /// <param name="grade"></param>
 /// <param name="clas"></param>
 /// <returns>对应资源数组</returns>
 public static List <Models.Resource> searchResourceAccordingGrade(string grade, string clas)
 {
     using (DataContext dc = new DataContext(common.conn))
     {
         if (string.IsNullOrWhiteSpace(grade) && !(string.IsNullOrWhiteSpace(clas)))
         {
             var resource = from x in dc.GetTable <Models.Resource>()
                            where x.Clas == clas
                            select x;
             if (resource.Count() >= 1)
             {
                 return(resource.ToList());
             }
             else
             {
                 throw (new Exception("没有找到对应资源"));
             }
         }
         else if (!(string.IsNullOrWhiteSpace(grade)) && string.IsNullOrWhiteSpace(clas))
         {
             var resource = from x in dc.GetTable <Models.Resource>()
                            where x.Grades == grade
                            select x;
             if (resource.Count() >= 1)
             {
                 return(resource.ToList());
             }
             else
             {
                 throw (new Exception("没有找到对应资源"));
             }
         }
         else if (grade != "" && clas != "")
         {
             var resource = from x in dc.GetTable <Models.Resource>()
                            where x.Grades == grade && x.Clas == clas
                            select x;
             if (resource.Count() >= 1)
             {
                 return(resource.ToList());
             }
             else
             {
                 throw (new Exception("没有找到对应资源"));
             }
         }
         else
         {
             var resource = from x in dc.GetTable <Models.Resource>()
                            select x;
             if (resource.Count() >= 1)
             {
                 return(resource.ToList());
             }
             else
             {
                 throw (new Exception("没有找到对应资源"));
             }
         }
     }
 }
        public void GetMarkClass(string variant)
        {
            DataContext dataContext = new DataContext(connection);

            var resultA = from x in dataContext.GetTable <TableStudents>()
                          where x.Class == "A"
                          select new { x.Id };
            var resultB = from x in dataContext.GetTable <TableStudents>()
                          where x.Class == "B"
                          select new { x.Id };
            var resultC = from x in dataContext.GetTable <TableStudents>()
                          where x.Class == "C"
                          select new { x.Id };
            var resultD = from x in dataContext.GetTable <TableStudents>()
                          where x.Class == "D"
                          select new { x.Id };
            var resultF = from x in dataContext.GetTable <TableStudents>()
                          where x.Class == "F"
                          select new { x.Id };


            var marksAll = from x in dataContext.GetTable <TablePerformance>()
                           select new { x.Id, x.Maths, x.Physics, x.Biology };

            int summMarkA = 0;
            int summMarkB = 0;
            int summMarkC = 0;
            int summMarkD = 0;
            int summMarkF = 0;


            foreach (var a in resultA)
            {
                foreach (var o in marksAll)
                {
                    if (o.Id == a.Id)
                    {
                        summMarkA += o.Maths + o.Physics + o.Biology;
                    }
                }
            }
            foreach (var a in resultB)
            {
                foreach (var o in marksAll)
                {
                    if (o.Id == a.Id)
                    {
                        summMarkB += o.Maths + o.Physics + o.Biology;
                    }
                }
            }
            foreach (var a in resultC)
            {
                foreach (var o in marksAll)
                {
                    if (o.Id == a.Id)
                    {
                        summMarkC += o.Maths + o.Physics + o.Biology;
                    }
                }
            }
            foreach (var a in resultD)
            {
                foreach (var o in marksAll)
                {
                    if (o.Id == a.Id)
                    {
                        summMarkD += o.Maths + o.Physics + o.Biology;
                    }
                }
            }
            foreach (var a in resultF)
            {
                foreach (var o in marksAll)
                {
                    if (o.Id == a.Id)
                    {
                        summMarkF += o.Maths + o.Physics + o.Biology;
                    }
                }
            }
            int[] massMarks = new int[5] {
                summMarkA, summMarkB, summMarkC, summMarkD, summMarkF
            };
            string[] massClassNumber = new string[5] {
                "A", "B", "C", "D", "F"
            };

            int max = massMarks[0];
            int min = massMarks[0];

            if (variant == "Best")
            {
                for (int i = 0; i < 5; i++)
                {
                    if (massMarks[i] > max)
                    {
                        max = massMarks[i];
                        labelBestClassOnMark.Content = massClassNumber[i];
                    }
                }
            }
            if (variant == "Worst")
            {
                for (int i = 0; i < 5; i++)
                {
                    if (massMarks[i] < min)
                    {
                        min = massMarks[i];
                        labelTheWorstClassOnMark.Content = massClassNumber[i];
                    }
                }
            }
        }
Example #45
0
        private void ButtonSteps_OnClick(object sender, RoutedEventArgs e)
        {
            DataContext          dataContext     = new DataContext(connectionString);
            Table <CellModel>    tableCellModels = dataContext.GetTable <CellModel>();
            Table <NumberOfGame> numberOfGames   = dataContext.GetTable <NumberOfGame>();
            var listNumber = numberOfGames.ToList();
            int ab         = listNumber.Count();

            var listNeedCell = tableCellModels.ToList();

            var number   = (from t in listNeedCell where t.NumberOfGame == ab select t).ToList <CellModel>();
            var donumber = (from t in listNeedCell where t.NumberOfGame == ab select t).ToList <CellModel>();

            //проходимся по всем строкам
            //foreach (DataRow row in dtdt.Rows)
            //{
            //    // получаем все ячейки строки
            //    foreach (DataRow rowrow in dtdt.Rows)
            //    {
            //        // получаем все ячейки строки
            //        var cells = row.ItemArray;

            //        foreach (object cell in cells)

            //    }

            //}



            foreach (var item in number)
            {
                var forcolumn = item.Column;
                var forrow    = item.Row;
                var fornumber = item.NumberOfGame;

                //циклы проверки соседей
                //var testColumn1 = p.Column - 1;
                //var testRow1 = p.Row - 1;
                //var testCR = dtdt.Rows[testColumn1][testRow1];



                var testColumn_1 = forcolumn - 1;
                var testRow_1    = forrow - 1;

                var testColumn__1 = forcolumn + 1;
                var testRow__1    = forrow + 1;

                //для ячейки: колонка 0 строка 0, проверка соседей
                if (testColumn_1 < 0 && testRow_1 < 0)
                {
                    //колонка та же, строка +
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }

                    //колонка +, строка +
                    var testCR__1__1 = dtdt.Rows[forrow + 1][forcolumn + 1];
                    if (testCR__1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //колонка +, строка та же
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                // нулевая колонка, но не нулевая строка, при этом не крайняя колонка или не крайняя строка
                if (testColumn_1 < 0 && testRow_1 >= 0 && testRow__1 <= _qrow)
                {
                    //колонка та же, строка -     1
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //колонка та же, строка +             2
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //колонка +, строка-                3
                    var testCR_1__1 = dtdt.Rows[forrow - 1][forcolumn + 1];
                    if (testCR_1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка +                 4
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка +              5
                    var testCR__1__1 = dtdt.Rows[forrow + 1][forcolumn + 1];
                    if (testCR__1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                // строка нулевая, при этом колонка не нулевая, но и не крайняя колонка
                if (testRow_1 < 0 && testColumn_1 >= 0 && testColumn__1 <= _column)
                {
                    //строка та же, колонка -              1
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка -                     2
                    var testCR__1_1 = dtdt.Rows[forrow + 1][forcolumn - 1];
                    if (testCR__1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка та же                3
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка +                    4
                    var testCR__1__1 = dtdt.Rows[forrow + 1][forcolumn + 1];
                    if (testCR__1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка +                 5
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                //крайняя строка, крайняя колонка
                if (testRow__1 > _qrow && testColumn__1 > _column)
                {
                    //строка та же, колонка -
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка -
                    var testCR_1_1 = dtdt.Rows[forrow - 1][forcolumn - 1];
                    if (testCR_1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка та же
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                // крайняя строка, но не крайняя колонка и не нулевая колонка
                if (testRow__1 > _qrow && testColumn__1 <= _column && testColumn_1 >= 0)
                {
                    //строка та же, колонка -         1
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка -               2
                    var testCR_1_1 = dtdt.Rows[forrow - 1][forcolumn - 1];
                    if (testCR_1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка та же            3
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка +                 4
                    var testCR_1__1 = dtdt.Rows[forrow - 1][forcolumn + 1];
                    if (testCR_1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка +                5
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                //нулевая колонка, крайняя строка
                if (testColumn_1 < 0 && testRow__1 > _qrow)
                {
                    //строка -, колонка та же
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }

                    //строка -, колонка +
                    var testCR_1__1 = dtdt.Rows[forrow - 1][forcolumn + 1];
                    if (testCR_1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка +
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                //крайняя колонка, нулевая строка
                if (testColumn__1 > _column && testRow_1 < 0)
                {
                    //строка та же, колонка -
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка -
                    var testCR__1_1 = dtdt.Rows[forrow + 1][forcolumn - 1];
                    if (testCR__1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка та же
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                //крайняя колонка но не нулевая строка и не крайняя строка
                if (testColumn__1 > _column && testRow_1 >= 0 && testRow__1 <= _qrow)
                {
                    //строка -, колонка та же            1
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка -                   2
                    var testCR_1_1 = dtdt.Rows[forrow - 1][forcolumn - 1];
                    if (testCR_1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка -                  3
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка -                     4
                    var testCR__1_1 = dtdt.Rows[forrow + 1][forcolumn - 1];
                    if (testCR__1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    // строка +, колонка та же                        5
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                if (testColumn_1 >= 0 && testRow_1 >= 0 && testColumn__1 <= _column && testRow__1 <= _qrow)
                {
                    //строка -, колонка -
                    var testCR_1_1 = dtdt.Rows[forrow - 1][forcolumn - 1];
                    if (testCR_1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка та же
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка +
                    var testCR_1__1 = dtdt.Rows[forrow - 1][forcolumn + 1];
                    if (testCR_1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка -
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка +
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка -
                    var testCR__1_1 = dtdt.Rows[forrow + 1][forcolumn - 1];
                    if (testCR__1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка та же
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка +
                    var testCR__1__1 = dtdt.Rows[forrow + 1][forcolumn + 1];
                    if (testCR__1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }


                ////////////////////////////////////////////////////////////
                //////////////////////////////////////////
                ////////////////////////////
            }
            var numberfor = (from t in listNeedCell where t.NumberOfGame == ab select t).ToList <CellModel>();

            foreach (var item in numberfor)
            {
                //var itemstring = item.ValueOfCell.ToString();
                if (item.ValueOfCell == 0 && item.Sosedi == 3)
                {
                    dtdt.Rows[item.Row][item.Column] = "1";
                    item.ValueOfCell = 1;
                    CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                    cell1.ValueOfCell = item.ValueOfCell;
                    dataContext.SubmitChanges();
                }
                if (item.ValueOfCell != 0 && (item.Sosedi < 2 || item.Sosedi > 3))
                {
                    dtdt.Rows[item.Row][item.Column] = "";
                    item.ValueOfCell = 0;
                    CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                    cell1.ValueOfCell = item.ValueOfCell;
                    dataContext.SubmitChanges();
                }
            }


            DataTable booksTable = new DataTable();

            //DataContext db = new DataContext(connectionString);
            //Table<CellModel> cellModelTable = db.GetTable<CellModel>();

            //booksTable = cellModelTable;
            //// NavigationService.Navigate(new CustomPlace(column, qrow));
            //CellModel cell = new CellModel();
            //p.ValueOfCell = 1;
            booksTable = dtdt;

            gridEmployees.DataContext = booksTable.DefaultView;
            var list = booksTable.Select().SelectMany(row => row.ItemArray).Select(x => (string)x).ToList();

            dtdt = booksTable;
            var qrowsindtdt  = dtdt.Rows.Count;
            var columnindtdt = dtdt.Columns.Count;

            for (int i = 0; i < qrowsindtdt; i++)
            {
                for (int b = 0; b < columnindtdt; b++)
                {
                    //dtdt.Rows[b][i] = "";

                    CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Column == b && p.Row == i && p.NumberOfGame == ab);

                    cell1.Sosedi = 0;

                    dataContext.SubmitChanges();
                }
            }
        }