Beispiel #1
0
        //寫入店家尺寸(在新增飲料編輯時使用)
        public static bool EditSize(int MenuID, Add2_MEnuSis AddType)
        {
            NewDrinkDB db = new NewDrinkDB();

            var Nsis = new MenuSISEdit()
            {
                MenuID   = MenuID,
                Size     = AddType.Size,
                SizeName = AddType.SizeName
            };
            var SizeCheck = Models.ManagerModels.CheckCheckboxNotEmpty_MenuSIS(Nsis, "size");
            //檢查未勾選的,從店家尺寸表及飲料尺寸價表刪除////////////////////////////////////////
            var  SizeFind = db.MenuSizes.Where(m => m.MenuID == Nsis.MenuID);
            var  NoSize   = Models.ManagerModels.CheckCheckboxNotEmpty_MenuSIS(Nsis, "sizeNo");
            bool AreCheck = true;
            bool AreFalse = false;

            if (SizeCheck != null || SizeCheck.Count > 0)
            {
                //檢查勾選的,從店家尺寸表新增
                foreach (var itemsize in SizeCheck)
                {
                    int newitem = 0;
                    //檢查新勾的有哪些
                    foreach (var item in SizeFind)
                    {
                        if (itemsize == item.SizeID)
                        {
                            AreCheck = true;
                            break;
                        }
                        else
                        {
                            //比對找到新勾選的項目
                            AreCheck = false;
                            newitem  = itemsize;
                        }
                    }
                    //加入新勾選的項目
                    if (!AreCheck)
                    {
                        db.MenuSizes.Add(new MenuSize()
                        {
                            MenuID = Nsis.MenuID,
                            SizeID = newitem
                        });
                    }
                }
            }
            foreach (var itemNo in NoSize)
            {
                //檢查以前勾的有哪些
                foreach (var item in SizeFind)
                {
                    if (itemNo == item.SizeID)
                    {
                        AreFalse = true;
                        break;
                    }
                }
                //刪除不勾選的項目
                if (AreFalse)
                {
                    var deleteS = db.MenuSizes.Where(m => m.MenuID == Nsis.MenuID && m.SizeID == itemNo);
                    db.MenuSizes.RemoveRange(deleteS);

                    var deleteST = db.SizeTables.Where(m => m.MenuID == Nsis.MenuID && m.SizeID == itemNo);
                    db.SizeTables.RemoveRange(deleteST);
                }
            }
            //新增尺寸
            if (Nsis.SizeName != null)
            {
                var NewSizeType = new List <SizeType>();
                foreach (var item in Nsis.SizeName)
                {
                    var NoRepeat = db.SizeTypes.Where(m => m.SizeName == item.SizeName);
                    if (NoRepeat.FirstOrDefault() == null && !String.IsNullOrEmpty(item.SizeName))
                    {
                        NewSizeType.Add(new SizeType()
                        {
                            SizeName = item.SizeName
                        });
                    }
                }
                if (NewSizeType != null && NewSizeType.Count != 0)
                {
                    db.SizeTypes.AddRange(NewSizeType);
                    db.SaveChanges();
                }
                //取出尺寸ID,寫入店家尺寸表
                var NewMenuSize = new List <MenuSize>();
                foreach (var item in Nsis.SizeName)
                {
                    if (!String.IsNullOrEmpty(item.SizeName))
                    {
                        int SizeID = Models.ManagerModels.SweetID(item.SizeName, "size");
                        NewMenuSize.Add(new MenuSize()
                        {
                            MenuID = Nsis.MenuID,
                            SizeID = SizeID
                        });
                    }
                }
                if (NewMenuSize != null && NewMenuSize.Count != 0)
                {
                    db.MenuSizes.AddRange(NewMenuSize);
                }
            }

            db.SaveChanges();
            db.Dispose();
            return(true);
        }
