Beispiel #1
0
        public static bool ChangeDbText(string fdname, string name, string abv, string cat, string type)
        {
            MaterialCommodities mc = GetCatName(cat, name);             // is the name,cat duplex there?

            if (mc != null && !mc.fdname.Equals(fdname))                // yes, so entry is there with name/cat, and fdname is the same, ok.  else abort
            {
                return(false);                                          // if fdname is different to the one we want to modify, but cat/name is there, its a duplicate
            }
            mc = GetCatFDName(null, fdname);                            // now pick it up by its primary key for frontier, the fdname

            if (mc != null)
            {
                mc.name      = name;
                mc.shortname = abv;
                mc.category  = cat;
                mc.type      = type;
                mc.flags     = 1;
                mc.Update();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        public static void AddNewTypeC(SQLiteConnectionUser cn, string c, Color cl, string namelist, string t, string sn = "")
        {
            string[] list = namelist.Split(';');

            foreach (string name in list)
            {
                if (name.Length > 0)   // just in case a semicolon slips thru
                {
                    string fdname = EDDiscovery.Tools.FDName(name);

                    MaterialCommodities mc = GetCatFDName(null, fdname, cn);

                    if (mc == null)
                    {
                        mc = new MaterialCommodities(0, c, name, fdname, t, sn, cl, 0);
                        mc.Add(cn);
                    }               // don't change any user changed fields
                    else if (mc.flags == 0 && (!mc.name.Equals(name) && !mc.shortname.Equals(sn) || !mc.category.Equals(c) || !mc.type.Equals(t) || mc.colour.ToArgb() != cl.ToArgb()))
                    {
                        mc.name      = name;
                        mc.shortname = sn;          // So, name is there, update the others
                        mc.category  = c;
                        mc.type      = t;
                        mc.colour    = cl;
                        mc.Update(cn);
                    }
                }
            }
        }
Beispiel #3
0
        public void Craft(string name, int num)
        {
            MaterialCommodities mc = list.Find(x => x.fdname.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (mc != null)                 // if we find it, we remove count, else we don't worry since we may have not got the bought/collected event
            {
                mc.count = Math.Max(mc.count - num, 0);
            }
        }
Beispiel #4
0
        public void Set(string cat, string name, int num, double price, SQLiteConnectionUser conn, bool ignorecatonsearch = false)
        {
            MaterialCommodities mc = EnsurePresent(cat, name, conn);

            mc.count = num;
            if (price > 0)
            {
                mc.price = price;
            }
        }
Beispiel #5
0
 public MaterialCommodities(MaterialCommodities c)     // copy constructor, ensure a different copy of this
 {
     id        = c.id;
     category  = c.category;
     name      = String.Copy(c.name);
     fdname    = String.Copy(c.fdname);
     type      = String.Copy(c.type);
     shortname = c.shortname;
     colour    = c.colour;
     flags     = c.flags;
     count     = c.count;
     price     = c.price;
 }
Beispiel #6
0
        // ignore cat is only used if you don't know what it is
        public void Change(string cat, string name, int num, long price, SQLiteConnectionUser conn, bool ignorecatonsearch = false)
        {
            MaterialCommodities mc = EnsurePresent(cat, name, conn, ignorecatonsearch);

            double costprev = mc.count * mc.price;
            double costnew  = num * price;

            mc.count = Math.Max(mc.count + num, 0);;

            if (mc.count > 0 && num > 0)                    // if bought (defensive with mc.count)
            {
                mc.price = (costprev + costnew) / mc.count; // price is now a combination of the current cost and the new cost. in case we buy in tranches
            }
        }
Beispiel #7
0
        public MaterialCommodities GetMaterialCommodity(string cat, string fdname, SQLiteConnectionUser conn)
        {
            MaterialCommodities mcdb = MaterialCommodities.GetCatFDName(cat, fdname, conn);    // look up in DB and see if we have a record of this type of item

            MaterialCommodities mc = null;

            if (mcdb != null)
            {
                mc = new MaterialCommodities(0, cat, mcdb.name, mcdb.fdname, mcdb.type, mcdb.shortname, Color.Green, 0);
            }
            else
            {
                mc = new MaterialCommodities(0, cat, fdname, fdname, "", "", Color.Green, 0);
            }

            return(mc);
        }
Beispiel #8
0
        // ifnorecatonsearch is used if you don't know if its a material or commodity.. for future use.

        private MaterialCommodities EnsurePresent(string cat, string fdname, SQLiteConnectionUser conn, bool ignorecatonsearch = false)
        {
            MaterialCommodities mc = list.Find(x => x.fdname.Equals(fdname, StringComparison.InvariantCultureIgnoreCase) && (ignorecatonsearch || x.category.Equals(cat, StringComparison.InvariantCultureIgnoreCase)));

            if (mc == null)
            {
                MaterialCommodities mcdb = MaterialCommodities.GetCatFDName(cat, fdname, conn); // look up in DB and see if we have a record of this type of item

                if (mcdb == null)                                                               // no record of this, add as Unknown to db
                {
                    mcdb = new MaterialCommodities(0, cat, fdname, fdname, "", "", Color.Green, 0);
                    mcdb.Add();                 // and add to data base
                }

                mc = new MaterialCommodities(0, mcdb.category, mcdb.name, mcdb.fdname, mcdb.type, mcdb.shortname, mcdb.colour, 0);        // make a new entry
                list.Add(mc);
            }

            return(mc);
        }