Exemple #1
0
        public SToreRack(Positionable positionable, int price, string name, string manufact, int x, int y, int z) : base(positionable, price, manufact)
        {
            Id        = ID;
            this.Name = name;
            ID++;
            positionable.changePos();

            RackDB RDB = new RackDB(Name, 1, Id);

            RDB.InDB();

            IdRack = RDB.id;

            Models.StoreRack BR = new Models.StoreRack {
                id = ID - 1, name = Name, Firma = manufact, Square = Convert.ToString(x * y), Price = Convert.ToString(price)
            };
            InXML IX = new InXML("D:\\obj.xml", BR, true);
        }
Exemple #2
0
        public InXML(string pathname, Models.StoreRack br, bool qw)
        {
            if (qw)
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(pathname);
                XmlElement xRoot = xDoc.DocumentElement;
                // создаем новый элемент user
                XmlElement userElem = xDoc.CreateElement("user");
                // создаем атрибут name
                XmlAttribute nameAttr = xDoc.CreateAttribute("name");

                XmlElement IdElem      = xDoc.CreateElement("Id");
                XmlElement companyElem = xDoc.CreateElement("company");
                XmlElement squareElem  = xDoc.CreateElement("square");
                XmlElement priceElem   = xDoc.CreateElement("price");
                // создаем текстовые значения для элементов и атрибута
                XmlText idText      = xDoc.CreateTextNode(Convert.ToString(br.id));
                XmlText nameText    = xDoc.CreateTextNode(br.name + Convert.ToString(br));
                XmlText companyText = xDoc.CreateTextNode(br.Firma);
                XmlText squareText  = xDoc.CreateTextNode(Convert.ToString(br.Square));
                XmlText priceText   = xDoc.CreateTextNode(Convert.ToString(br.Price));

                //добавляем узлы
                nameAttr.AppendChild(nameText);
                IdElem.AppendChild(idText);
                companyElem.AppendChild(companyText);
                priceElem.AppendChild(priceText);
                userElem.Attributes.Append(nameAttr);
                userElem.AppendChild(IdElem);
                userElem.AppendChild(companyElem);
                userElem.AppendChild(squareElem);
                userElem.AppendChild(priceElem);
                xRoot.AppendChild(userElem);
                xDoc.Save(pathname);
            }
            // string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=BetekBash;Integrated Security=True";

            // Создание подключения
            SqlConnection connection = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename ='C:\Users\nikit\source\repos\ConsoleApp3\ConsoleApp3\Rack.mdf'; Integrated Security = True");

            try
            {
                // Открываем подключение
                connection.Open();
                Console.WriteLine("Подключение открыто");

                int    ID     = br.id;
                string Name   = br.name;
                string Firma  = br.Firma;
                string Square = br.Square;
                string Price  = br.Price;


                string sql = string.Format("Insert Into StoreRack" +
                                           "(ID, Name, Firma, Square, Price) Values(@ID, @Name, @Firma, @Square, @Price)");

                using (SqlCommand cmd = new SqlCommand(sql, connection))
                {
                    // Добавить параметры
                    cmd.Parameters.AddWithValue("@ID", ID);
                    cmd.Parameters.AddWithValue("@Name", Name);
                    cmd.Parameters.AddWithValue("@Firma", Firma);
                    cmd.Parameters.AddWithValue("@Square", Square);
                    cmd.Parameters.AddWithValue("@Price", Price);

                    cmd.ExecuteNonQuery();
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                // закрываем подключение
                connection.Close();
                Console.WriteLine("Подключение закрыто...");
            }
        }