Ejemplo n.º 1
0
        static void Main()
        {
            ///TODO: clean up duplicate entries in inventory sql table caused by multiple recipies using an item
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                FrmLoading.ShowSplashScreen();

                loadAllFromDB();

                FrmLoading.setText("Creating main form...");
                mainForm = new FrmMain();

                FrmLoading.setText("Loading main form...");

                Application.Run(mainForm);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            HistoryRecord hrCloser = new HistoryRecord()
            {
                ii = new InventoryItem()
                {
                    item = new Item()
                    {
                        id = int.MaxValue
                    }
                }
            };

            foreach (KeyValuePair <string, Inventory> i in inventories)
            {
                i.Value.addHistory(hrCloser);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads all the items and recipies from the database
        /// </summary>
        public static void loadAllFromDB()
        {
            items    = new Dictionary <int, Item>();
            recipies = new List <Recipie>();

            FrmLoading.setText("Connecting to DB...");
            using (SqlConnection dataConnection = new SqlConnection(Program.connectionString))
            {
                dataConnection.Open();

                FrmLoading.setText("Loading Items from DB...");
                //load loot
                DataSet dsItems    = new DataSet();
                string  selectLoot = @"SELECT *
								  FROM items
								  ORDER BY id"                                ;
                using (SqlDataAdapter da = new SqlDataAdapter(selectLoot, dataConnection))
                {
                    da.Fill(dsItems);
                }

                foreach (DataRow row in dsItems.Tables[0].Rows)
                {
                    Item item = new Item();
                    item.id          = (int)row["id"];
                    item.name        = (string)row["name"];
                    item.cost        = (int)row["cost"];
                    item.description = (string)row["description"];
                    item.type        = (string)row["type"];
                    item.subType     = (string)row["subType"];

                    items.Add(item.id, item);
                }

                FrmLoading.setText("Loading Recipies from DB...");

                //load recipies
                DataSet dsRecipies     = new DataSet();
                string  selectRecipies = @"SELECT *
									  FROM recipies
									  ORDER BY id"                                    ;
                using (SqlDataAdapter da = new SqlDataAdapter(selectRecipies, dataConnection))
                {
                    da.Fill(dsRecipies);
                }

                DataSet dsRecipieIngredients = new DataSet();
                string  selectIngredients    = @"SELECT *
											 FROM recipieIngredients
                                             ORDER BY recipieID";
                using (SqlDataAdapter da = new SqlDataAdapter(selectIngredients, dataConnection))
                {
                    da.Fill(dsRecipieIngredients);
                }

                int iLine = 0;
                foreach (DataRow row in dsRecipies.Tables[0].Rows)
                {
                    Recipie r = new Recipie();
                    r.id           = (int)row["id"];
                    r.result       = Program.items[(int)row["result"]];
                    r.resultQty    = (int)row["resultQty"];
                    r.profession   = (string)row["profession"];
                    r.crafterLevel = (string)row["crafterLevel"];
                    r.hours        = (byte)row["hours"];

                    while (iLine < dsRecipieIngredients.Tables[0].Rows.Count)
                    {
                        if (((int)dsRecipieIngredients.Tables[0].Rows[iLine]["recipieID"]) == r.id)
                        {
                            InventoryItem iq = new InventoryItem();
                            iq.item = Program.items[(int)dsRecipieIngredients.Tables[0].Rows[iLine]["ingredient"]];
                            iq.qty  = (int)dsRecipieIngredients.Tables[0].Rows[iLine]["qty"];
                            r.ingredients.Add(iq);
                        }
                        else if (((int)dsRecipieIngredients.Tables[0].Rows[iLine]["recipieID"]) > r.id)
                        {
                            break;
                        }
                        iLine++;
                    }

                    recipies.Add(r);
                }


                FrmLoading.setText("Generating Local Inventory Lists...");
                inventories = new Dictionary <string, Inventory>();
                inventories.Add("On Hand", new Inventory("On Hand"));
                string selectLootLocations = @"select distinct location from inventory where location != 'On Hand'";
                using (SqlCommand commIngredients = new SqlCommand(selectLootLocations, dataConnection))
                {
                    using (SqlDataReader reader = commIngredients.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            inventories.Add(reader.GetString(0), new Inventory(reader.GetString(0)));
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 static private void ShowForm()
 {
     splashForm = new FrmLoading();
     Application.Run(splashForm);
 }