Beispiel #2
0
        //將加料資料判斷,並寫進資料庫
        public static bool EditAdditem(int MenuID, Add2_MEnuSis AddType)
        {
            NewDrinkDB db = new NewDrinkDB();

            var Dele = new List <int>();

            //先取出原有的所有配料
            var olditem = db.AddItemTypePrices.Where(m => m.MenuID == MenuID);

            if (olditem.FirstOrDefault() != null)
            {
                //如果AddType.AddItemCreate = null就將配料全刪除
                if (AddType.AddItemCreate == null)
                {
                    foreach (var item in olditem)
                    {
                        Dele.Add(item.ID);
                        //刪除價錢表
                        var DeAddTP = db.AddItemTypePrices.Where(m => m.ItemID == item.ItemID && m.MenuID == MenuID);
                        foreach (var item2 in DeAddTP)
                        {
                            //刪除飲料加料價表
                            var DeAddTable = db.AddItemTables.Where(m => m.ItemIDPriceID == item2.ID);
                            db.AddItemTables.RemoveRange(DeAddTable);
                        }
                        db.AddItemTypePrices.RemoveRange(DeAddTP);
                        db.SaveChanges();
                    }
                    db.Dispose();
                    return(true);
                }


                foreach (var item in olditem)
                {
                    var T = true;
                    foreach (var itemAdd in AddType.AddItemCreate)
                    {
                        if (item.ItemID == itemAdd.ID)
                        {
                            T = true;
                            break;
                        }
                        else
                        {
                            T = false;
                        }
                    }
                    if (T == false)
                    {
                        Dele.Add(item.ID);
                        //刪除價錢表
                        var DeAddTP = db.AddItemTypePrices.Where(m => m.ItemID == item.ItemID && m.MenuID == MenuID);
                        foreach (var item2 in DeAddTP)
                        {
                            //刪除飲料加料價表
                            var DeAddTable = db.AddItemTables.Where(m => m.ItemIDPriceID == item2.ID);
                            db.AddItemTables.RemoveRange(DeAddTable);
                        }
                        db.AddItemTypePrices.RemoveRange(DeAddTP);
                        db.SaveChanges();
                    }
                }
            }


            //再用要更新的配料ID去找看看哪一筆不在了
            //編輯以itemID更新舊資料
            //判斷更新
            foreach (var item in AddType.AddItemCreate)
            {
                if (item.ID != 0)
                {
                    //更新配料名(種類表)
                    var UpAddT = db.AddItemTypes.Find(item.ID);
                    if (UpAddT != null)
                    {
                        UpAddT.ItemName = item.ItemName;
                    }
                    //更新價錢(價錢表)
                    var UpAddTP = db.AddItemTypePrices.Where(m => m.MenuID == MenuID && m.ItemID == item.ID);
                    if (UpAddTP != null)
                    {
                        var UpAddTPL = UpAddTP.Where(m => m.SizeNumber == 0);
                        foreach (var LSize in UpAddTPL)
                        {
                            LSize.ItemPrice = item.LPrice;
                        }

                        var UpAddTPM = UpAddTP.Where(m => m.SizeNumber == 1);
                        foreach (var MSize in UpAddTPM)
                        {
                            MSize.ItemPrice = item.MPrice;
                        }

                        var UpAddTPS = UpAddTP.Where(m => m.SizeNumber == 2);
                        foreach (var SSize in UpAddTPS)
                        {
                            SSize.ItemPrice = item.SPrice;
                        }
                    }
                    db.SaveChanges();
                }
            }



            //新增(2種狀況)
            //已有的種類(判斷不得重複)
            //新的種類:新增加料種類表,寫入新的配料價表
            if (AddType.AddItemCreate != null)
            {
                foreach (var item in AddType.AddItemCreate)
                {
                    if (item.ID == 0)
                    {
                        //新增加料種類表
                        var query = db.AddItemTypes.Add(new AddItemType()
                        {
                            ItemName = item.ItemName
                        });
                        db.SaveChanges();
                        int ItemID  = 0;
                        var CheckID = db.AddItemTypes.Where(m => m.ItemName == item.ItemName);
                        foreach (var itemid in CheckID)
                        {
                            ItemID = itemid.ID;
                        }

                        //寫入新的配料價表
                        var AdditemPL = db.AddItemTypePrices.Add(new AddItemTypePrice()
                        {
                            ItemID = ItemID, SizeNumber = 0, ItemPrice = item.LPrice, MenuID = MenuID
                        });
                        var AdditemPM = db.AddItemTypePrices.Add(new AddItemTypePrice()
                        {
                            ItemID = ItemID, SizeNumber = 1, ItemPrice = item.MPrice, MenuID = MenuID
                        });
                        var AdditemPS = db.AddItemTypePrices.Add(new AddItemTypePrice()
                        {
                            ItemID = ItemID, SizeNumber = 2, ItemPrice = item.SPrice, MenuID = MenuID
                        });

                        db.SaveChanges();
                    }
                }
            }

            db.Dispose();
            return(true);
        }
