// Adds record to the table orders
        public static bool AddOrder(string dates, string amounts, string mats, string dests,
                                    string fashions, string types)
        {
            BufferData bufferData = BufferData.GetInstance();

            int id = bufferData.OrdersViewTable.Data.Max(x => x.IdOrder) + 1;

            string date   = ValidateField.ValidateDate(dates);
            int    amount = ValidateField.ValidateNumber(amounts);

            mats     = ValidateField.ValidateString(mats);
            dests    = ValidateField.ValidateString(dests);
            fashions = ValidateField.ValidateString(fashions);
            types    = ValidateField.ValidateString(types);


            int idDest = bufferData.DestinationTable.Data.First(x => x.Type == dests).IdDestination;
            int idState;
            int idFashion = bufferData.FashionTable.Data.First(x => x.Name == fashions).IdFashion;
            int idType    = bufferData.MaterialTypeTable.Data.First(x => x.Name == types).IdMaterialType;
            int idMat     = bufferData.MaterialTable.Data.First(
                x => x.Name == mats &&
                x.IdFashion == idFashion &&
                x.IdMaterialType == idType).IdMaterial;

            if ((StockCalculate.GetTotalExistMaterial(idMat) - amount) >= 0)
            {
                idState = 1;
            }
            else
            {
                idState = 2;
            }

            string query;

            query = "Insert into orders (id_order, date, amount_material, id_material, id_destination, id_state) values (" +
                    id + ", '" +
                    date + "', '" +
                    amount + "', '" +
                    idMat + "', '" +
                    idDest + "', '" +
                    idState + "');";

            DepotDbConnector.GetInstance().InsertQuerry(query);
            return((idState == 1) ? true : false);
        }
        public static void UpdateOrders(int oldId, string ids, string dates, string amounts, string idMats, string idDests, string idStates)
        {
            BufferData bufferData = BufferData.GetInstance();

            int    id      = ValidateField.ValidateKey(ids, oldId, bufferData.DestinationTable.GetIdList());
            string date    = ValidateField.ValidateDate(dates);
            int    amount  = ValidateField.ValidateNumber(amounts);
            int    idMat   = ValidateField.ValidateNumber(idMats);
            int    idDest  = ValidateField.ValidateNumber(idDests);
            int    idState = ValidateField.ValidateNumber(idStates);

            if ((StockCalculate.GetTotalExistMaterial(idMat) - amount) >= 0)
            {
                idState = 1;
            }
            else
            {
                idState = 2;
            }

            string query;

            if (bufferData.EditMode == BufferData.EditModes.Update)
            {
                query = "Update orders set id_order = " + id +
                        ", date = '" + date +
                        "', amount_material = '" + amount +
                        "', id_material = '" + idMat +
                        "', id_destination = '" + idDest +
                        "', id_state = '" + idState +
                        "' where id_order = " + oldId + ";";

                DepotDbConnector.GetInstance().UpdateQuerry(query);
            }
            if (bufferData.EditMode == BufferData.EditModes.Insert)
            {
                query = "Insert into orders (id_order, date, amount_material, id_material, id_destination, id_state) values (" +
                        id + ", '" +
                        date + "', '" +
                        amount + "', '" +
                        idMat + "', '" +
                        idDest + "', '" +
                        idState + "');";

                DepotDbConnector.GetInstance().InsertQuerry(query);
            }
        }