Exemplo n.º 1
0
        public bool AddListCells(CellStructure cellStr)
        {
            bool f = false;

            try
            {
                foreach (Cell c in cellStr.Cells)
                {
                    sqlConnection = GetSqlConnection();
                    SqlCommand sql = new SqlCommand("INSERT INTO CellStructures_Cells (Id_Cell, Id_CellStructure) VALUES (@cell, @cs);", sqlConnection);
                    sqlConnection.Close();
                    sqlConnection.Open();
                    sql.Parameters.AddWithValue("@cs", cellStr.Id);
                    sql.Parameters.AddWithValue("@cell", c.Id);
                    sql.ExecuteReader();
                    sqlConnection.Close();
                }
                f = true;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(f);
        }
Exemplo n.º 2
0
        public bool AddCellStructure(CellStructure cs)
        {
            bool f = false;

            try
            {
                sqlConnection = GetSqlConnection();
                SqlCommand cmd = new SqlCommand("InsertCS", sqlConnection);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@descCS", System.Data.SqlDbType.VarChar, 400));
                cmd.Parameters["@descCS"].Value = cs.Description;

                cmd.Parameters.Add(new SqlParameter("@idCS", System.Data.SqlDbType.Int, 8));
                cmd.Parameters["@idCS"].Direction = System.Data.ParameterDirection.Output;

                sqlConnection.Close();
                sqlConnection.Open();
                cmd.ExecuteNonQuery();

                cs.Id = (int)cmd.Parameters["@idCS"].Value;

                f = AddValues(cs.Properties, cs.Id, GetIdParentType(ParentType.CelluralStructure));
                f = AddListCells(cs);

                sqlConnection.Close();
                f = true;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(f);
        }
Exemplo n.º 3
0
        public bool AddDetail(Detail detail)
        {
            bool f = false;

            try
            {
                if (AddCellStructure(detail.CellStructure))
                {
                    CellStructure newCS = GetCellStructures().FindLast(x => x.Description.Equals(detail.CellStructure.Description));
                    if (newCS != null)
                    {
                        sqlConnection = GetSqlConnection();
                        SqlCommand cmd = new SqlCommand("InsertDetail", sqlConnection);
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;

                        cmd.Parameters.Add(new SqlParameter("@idMat", System.Data.SqlDbType.Int, 8));
                        cmd.Parameters["@idMat"].Value = detail.Material.Id;

                        cmd.Parameters.Add(new SqlParameter("@idCS", System.Data.SqlDbType.Int, 8));
                        cmd.Parameters["@idCS"].Value = detail.CellStructure.Id;

                        cmd.Parameters.Add(new SqlParameter("@nameDetail", System.Data.SqlDbType.VarChar, 50));
                        cmd.Parameters["@nameDetail"].Value = detail.Name;

                        cmd.Parameters.Add(new SqlParameter("@descDet", System.Data.SqlDbType.VarChar, 400));
                        cmd.Parameters["@descDet"].Value = detail.Name;

                        cmd.Parameters.Add(new SqlParameter("@idDetail", System.Data.SqlDbType.Int, 8));
                        cmd.Parameters["@idDetail"].Direction = System.Data.ParameterDirection.Output;

                        sqlConnection.Close();
                        sqlConnection.Open();
                        cmd.ExecuteNonQuery();

                        detail.Id = (int)cmd.Parameters["@idDetail"].Value;


                        detail.CellStructure.Id = newCS.Id;

                        {
                            f = AddValues(detail.Properties, detail.Id, GetIdParentType(ParentType.Detail));
                        }
                        sqlConnection.Close();
                        f = true;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(f);
        }
Exemplo n.º 4
0
        public List <CellStructure> GetCellStructures()
        {
            List <CellStructure> list = new List <CellStructure>();

            try
            {
                sqlConnection = GetSqlConnection();
                SqlCommand sql = new SqlCommand("SELECT * from Cellular_Structures", sqlConnection);
                sqlConnection.Close();
                sqlConnection.Open();

                SqlDataReader sDR = sql.ExecuteReader();

                if (sDR.HasRows)
                {
                    while (sDR.Read())
                    {
                        CellStructure cs = new CellStructure();

                        cs.Id          = sDR.GetInt32(0);
                        cs.Description = sDR.GetString(1);


                        List <int>  idCells = GetListCellInCS(cs.Id);
                        List <Cell> cells   = GetCells();

                        foreach (int id in idCells)
                        {
                            cs.Cells.Add(cells.FindLast(x => x.Id == id));
                        }

                        cs.Properties = GetPropertyValues(ParentType.CelluralStructure).FindAll(x => x.IdParent == cs.Id);

                        list.Add(cs);
                    }
                }
                sqlConnection.Close();
            }
            catch (System.Exception ex)
            {
                //DialogManager.showDialogError("Возможна ошибка базы данных! Проверьте!", "Внимание!");
                Console.WriteLine(ex);
            }
            return(list);
        }