Beispiel #3
0
        //寫入店家甜度(在新增飲料編輯時使用)
        public static bool EditSweet(int MenuID, Add2_MEnuSis AddType)
        {
            NewDrinkDB db = new NewDrinkDB();

            var Nsis = new MenuSISEdit()
            {
                MenuID    = MenuID,
                Sweet     = AddType.Sweet,
                SweetName = AddType.SweetName
            };
            var SweetCheck = Models.ManagerModels.CheckCheckboxNotEmpty_MenuSIS(Nsis, "sweet");

            //判斷甜度.只填一個或都填的情況/////////////////////////////////////
            //檢查未勾選的,從店家甜度表及飲料甜度表刪除
            var  SweetFind = db.MenuSweets.Where(m => m.MenuID == Nsis.MenuID);
            var  NoSweet   = Models.ManagerModels.CheckCheckboxNotEmpty_MenuSIS(Nsis, "sweetNo");
            bool AreCheck  = true;
            bool AreFalse  = false;

            if (SweetCheck != null || SweetCheck.Count > 0)
            {
                //檢查勾選的,從店家甜度表新增
                foreach (var itemsweet in SweetCheck)
                {
                    int newitem = 0;
                    //檢查新勾的有哪些
                    foreach (var item in SweetFind)
                    {
                        if (itemsweet == item.SweetID)
                        {
                            AreCheck = true;
                            break;
                        }
                        else
                        {
                            //比對找到新勾選的項目
                            AreCheck = false;
                            newitem  = itemsweet;
                        }
                    }
                    //加入新勾選的項目
                    if (!AreCheck)
                    {
                        db.MenuSweets.Add(new MenuSweet()
                        {
                            MenuID  = Nsis.MenuID,
                            SweetID = newitem
                        });
                    }
                }
            }
            foreach (var itemNo in NoSweet)
            {
                //檢查以前勾的有哪些
                foreach (var item in SweetFind)
                {
                    if (itemNo == item.SweetID)
                    {
                        AreFalse = true;
                        break;
                    }
                }
                //刪除不勾選的項目
                if (AreFalse)
                {
                    var deleteS  = db.MenuSweets.Where(m => m.MenuID == Nsis.MenuID && m.SweetID == itemNo);
                    var deleteST = db.SizeTables.Where(m => m.MenuID == Nsis.MenuID);
                    foreach (var item in deleteST)
                    {
                        var deleteSweetTable = db.SweetTables.Where(m => m.SizePID == item.ID && m.SweetID == itemNo);
                        db.SweetTables.RemoveRange(deleteSweetTable);
                    }
                    db.MenuSweets.RemoveRange(deleteS);
                }
            }
            //新增甜度
            if (Nsis.SweetName != null)
            {
                //若新增,則新增甜度表種類
                //判斷是否有重複的名字
                var NewSweetType = new List <SweetType>();
                foreach (var item in Nsis.SweetName)
                {
                    var NoRepeat = db.SweetTypes.Where(m => m.SweetName == item.SweetName);
                    if (NoRepeat.FirstOrDefault() == null && !String.IsNullOrEmpty(item.SweetName))
                    {
                        NewSweetType.Add(new SweetType()
                        {
                            SweetName = item.SweetName
                        });
                    }
                }
                if (NewSweetType != null && NewSweetType.Count != 0)
                {
                    db.SweetTypes.AddRange(NewSweetType);
                    db.SaveChanges();
                }
                //取出甜度ID,寫入店家甜度表
                var NewMenuSweet = new List <MenuSweet>();
                foreach (var item in Nsis.SweetName)
                {
                    if (!String.IsNullOrEmpty(item.SweetName))
                    {
                        int SweetID = Models.ManagerModels.SweetID(item.SweetName, "sweet");
                        NewMenuSweet.Add(new MenuSweet()
                        {
                            MenuID  = Nsis.MenuID,
                            SweetID = SweetID
                        });
                    }
                }
                if (NewMenuSweet != null && NewMenuSweet.Count != 0)
                {
                    db.MenuSweets.AddRange(NewMenuSweet);
                }
            }

            db.SaveChanges();
            db.Dispose();
            return(true);
        }
