Ejemplo n.º 1
0
        }//FindSparePartsByArticulOrTitle

        public static IList <SparePart> FindSparePartsByArticuls(IList <string> articuls)
        {
            IList <SparePart> spareParts = new List <SparePart>();

            using (SQLiteConnection connection = GetDatabaseConnection("SparePartConfig") as SQLiteConnection)
            {
                connection.Open();
                var cmd = new SQLiteCommand(null, connection);

                cmd.CommandText = "SELECT * FROM SparePart WHERE Articul LIKE @Articul";

                SQLiteParameter param = new SQLiteParameter();
                param.ParameterName = "@Articul";
                cmd.Parameters.Add(param);
                cmd.Prepare();


                for (int i = 0; i < articuls.Count; ++i)
                {
                    param.Value = articuls[i];
                    var dataReader = cmd.ExecuteReader();

                    while (dataReader.Read())
                    {
                        SparePart sparePart = new SparePart
                        {
                            Photo        = dataReader["Photo"] as string,
                            Id           = Convert.ToInt32(dataReader["Id"]),
                            Articul      = dataReader["Articul"] as string,
                            Title        = dataReader["Title"] as string,
                            Manufacturer = PartsDAL.FindManufacturerTitleById(Convert.ToInt32(dataReader["ManufacturerId"])),
                            Price        = Convert.ToDouble(dataReader["Price"]),
                            Markup       = Convert.ToDouble(dataReader["Markup"]),
                            Count        = Convert.ToDouble(dataReader["Count"]),
                            Unit         = dataReader["Unit"] as string
                        };
                        sparePart.SellingPrice = CalculationOfSellingPrice(sparePart.Price, sparePart.Markup);
                        sparePart.Providers    = FindSparePartProvidersById(sparePart.Id, connection);

                        spareParts.Add(sparePart);
                    } //while
                    dataReader.Dispose();  //Спорный момент с dataReader. Без Dispose выдаёт ошибку "dataReader already activate".
                }     //for
                connection.Close();
            }         //using
            return(spareParts);
        }             //FindSparePartsByArticuls
Ejemplo n.º 2
0
        }         //FindSparePartsByTitle

        public static IList <SparePart> FindSparePartsByArticulOrTitle(string TitleOrArticul)
        {
            IList <SparePart> spareParts = new List <SparePart>();

            using (SQLiteConnection connection = GetDatabaseConnection("SparePartConfig") as SQLiteConnection)
            {
                connection.Open();
                var cmd = new SQLiteCommand(null, connection);

                cmd.CommandText = "SELECT * FROM SparePart WHERE Title LIKE @TitleOrArticul OR Articul LIKE @TitleOrArticul";

                SQLiteParameter param = new SQLiteParameter();
                param.ParameterName = "@TitleOrArticul";
                param.Value         = TitleOrArticul;

                cmd.Parameters.Add(param);
                cmd.Prepare();

                var dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    var sparePart = new SparePart
                    {
                        Photo        = dataReader["Photo"] as string,
                        Id           = Convert.ToInt32(dataReader["Id"]),
                        Articul      = dataReader["Articul"] as string,
                        Title        = dataReader["Title"] as string,
                        Manufacturer = PartsDAL.FindManufacturerTitleById(Convert.ToInt32(dataReader["ManufacturerId"])),
                        Price        = Convert.ToDouble(dataReader["Price"]),
                        Markup       = Convert.ToDouble(dataReader["Markup"]),
                        Count        = Convert.ToDouble(dataReader["Count"]),
                        Unit         = dataReader["Unit"] as string
                    };
                    sparePart.SellingPrice = CalculationOfSellingPrice(sparePart.Price, sparePart.Markup);
                    sparePart.Providers    = FindSparePartProvidersById(sparePart.Id, connection);

                    spareParts.Add(sparePart);
                }//while

                connection.Close();
            }
            return(spareParts);
        }//FindSparePartsByArticulOrTitle
