コード例 #1
0
        //取得錯誤而返回的視圖
        public static MenuSISEdit ErrorBackMenu_MenuSIS(MenuSISEdit Nsis)
        {
            Nsis.Sweet  = MenuSIS_GetSweet(Nsis.MenuID);
            Nsis.IceHot = MenuSIS_GetIce(Nsis.MenuID);
            Nsis.Size   = MenuSIS_GetSize(Nsis.MenuID);

            return(Nsis);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
        //將甜度,冰度,尺寸加入陣列(編輯店家甜度.冰度.尺寸的視圖用,含勾選及不勾選)
        public static List <int> CheckCheckboxNotEmpty_MenuSIS(MenuSISEdit Nsis, string type)
        {
            var addItem = new List <int>();

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

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

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

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

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

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

            default:
                break;
            }

            return(addItem);
        }