Beispiel #4
0
        //寫入店家冰度(在新增飲料編輯時使用)
        public static bool EditIce(int MenuID, Add2_MEnuSis AddType)
        {
            NewDrinkDB db = new NewDrinkDB();

            var Nsis = new MenuSISEdit()
            {
                MenuID  = MenuID,
                IceHot  = AddType.IceHot,
                IceName = AddType.IceName
            };
            var IceCheck = Models.ManagerModels.CheckCheckboxNotEmpty_MenuSIS(Nsis, "ice");
            //檢查未勾選的,從店家冰度表及飲料冰度表刪除////////////////////////////////////////
            var  IceFind  = db.MenuIces.Where(m => m.MenuID == Nsis.MenuID);
            var  NoIce    = Models.ManagerModels.CheckCheckboxNotEmpty_MenuSIS(Nsis, "iceNo");
            bool AreCheck = true;
            bool AreFalse = false;

            if (IceCheck != null || IceCheck.Count > 0)
            {
                //檢查勾選的,從店家冰度表新增
                foreach (var itemice in IceCheck)
                {
                    int newitem = 0;
                    //檢查新勾的有哪些
                    foreach (var item in IceFind)
                    {
                        if (itemice == item.IceID)
                        {
                            AreCheck = true;
                            break;
                        }
                        else
                        {
                            //比對找到新勾選的項目
                            AreCheck = false;
                            newitem  = itemice;
                        }
                    }
                    //加入新勾選的項目
                    if (!AreCheck)
                    {
                        db.MenuIces.Add(new MenuIce()
                        {
                            MenuID = Nsis.MenuID,
                            IceID  = newitem
                        });
                    }
                }
            }
            foreach (var itemNo in NoIce)
            {
                //檢查以前勾的有哪些
                foreach (var item in IceFind)
                {
                    if (itemNo == item.IceID)
                    {
                        AreFalse = true;
                        break;
                    }
                }
                //刪除不勾選的項目
                if (AreFalse)
                {
                    var deleteI  = db.MenuIces.Where(m => m.MenuID == Nsis.MenuID && m.IceID == itemNo);
                    var deleteIT = db.SizeTables.Where(m => m.MenuID == Nsis.MenuID);
                    foreach (var item in deleteIT)
                    {
                        var deleteIceTable = db.IceTables.Where(m => m.SizePID == item.ID && m.IceID == itemNo);
                        db.IceTables.RemoveRange(deleteIceTable);
                    }
                    db.MenuIces.RemoveRange(deleteI);
                }
            }
            //新增冰度
            if (Nsis.IceName != null)
            {
                //若新增,則新增冰度表種類
                //判斷是否有重複的名字
                var NewIceType = new List <IceType>();
                foreach (var item in Nsis.IceName)
                {
                    var NoRepeat = db.IceTypes.Where(m => m.IceName == item.IceName);
                    if (NoRepeat.FirstOrDefault() == null && !String.IsNullOrEmpty(item.IceName))
                    {
                        NewIceType.Add(new IceType()
                        {
                            IceName = item.IceName
                        });
                    }
                }
                if (NewIceType != null && NewIceType.Count != 0)
                {
                    db.IceTypes.AddRange(NewIceType);
                    db.SaveChanges();
                }
                //取出冰度ID,寫入店家冰度表
                var NewMenuIce = new List <MenuIce>();
                foreach (var item in Nsis.IceName)
                {
                    if (!String.IsNullOrEmpty(item.IceName))
                    {
                        int IceID = Models.ManagerModels.SweetID(item.IceName, "ice");
                        NewMenuIce.Add(new MenuIce()
                        {
                            MenuID = Nsis.MenuID,
                            IceID  = IceID
                        });
                    }
                }
                if (NewMenuIce != null && NewMenuIce.Count != 0)
                {
                    db.MenuIces.AddRange(NewMenuIce);
                }
            }

            db.SaveChanges();
            db.Dispose();
            return(true);
        }
Beispiel #5
0
        //將甜度,冰度,尺寸加入陣列
        public static List <int> CheckCheckboxNotEmpty2(Add2_MEnuSis newM, string type)
        {
            var addItem = new List <int>();

            switch (type)
            {
            case "sweet":
                foreach (var item in newM.Sweet)
                {
                    if (item.Selected)
                    {
                        //加到陣列
                        var DD = Int32.Parse(item.Value);
                        addItem.Add(DD);
                    }
                    else
                    {
                        //跳過
                        continue;
                    }
                }
                break;

            case "ice":
                foreach (var item in newM.IceHot)
                {
                    if (item.Selected)
                    {
                        //加到陣列
                        var DD = Int32.Parse(item.Value);
                        addItem.Add(DD);
                    }
                    else
                    {
                        //跳過
                        continue;
                    }
                }
                break;

            case "size":
                foreach (var item in newM.Size)
                {
                    if (item.Selected)
                    {
                        //加到陣列
                        var DD = Int32.Parse(item.Value);
                        addItem.Add(DD);
                    }
                    else
                    {
                        //跳過
                        continue;
                    }
                }
                break;

            default:
                break;
            }

            return(addItem);
        }