Ejemplo n.º 3
0
        }             //FindSparePartsByArticuls

        public static SparePart FindSparePartById(int id)
        {
            SparePart sparePart = null;

            using (SQLiteConnection connection = GetDatabaseConnection("SparePartConfig") as SQLiteConnection)
            {
                connection.Open();
                var cmd = new SQLiteCommand(null, connection);

                cmd.CommandText = "SELECT * FROM SparePart WHERE Id = @Id";

                SQLiteParameter param = new SQLiteParameter();
                param.ParameterName = "@Id";
                param.Value         = id;

                cmd.Parameters.Add(param);
                cmd.Prepare();

                var dataReader = cmd.ExecuteReader();

                dataReader.Read();

                sparePart = new SparePart
                {
                    Photo        = dataReader["Photo"] as string,
                    Id           = Convert.ToInt32(dataReader["Id"]),
                    Articul      = dataReader["Articul"] as string,
                    Title        = dataReader["Title"] as string,
                    Manufacturer = PartsDAL.FindManufacturerTitleById(Convert.ToInt32(dataReader["ManufacturerId"])),
                    Price        = Convert.ToDouble(dataReader["Price"]),
                    Markup       = Convert.ToDouble(dataReader["Markup"]),
                    Count        = Convert.ToDouble(dataReader["Count"]),
                    Unit         = dataReader["Unit"] as string
                };
                sparePart.SellingPrice = CalculationOfSellingPrice(sparePart.Price, sparePart.Markup);
                sparePart.Providers    = FindSparePartProvidersById(sparePart.Id, connection);

                connection.Close();
            } //using
            return(sparePart);
        }     //FindSparePartById
Ejemplo n.º 4
0
        }             //FindSparePartById

        public static IList <SparePart> FindSparePartById(IList <int> sparePartsId, SQLiteConnection openConnection)
        {
            IList <SparePart> spareParts = new List <SparePart>();
            var cmd = new SQLiteCommand("SELECT * FROM SparePart WHERE Id = @Id", openConnection);

            SQLiteParameter param = new SQLiteParameter();

            param.ParameterName = "@Id";

            cmd.Parameters.Add(param);
            cmd.Prepare();

            for (int i = 0; i < sparePartsId.Count; ++i)
            {
                param.Value = sparePartsId[i];
                var dataReader = cmd.ExecuteReader();

                while (dataReader.Read())
                {
                    SparePart sparePart = new SparePart
                    {
                        Photo        = dataReader["Photo"] as string,
                        Id           = Convert.ToInt32(dataReader["Id"]),
                        Articul      = dataReader["Articul"] as string,
                        Title        = dataReader["Title"] as string,
                        Manufacturer = PartsDAL.FindManufacturerTitleById(Convert.ToInt32(dataReader["ManufacturerId"])),
                        Price        = Convert.ToDouble(dataReader["Price"]),
                        Markup       = Convert.ToDouble(dataReader["Markup"]),
                        Count        = Convert.ToDouble(dataReader["Count"]),
                        Unit         = dataReader["Unit"] as string
                    };
                    sparePart.SellingPrice = CalculationOfSellingPrice(sparePart.Price, sparePart.Markup);
                    sparePart.Providers    = FindSparePartProvidersById(sparePart.Id, openConnection);

                    spareParts.Add(sparePart);
                } //while
                dataReader.Dispose();  //Спорный момент с dataReader. Без Dispose выдаёт ошибку "dataReader already activate".
            }     //for
            return(spareParts);
        }         //FindSparePartById
Ejemplo n.º 5
0
        }//FindSparePartByArticul

        public static IList <SparePart> FindSparePartByArticul(string sparePartArticul, SQLiteConnection openConnection)
        {
            IList <SparePart> spareParts = new List <SparePart>();

            var cmd = new SQLiteCommand(null, openConnection);

            cmd.CommandText = "SELECT * FROM SparePart WHERE Articul LIKE @Articul";

            SQLiteParameter param = new SQLiteParameter();

            param.ParameterName = "@Articul";
            param.Value         = sparePartArticul;

            cmd.Parameters.Add(param);
            cmd.Prepare();

            var dataReader = cmd.ExecuteReader();

            while (dataReader.Read())
            {
                var sparePart = new SparePart
                {
                    Photo        = dataReader["Photo"] as string,
                    Id           = Convert.ToInt32(dataReader["Id"]),
                    Articul      = dataReader["Articul"] as string,
                    Title        = dataReader["Title"] as string,
                    Manufacturer = PartsDAL.FindManufacturerTitleById(Convert.ToInt32(dataReader["ManufacturerId"])),
                    Price        = Convert.ToDouble(dataReader["Price"]),
                    Markup       = Convert.ToDouble(dataReader["Markup"]),
                    Count        = Convert.ToDouble(dataReader["Count"]),
                    Unit         = dataReader["Unit"] as string
                };
                sparePart.SellingPrice = CalculationOfSellingPrice(sparePart.Price, sparePart.Markup);
                sparePart.Providers    = FindSparePartProvidersById(sparePart.Id, openConnection);

                spareParts.Add(sparePart);
            } ///while
            return(spareParts);
        }     //FindSparePartByArticul