Beispiel #1
0
        public static void Delete(int id)
        {
            DBExecutor <int> dbExecutor = new DBExecutor <int>();

            dbExecutor.Execute(delegate(SqlCommand myCommand)
            {
                int updatedRows;
                myCommand.CommandText = string.Format("DELETE FROM Stock WHERE ItemId={0}", id);
                updatedRows           = myCommand.ExecuteNonQuery();
                return(updatedRows);
            }
                               );
        }
Beispiel #2
0
        public void Save(int itemid, string batch, int opStock)
        {
            DBExecutor <int> dbExecutor = new DBExecutor <int>();

            dbExecutor.Execute(delegate(SqlCommand myCommand)
            {
                int updatedRows;
                myCommand.CommandText = string.Format("INSERT INTO Stock VALUES({0},'{1}',0,0,{2},'2018-01-01')", itemid, batch, opStock);
                updatedRows           = myCommand.ExecuteNonQuery();
                return(updatedRows);
            }
                               );
        }
Beispiel #3
0
        public static string Read(int id)
        {
            string itemName = string.Empty;
            DBExecutor <string> dbExecutor = new DBExecutor <string>();

            dbExecutor.Execute(delegate(SqlCommand myCommand)
            {
                SqlDataReader tableData;
                myCommand.CommandText = string.Format("SELECT * FROM Items WHERE id={0}", id);
                tableData             = myCommand.ExecuteReader();
                while (tableData.Read())
                {
                    itemName = Convert.ToString(tableData["Name"]);
                }
                return(itemName);
            }
                               );
            return(itemName);
        }
Beispiel #4
0
        public int Save(string name)
        {
            int newId = 0;
            DBExecutor <int> dbExecutor = new DBExecutor <int>();

            dbExecutor.Execute(delegate(SqlCommand myCommand)
            {
                SqlDataReader tableData;
                myCommand.CommandText = string.Format("INSERT INTO Items VALUES('{0}')", name);
                newId = myCommand.ExecuteNonQuery();
                myCommand.CommandText = string.Format("SELECT ID FROM Items WHERE Name='{0}'", name);
                tableData             = myCommand.ExecuteReader();
                while (tableData.Read())
                {
                    newId = Convert.ToInt32(tableData["ID"]);
                }
                return(newId);
            }
                               );
            return(newId);
        }
Beispiel #5
0
        public static ItemBatch Read(int id)
        {
            DBExecutor <ItemBatch> db = new DBExecutor <ItemBatch>();

            return(db.Execute(delegate(SqlCommand cmd)
            {
                cmd.CommandText = "SELECT * FROM STOCK WHERE ID=" + id;
                var dr = cmd.ExecuteReader();
                ItemBatch ib = new ItemBatch();
                while (dr.Read())
                {
                    ib.Id = Convert.ToInt32(dr["ID"]);
                    ib.item.id = Convert.ToInt32(dr["ItemID"]);
                    ib.item.Name = Item.Read(ib.item.id);
                    ib.Batch = Convert.ToString(dr["BatchNo"]);
                    ib.CP = Convert.ToDouble(dr["CostPrice"]);
                    ib.SP = Convert.ToDouble(dr["SellingPrice"]);
                    ib.OpStock = Convert.ToInt32(dr["NoOfItems"]);
                }
                return ib;
            }));
        }
Beispiel #6
0
        public static List <Item> ReadAll()
        {
            List <Item> items = new List <Item>();
            DBExecutor <List <Item> > dbExecutor = new DBExecutor <List <Item> >();

            dbExecutor.Execute(delegate(SqlCommand myCommand)
            {
                SqlDataReader tableData;
                myCommand.CommandText = string.Format("SELECT * FROM Items");
                tableData             = myCommand.ExecuteReader();
                while (tableData.Read())
                {
                    Item item = new Item();
                    item.id   = Convert.ToInt32(tableData["ID"]);
                    item.Name = Convert.ToString(tableData["Name"]);
                    items.Add(item);
                }

                return(items);
            }
                               );
            return(items);
        }
Beispiel #7
0
        public static List <ItemBatch> ReadAll()
        {
            DBExecutor <List <ItemBatch> > db = new DBExecutor <List <ItemBatch> >();

            return(db.Execute(delegate(SqlCommand cmd)
            {
                List <ItemBatch> ret = new List <ItemBatch>();
                cmd.CommandText = "SELECT * FROM STOCK ORDER BY ItemID";
                var dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    ItemBatch ib = new ItemBatch();
                    ib.Id = Convert.ToInt32(dr["ID"]);
                    ib.item.id = Convert.ToInt32(dr["ItemID"]);
                    ib.item.Name = Item.Read(ib.item.id);
                    ib.Batch = Convert.ToString(dr["BatchNo"]);
                    ib.CP = Convert.ToDouble(dr["CostPrice"]);
                    ib.SP = Convert.ToDouble(dr["SellingPrice"]);
                    ib.OpStock = Convert.ToInt32(dr["NoOfItems"]);
                    ret.Add(ib);
                }
                return ret;
            }));
        }