コード例 #1
0
        public static bool DeleteItem(int Id)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                if (db.ITMGRPs.Where(o => o.Id == Id).Any())
                {
                    ITMGRP IGRow = db.ITMGRPs.SingleOrDefault(o => o.Id == Id);
                    if (IGRow.Item_Type == 1)
                    {
                        db.CSHMIMP0.Single(o => o.MIMMIC == IGRow.Item_Code).Group = 0;
                    }
                    else if (IGRow.Item_Type == 2)
                    {
                        db.INVRIMP0.Single(o => o.RIMRIC == IGRow.Item_Code).Group = 0;
                    }
                    if (IGRow.Item_Type == 3)
                    {
                        db.Store_Profile.Single(o => o.STORE_NO == IGRow.Item_Code).Group = 0;
                    }
                    if (IGRow.Item_Type == 4)
                    {
                        foreach (var v in db.INVRIRP0.Where(o => o.RIRMIC == IGRow.Item_Code))
                        {
                            v.Group = 0;
                        }
                    }

                    db.ITMGRPs.Remove(IGRow);
                    // Save DB
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Source);
                        System.Diagnostics.Debug.WriteLine(e.Message);
                        System.Diagnostics.Debug.WriteLine(e.StackTrace);
                        System.Diagnostics.Debug.WriteLine(e.InnerException);
                        Exception f = e.InnerException;
                        while (f != null)
                        {
                            System.Diagnostics.Debug.WriteLine("INNER:");
                            System.Diagnostics.Debug.WriteLine(f.Message);
                            System.Diagnostics.Debug.WriteLine(f.Source);
                            f = f.InnerException;
                        }
                        System.Diagnostics.Debug.WriteLine(e.Data);
                        return(false);
                    }
                    return(true);
                }
                return(false);
            }
        }
コード例 #2
0
 public static bool DeleteGroup(int GroupId)
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         if (db.ITMGRPs.Where(o => o.Group_Id == GroupId).Any())
         {
             db.ITMGRPs.RemoveRange(db.ITMGRPs.Where(o => o.Group_Id == GroupId));
             foreach (var v in db.CSHMIMP0.Where(o => o.Group == GroupId))
             {
                 v.Group = 0;
             }
             foreach (var v in db.INVRIMP0.Where(o => o.Group == GroupId))
             {
                 v.Group = 0;
             }
             foreach (var v in db.Store_Profile.Where(o => o.Group == GroupId))
             {
                 v.Group = 0;
             }
             foreach (var v in db.INVRIRP0.Where(o => o.Group == GroupId))
             {
                 v.Group = 0;
             }
             // Save DB
             try
             {
                 db.SaveChanges();
                 return(true);
             }
             catch (Exception e)
             {
                 System.Diagnostics.Debug.WriteLine(e.Source);
                 System.Diagnostics.Debug.WriteLine(e.Message);
                 System.Diagnostics.Debug.WriteLine(e.StackTrace);
                 System.Diagnostics.Debug.WriteLine(e.InnerException);
                 Exception f = e.InnerException;
                 while (f != null)
                 {
                     System.Diagnostics.Debug.WriteLine("INNER:");
                     System.Diagnostics.Debug.WriteLine(f.Message);
                     System.Diagnostics.Debug.WriteLine(f.Source);
                     f = f.InnerException;
                 }
                 System.Diagnostics.Debug.WriteLine(e.Data);
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }
コード例 #3
0
        public bool DeleteBusinessExtension(BusinessExtensionViewModel BEXViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                BUSINESS_EXT bexRow;

                if (db.BUSINESS_EXT.Where(o => o.ID.ToString().Equals(BEXViewModel.ID)).Any())
                {
                    bexRow = db.BUSINESS_EXT.Single(o => o.ID.ToString().Equals(BEXViewModel.ID));
                }
                else
                {
                    return(false);
                }

                // Get position in the table to be used in the deletion of entry in StoreProfile table
                int index = db.BUSINESS_EXT.ToList().IndexOf(bexRow);
                // Get Store_Profile rows that contain 'index' in `BET`
                List <Store_Profile> SPRows = db.Store_Profile.Where(o => o.BET.Contains(index.ToString())).ToList();
                for (int i = 0; i < SPRows.Count(); i++)
                {
                    string BETString = SPRows[i].BET;
                    BETString     = BETString.Replace(index.ToString(), ""); // Replace the index with empty
                    BETString     = BETString.Replace(",,", ",");            // Removes instances of blank between delimiters
                    SPRows[i].BET = BETString;                               // Replace old entry
                }

                try
                {
                    db.BUSINESS_EXT.Remove(bexRow);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #4
0
        public static bool UpdateRawItemPrice(RawItemPriceUpdateViewModel RIPViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                RIM_VEM_Lookup RVLRow;
                if (db.RIM_VEM_Lookup.Where(o => o.RIM_VEM_ID.Equals(RIPViewModel.RIM_VEM_ID)).Any())
                {
                    RVLRow = db.RIM_VEM_Lookup.Single(o => o.RIM_VEM_ID.Equals(RIPViewModel.RIM_VEM_ID));
                }
                else
                {
                    RVLRow = new RIM_VEM_Lookup();
                }

                RVLRow.RIM_VEM_ID = RIPViewModel.RIM_VEM_ID;
                RVLRow.RIMRIC     = int.Parse(RIPViewModel.RIMRIC);
                RVLRow.VEMVEN     = int.Parse(RIPViewModel.VEMVEN);
                RVLRow.VEMDS1     = RIPViewModel.VEMDS1.Trim();
                RVLRow.RIMCPR     = double.Parse(RIPViewModel.RIMCPR);
                RVLRow.RIMRID     = db.INVRIMP0.Single(o => o.RIMRIC.ToString().Equals(RIPViewModel.RIMRIC)).RIMRID;
                //RVLRow.RIMPDT = DateTime.Parse(RIPViewModel.RIMPDT);
                //RVLRow.RIMCPN = double.Parse(RIPViewModel.RIMCPN);

                try
                {
                    if (!db.RIM_VEM_Lookup.Where(o => o.RIM_VEM_ID.Equals(RIPViewModel.RIM_VEM_ID)).Any())
                    {
                        db.RIM_VEM_Lookup.Add(RVLRow);
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #5
0
 public static bool LogDateTime(string username)
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         if (db.Accounts.Where(o => o.Username.Trim().Equals(username)).Any())
         {
             Account ac = db.Accounts.SingleOrDefault(o => o.Username.Trim().Equals(username));
             ac.TimeLastLogged = DateTime.Now;
             db.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
コード例 #6
0
        public bool UpdateOwnership(OwnershipViewModel OSPViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                OWNERSHIP ospRow = new OWNERSHIP();

                ospRow.Id     = int.Parse(OSPViewModel.Id);
                ospRow.OWNSHP = OSPViewModel.OWNSHP;
                try
                {
                    if (db.OWNERSHIPs.Where(o => o.Id.ToString().Equals(OSPViewModel.Id)).Any())
                    {
                        var rowToRemove = db.OWNERSHIPs.Single(o => o.Id.ToString().Equals(OSPViewModel.Id));
                        db.OWNERSHIPs.Remove(rowToRemove);
                        db.OWNERSHIPs.Add(ospRow);
                    }
                    else
                    {
                        db.OWNERSHIPs.Add(ospRow);
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #7
0
        public bool UpdateProfitCenter(ProfitCenterViewModel PRCViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                PROFIT_CEN prcRow = new PROFIT_CEN();

                prcRow.Id     = int.Parse(PRCViewModel.Id);
                prcRow.PRFCNT = PRCViewModel.PRFCNT;
                try
                {
                    if (db.PROFIT_CEN.Where(o => o.Id.ToString().Equals(PRCViewModel.Id)).Any())
                    {
                        var rowToRemove = db.PROFIT_CEN.Single(o => o.Id.ToString().Equals(PRCViewModel.Id));
                        db.PROFIT_CEN.Remove(rowToRemove);
                        db.PROFIT_CEN.Add(prcRow);
                    }
                    else
                    {
                        db.PROFIT_CEN.Add(prcRow);
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #8
0
        public bool UpdateLocation(LocationViewModel LCNViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                LOCATION lcnRow = new LOCATION();

                lcnRow.Id     = int.Parse(LCNViewModel.Id);
                lcnRow.LOCATN = LCNViewModel.LOCATN;
                try
                {
                    if (db.LOCATIONs.Where(o => o.Id.ToString().Equals(LCNViewModel.Id)).Any())
                    {
                        var rowToRemove = db.LOCATIONs.Single(o => o.Id.ToString().Equals(LCNViewModel.Id));
                        db.LOCATIONs.Remove(rowToRemove);
                        db.LOCATIONs.Add(lcnRow);
                    }
                    else
                    {
                        db.LOCATIONs.Add(lcnRow);
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #9
0
 public bool UpdateDessertPriceTier(DessertPriceTierViewModel DPTViewModel)
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         Dessert_Price_Tier dptRow = new Dessert_Price_Tier();
         dptRow.Id         = int.Parse(DPTViewModel.Id);
         dptRow.Price_Tier = DPTViewModel.Price_Tier;
         try
         {
             if (db.Dessert_Price_Tier.Where(o => o.Id.ToString().Equals(DPTViewModel.Id)).Any())
             {
                 var rowToRemove = db.Dessert_Price_Tier.Single(o => o.Id.ToString().Equals(DPTViewModel.Id));
                 db.Dessert_Price_Tier.Remove(rowToRemove);
                 db.Dessert_Price_Tier.Add(dptRow);
             }
             else
             {
                 db.Dessert_Price_Tier.Add(dptRow);
             }
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.Source);
             System.Diagnostics.Debug.WriteLine(e.Message);
             System.Diagnostics.Debug.WriteLine(e.StackTrace);
             System.Diagnostics.Debug.WriteLine(e.InnerException);
             Exception f = e.InnerException;
             while (f != null)
             {
                 System.Diagnostics.Debug.WriteLine("INNER:");
                 System.Diagnostics.Debug.WriteLine(f.Message);
                 System.Diagnostics.Debug.WriteLine(f.Source);
                 f = f.InnerException;
             }
             System.Diagnostics.Debug.WriteLine(e.Data);
             return(false);
         }
     }
 }
コード例 #10
0
 public bool UpdateBusinessExtension(BusinessExtensionViewModel BEXViewModel)
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         BUSINESS_EXT bexRow = new BUSINESS_EXT();
         bexRow.ID     = int.Parse(BEXViewModel.ID);
         bexRow.LONGNM = BEXViewModel.LONGNM;
         try
         {
             if (db.BUSINESS_EXT.Where(o => o.ID.ToString().Equals(BEXViewModel.ID)).Any())
             {
                 var rowToRemove = db.BUSINESS_EXT.Single(o => o.ID.ToString().Equals(BEXViewModel.ID));
                 db.BUSINESS_EXT.Remove(rowToRemove);
                 db.BUSINESS_EXT.Add(bexRow);
             }
             else
             {
                 db.BUSINESS_EXT.Add(bexRow);
             }
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.Source);
             System.Diagnostics.Debug.WriteLine(e.Message);
             System.Diagnostics.Debug.WriteLine(e.StackTrace);
             System.Diagnostics.Debug.WriteLine(e.InnerException);
             Exception f = e.InnerException;
             while (f != null)
             {
                 System.Diagnostics.Debug.WriteLine("INNER:");
                 System.Diagnostics.Debug.WriteLine(f.Message);
                 System.Diagnostics.Debug.WriteLine(f.Source);
                 f = f.InnerException;
             }
             System.Diagnostics.Debug.WriteLine(e.Data);
             return(false);
         }
     }
 }
コード例 #11
0
        public bool DeleteMcCafeLevel3PriceTier(McCafeLevel3PriceTierViewModel ML3ViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                McCafe_Level_3_Price_Tier ml3Row;

                if (db.McCafe_Level_3_Price_Tier.Where(o => o.Id.ToString().Equals(ML3ViewModel.Id)).Any())
                {
                    ml3Row = db.McCafe_Level_3_Price_Tier.Single(o => o.Id.ToString().Equals(ML3ViewModel.Id));
                }
                else
                {
                    return(false);
                }
                try
                {
                    db.McCafe_Level_3_Price_Tier.Remove(ml3Row);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #12
0
        public bool DeleteUserAccount(AccountViewModel AViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                Account ARow = new Account();
                if (db.Accounts.Where(o => o.Username.Equals(AViewModel.Username)).Any())
                {
                    ARow = db.Accounts.Single(o => o.Username.Equals(AViewModel.Username));
                }
                else
                {
                    return(false);
                }

                try
                {
                    db.Accounts.Remove(ARow);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #13
0
        public bool DeleteProjectGoldPriceTier(ProjectGoldPriceTierViewModel PGTViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                Project_Gold_Price_Tier pgtRow;

                if (db.Project_Gold_Price_Tier.Where(o => o.Id.ToString().Equals(PGTViewModel.Id)).Any())
                {
                    pgtRow = db.Project_Gold_Price_Tier.Single(o => o.Id.ToString().Equals(PGTViewModel.Id));
                }
                else
                {
                    return(false);
                }
                try
                {
                    db.Project_Gold_Price_Tier.Remove(pgtRow);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #14
0
        public bool Audit(AuditLogViewModel ALViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                Audit_Log alRow = new Audit_Log();
                alRow.Id          = new Random().Next(1, 999999999); // To be changed soon
                alRow.UserId      = ALViewModel.UserId;
                alRow.Date_Time   = DateTime.Parse(ALViewModel.Date_Time);
                alRow.Page        = ALViewModel.Page;
                alRow.ItemId      = ALViewModel.ItemId;
                alRow.Page_Action = ALViewModel.Page_Action;
                alRow.Name        = ALViewModel.Name;

                try
                {
                    db.Audit_Log.Add(alRow);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #15
0
 /*
  * Deletes the specified row given in the ViewModel properties.
  *
  * Returns true if operation is successful.
  * */
 public static bool DeleteVendor(VendorMasterViewModel VMViewModel)
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         try
         {
             if (db.INVVEMP0.Where(o => o.VEMVEN.ToString().Equals(VMViewModel.VEMVEN)).Any())
             {
                 INVVEMP0 rowToDelete = db.INVVEMP0.Single(o => o.VEMVEN.ToString().Equals(VMViewModel.VEMVEN));
                 db.INVVEMP0.Remove(rowToDelete);
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.Source);
             System.Diagnostics.Debug.WriteLine(e.Message);
             System.Diagnostics.Debug.WriteLine(e.StackTrace);
             System.Diagnostics.Debug.WriteLine(e.InnerException);
             Exception f = e.InnerException;
             while (f != null)
             {
                 System.Diagnostics.Debug.WriteLine("INNER:");
                 System.Diagnostics.Debug.WriteLine(f.Message);
                 System.Diagnostics.Debug.WriteLine(f.Source);
                 f = f.InnerException;
             }
             System.Diagnostics.Debug.WriteLine(e.Data);
             return(false);
         }
     }
 }
コード例 #16
0
 public static bool DeleteRawItemPrice(RawItemPriceUpdateViewModel RIPViewModel)
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         try
         {
             if (db.RIM_VEM_Lookup.Where(o => o.RIM_VEM_ID.Equals(RIPViewModel.RIM_VEM_ID)).Any())
             {
                 RIM_VEM_Lookup rowToRemove = db.RIM_VEM_Lookup.FirstOrDefault(o => o.RIM_VEM_ID.Equals(RIPViewModel.RIM_VEM_ID));
                 db.RIM_VEM_Lookup.Remove(rowToRemove);
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.Source);
             System.Diagnostics.Debug.WriteLine(e.Message);
             System.Diagnostics.Debug.WriteLine(e.StackTrace);
             System.Diagnostics.Debug.WriteLine(e.InnerException);
             Exception f = e.InnerException;
             while (f != null)
             {
                 System.Diagnostics.Debug.WriteLine("INNER:");
                 System.Diagnostics.Debug.WriteLine(f.Message);
                 System.Diagnostics.Debug.WriteLine(f.Source);
                 f = f.InnerException;
             }
             System.Diagnostics.Debug.WriteLine(e.Data);
             return(false);
         }
     }
 }
コード例 #17
0
        /*
         * Generates text from database
         */
        public ReportViewModel GeneratePackets(TextGeneratorViewModel TGViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                ReportViewModel report = new ReportViewModel();
                string          key    = GenerateKey();
                report.Message = key;

                for (int i = 0; i < TGViewModel.StoreList.Count(); i++)
                {
                    if (TGViewModel.StoreList[i].Cb || TGViewModel.IncludeAllStores)
                    {
                        // Data creation
                        MemoryStream  ms             = new MemoryStream();
                        StreamWriter  sb             = new StreamWriter(ms);
                        TextGenerator tg             = new TextGenerator();
                        string        Store_No       = TGViewModel.StoreList[i].value;
                        string        Store_Name     = TGViewModel.StoreList[i].text;
                        string        DateAndTimeNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        DateTime      DateFrom       = DateTime.Parse(TGViewModel.DateFrom);
                        DateTime      DateTo         = DateTime.Parse(TGViewModel.DateTo);

                        // Append first line
                        sb.Write("01," + Store_No + "," + Store_Name + "," + DateAndTimeNow + "," + TGViewModel.PromoTitle + "\n");

                        if (TGViewModel.IncludeMIM || TGViewModel.IncludeAll)
                        {
                            List <CSHMIMP0> MIRows = GetMenutems(Store_No, DateFrom, DateTo);
                            foreach (CSHMIMP0 mi in MIRows)
                            {
                                sb.Write(tg.GenerateMenuItemMasterText(mi));
                                mi.STATUS = "0";
                            }
                        }
                        if (TGViewModel.IncludeRIM || TGViewModel.IncludeAll)
                        {
                            List <INVRIMP0> RIRows = GetRawItems(Store_No, DateFrom, DateTo);
                            foreach (INVRIMP0 ri in RIRows)
                            {
                                sb.Write(tg.GenerateRawItemMasterText(ri));
                                ri.STATUS = "0";
                            }
                        }
                        if (TGViewModel.IncludeREC || TGViewModel.IncludeAll)
                        {
                            List <INVRIRP0> RERows = GetRecipes(Store_No, DateFrom, DateTo);
                            foreach (INVRIRP0 re in RERows)
                            {
                                sb.Write(tg.GenerateRecipeText(re));
                                re.STATUS = "0";
                            }
                        }

                        List <CSHVMLP0> VMRows = GetValueMeal(Store_No, DateFrom, DateTo);
                        foreach (CSHVMLP0 vm in VMRows)
                        {
                            sb.Write(tg.GenerateValueMealText(vm));
                            vm.STATUS = "0";
                        }

                        List <CSHPMGP0> PMGRows = GetProductMixGroup(Store_No, DateFrom, DateTo);
                        foreach (CSHPMGP0 pmg in PMGRows)
                        {
                            sb.Write(tg.GenerateProductMixText(pmg));
                            pmg.STATUS = "0";
                        }

                        List <INVMGRP0> MGRows = GetMaterialGroup(Store_No, DateFrom, DateTo);
                        foreach (INVMGRP0 mg in MGRows)
                        {
                            sb.Write(tg.GenerateMaterialGroupText(mg));
                            mg.STATUS = "0";
                        }
                        List <INVUOMP0> UOMRows = GetUnitOfMeasure(Store_No, DateFrom, DateTo);
                        foreach (INVUOMP0 uom in UOMRows)
                        {
                            sb.Write(tg.GenerateInitOfMeasureText(uom));
                            uom.STATUS = "0";
                        }
                        List <INVVEMP0> VERows = GetVendor(Store_No, DateFrom, DateTo);
                        foreach (INVVEMP0 ve in VERows)
                        {
                            sb.Write(tg.GenerateVendorText(ve));
                            ve.STATUS = "0";
                        }
                        // File creation
                        //  *Used for file name
                        string PaddedStore_No = TGViewModel.StoreList[i].value;
                        int    len            = PaddedStore_No.Length;
                        for (int j = 0; j < (5 - len); j++)
                        {
                            PaddedStore_No = "0" + PaddedStore_No;
                        }
                        string filename = "CFM" + PaddedStore_No + "_" + DateTime.Now.ToString("MMddyyyy_HHmm");
                        if (TGViewModel.IncludeAll)
                        {
                            filename += ".ALL";
                        }
                        else
                        {
                            filename += ".PRO";
                        }
                        string path = @"C:/SMS/SMSWEBCFM/";

                        if (!System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.CreateDirectory(path);
                        }

                        FileStream file = new FileStream(path + "e" + filename, FileMode.Create, FileAccess.ReadWrite);
                        ms.WriteTo(file);
                        file.Close();
                        ms.Close();
                        EncryptText(path + "e" + filename, path + filename, key);
                        File.Delete(path + "e" + filename);

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine(e.Source);
                            System.Diagnostics.Debug.WriteLine(e.Message);
                            System.Diagnostics.Debug.WriteLine(e.StackTrace);
                            System.Diagnostics.Debug.WriteLine(e.InnerException);
                            Exception f = e.InnerException;
                            while (f != null)
                            {
                                System.Diagnostics.Debug.WriteLine("INNER:");
                                System.Diagnostics.Debug.WriteLine(f.Message);
                                System.Diagnostics.Debug.WriteLine(f.Source);
                                f = f.InnerException;
                            }
                            System.Diagnostics.Debug.WriteLine(e.Data);
                        }
                    }
                }
                return(report);
            }
        }
コード例 #18
0
        public static ReportViewModel ImportExcel(Stream file, string user)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                ReportViewModel error = new ReportViewModel();
                XLWorkbook      workBook;
                try
                {
                    workBook = new XLWorkbook(file);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    error.Result     = false;
                    error.Message    = "File format not supported";
                    error.ErrorLevel = 3;
                    return(error);
                }
                IXLWorksheet workSheet     = workBook.Worksheet(1);
                var          MIMRowList    = new List <CSHMIMP0>();
                bool         IsFirstRow    = true;
                int          succesfulRows = 0;
                int          blankCounter  = 0;
                IXLRow       FirstRow      = workSheet.Rows().ElementAt(0);
                if (FirstRow == null || FirstRow.CellCount() <= 0)
                {
                    error.Result     = false;
                    error.ErrorLevel = 3;
                    error.Message    = "File has incorrect or unsupported format";
                    return(error);
                }
                int index = 1;
                foreach (IXLRow row in workSheet.Rows())
                {
                    if (row == null)
                    {
                        break;
                    }

                    if (IsFirstRow)
                    {
                        FirstRow   = row;
                        IsFirstRow = false;
                    }
                    else
                    {
                        if (row.Cells() == null || row.CellCount() <= 0)
                        {
                            break;
                        }

                        INVVEMP0 VRow       = new INVVEMP0();
                        int      errorLevel = 0;
                        for (int i = 1; i < row.CellCount(); i++)
                        {
                            System.Diagnostics.Debug.WriteLine("Cell count: " + i);
                            System.Diagnostics.Debug.WriteLine("Cell header: " + FirstRow.Cell(i).Value.ToString().ToUpper());
                            System.Diagnostics.Debug.WriteLine("Cell data: " + row.Cell(i).Value.ToString());
                            System.Diagnostics.Debug.WriteLine("Row: " + index);

                            if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMVEN") ||
                                FirstRow.Cell(i).Value.ToString().ToUpper().Contains("VENDOR NUMBER") ||
                                FirstRow.Cell(i).Value.ToString().ToUpper().Contains("VENDOR #"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMVEN = int.Parse(row.Cell(i).Value.ToString());
                                }
                                else
                                {
                                    error.Message += "Vendor number [" + row.Cell(i).Value.ToString() + "] at {Row " + index + "} not in the correct format. | ";
                                    if (error.ErrorLevel != 3)
                                    {
                                        errorLevel = 2;
                                    }
                                    error.Result = false;
                                    break;
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMDS1") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("DESCRIPTION 1"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMDS1 = row.Cell(i).Value.ToString();
                                }
                                else
                                {
                                    error.Result   = false;
                                    error.Message += "Description 1 [" + row.Cell(i).Value.ToString() + "]  at {Row " + index + "} not in the correct format. | ";
                                    if (error.ErrorLevel != 3)
                                    {
                                        errorLevel = 2;
                                    }
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMDS2") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("DESCRIPTION 2"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMDS2 = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMWSI") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("INTERNATIONAL WSI-NUMBER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMWSI = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMCCD") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("COUNTRY CODE"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMCCD = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMZIP") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("ZIP CODE"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMZIP = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMCTY") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("CITY"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMCTY = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMSTR") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("STREET"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMSTR = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMTEL") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("TELEPHONE NUMBER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMTEL = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMSTN") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("SHORT TELEPHONE NUMBER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMSTN = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMLOC") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("LOCAL VENDOR"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMLOC = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMDAY") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MINIMUM STOCK BUFFER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMDAY = double.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMTID") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("TELEPHONE ID"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMTID = row.Cell(i).Value.ToString();
                                }
                            }


                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMSTA") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("STATUS"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMSTA = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMDAT") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("CREATION/CHANGE DATE"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMDAT = DateTime.Parse(row.Cell(i).Value.ToString());
                                }
                                else
                                {
                                    VRow.VEMDAT = DateTime.Now;
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMUSR") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("USER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMUSR = row.Cell(i).Value.ToString();
                                }
                                else
                                {
                                    VRow.VEMUSR = user.ToUpper().Substring(0, 3);
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMADE") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("AUTO DELIVERY"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMADE = row.Cell(i).Value.ToString();
                                }
                                ;
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("VEMDEL") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("SUPPLY CHAIN VENDOR"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.VEMDEL = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("REGION"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.Region = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("PROVINCE"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.Province = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("CITY"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.City = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("STORE"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    VRow.Store = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value == null ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains(""))
                            {
                                blankCounter++;
                                if (blankCounter > 20)
                                {
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }

                        if (VRow.VEMVEN == 0 || VRow.VEMDS1 == null)
                        {
                            error.Result   = false;
                            error.Message += "{Row " + index + "} has incorrect format | ";
                            errorLevel     = 2;
                            continue;
                        }

                        if (db.INVVEMP0.Where(o => o.VEMVEN == VRow.VEMVEN).Any())
                        {
                            error.Result   = false;
                            error.Message += "Vendor [" + VRow.VEMVEN + "] at {Row " + index + "} is already defined | ";
                            errorLevel     = 2;
                        }

                        if (VRow.VEMLOC != null && !VRow.VEMLOC.Equals("") && !db.LOCATIONs.Where(o => o.Id.ToString().Equals(VRow.VEMLOC)).Any())
                        {
                            error.Result   = false;
                            error.Message += "Location with Id [" + VRow.VEMLOC + "] at {Row " + index + "} not available | ";
                            errorLevel     = 2;
                        }

                        if (VRow.Store != null && !VRow.Store.Equals("") && !db.Store_Profile.Where(o => o.STORE_NO.ToString().Equals(VRow.Store)).Any())
                        {
                            error.Result   = false;
                            error.Message += "Store with Id [" + VRow.VEMLOC + "] at {Row " + index + "} not available | ";
                            errorLevel     = 2;
                        }

                        if (errorLevel >= 2)
                        {
                            error.Message += "{Row " + index + "} not inserted | ";
                        }

                        if (errorLevel < 2)
                        {
                            db.INVVEMP0.Add(VRow);
                            try
                            {
                                db.SaveChanges();
                                // Special case for logging import
                                succesfulRows++;
                                new AuditLogManager().Audit(user, DateTime.Now, "Vendor Master", "Import", VRow.VEMVEN.ToString(), VRow.VEMDS1);
                                System.Diagnostics.Debug.WriteLine(VRow.VEMVEN);
                            }
                            catch (Exception e)
                            {
                                System.Diagnostics.Debug.WriteLine(e.Source);
                                System.Diagnostics.Debug.WriteLine(e.Message);
                                System.Diagnostics.Debug.WriteLine(e.StackTrace);
                                System.Diagnostics.Debug.WriteLine(e.InnerException);
                                Exception f = e.InnerException;
                                while (f != null)
                                {
                                    System.Diagnostics.Debug.WriteLine("INNER:");
                                    System.Diagnostics.Debug.WriteLine(f.Message);
                                    System.Diagnostics.Debug.WriteLine(f.Source);
                                    f = f.InnerException;
                                }
                                System.Diagnostics.Debug.WriteLine(e.Data);
                                error.Result   = false;
                                error.Message += "{Row " + index + "} failed to insert. | \n";
                                errorLevel     = 2;
                            }
                        }
                        error.ErrorLevel = errorLevel;
                        index++;
                    }
                }
                if (succesfulRows <= 0)
                {
                    error.Result     = false;
                    error.Message   += "No rows imported | ";
                    error.ErrorLevel = 3;
                }
                else if (succesfulRows >= index)
                {
                    error.ErrorLevel = 0;
                    error.Result     = true;
                }
                error.Message += "Imported " + index + " rows. ";
                return(error);
            }
        }
コード例 #19
0
        /*
         * Combined Create and Update Menu Item method.
         * Creates a INVVEMP0 instance (which will be a new table row)
         * and instantiates each VMViewModel property to the respective property of the former.
         * Also checks if the given Vendor Number is already in the table,
         * if true, the method performs an update, otherwise, creation.
         *
         * Returns true if the operation is successful.
         * */
        public static bool UpdateVendor(VendorMasterViewModel VMViewModel, string user)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                INVVEMP0 VMRow;
                if (db.INVVEMP0.Where(o => o.VEMVEN.ToString().Equals(VMViewModel.VEMVEN)).Any())
                {
                    VMRow = db.INVVEMP0.Single(o => o.VEMVEN.ToString().Equals(VMViewModel.VEMVEN));
                }

                else
                {
                    VMRow = new INVVEMP0();
                }

                if (VMViewModel.VEMVEN != null)
                {
                    VMRow.VEMVEN = int.Parse(VMViewModel.VEMVEN);
                }
                else
                {
                    return(false);
                }

                if (db.INVVEMP0.Where(o => (!o.VEMVEN.ToString().Equals(VMViewModel.VEMVEN) && o.VEMDS1.Equals(VMViewModel.VEMDS1))).Any())
                {
                    return(false);
                }

                if (VMViewModel.VEMDS1 != null)
                {
                    VMRow.VEMDS1 = VMViewModel.VEMDS1.Trim();     // Trim() makes sure no additional whitespace at the start end end of the string
                }
                else
                {
                    return(false);
                }

                if (VMViewModel.VEMLOC != null)
                {
                    VMRow.VEMLOC = VMViewModel.VEMLOC.Trim();
                }

                if (VMViewModel.Region != null)
                {
                    VMRow.Region = VMViewModel.Region;
                }
                else
                {
                    VMRow.Region = null;
                }

                if (VMViewModel.Province != null)
                {
                    VMRow.Province = VMViewModel.Province;
                }
                else
                {
                    VMRow.Province = null;
                }

                if (VMViewModel.City != null)
                {
                    VMRow.City = VMViewModel.City;
                }
                else
                {
                    VMRow.City = null;
                }

                VMRow.Store = VMViewModel.Store;
                if (VMViewModel.SelectAllCb)
                {
                    VMRow.Store = "ALL";
                }
                if (VMViewModel.SelectExceptCb)
                {
                    VMRow.Store        = "ALL";
                    VMRow.Except_Store = VMViewModel.Store.Trim();
                }
                else
                {
                    VMRow.Except_Store = null;
                }

                VMRow.VEMDAT = DateTime.Now;

                VMRow.VEMUSR = user.Substring(0, 3).ToUpper();

                try
                {    // Perform an update if Vendor number already exists
                    if (db.INVVEMP0.Where(o => o.VEMVEN.ToString().Equals(VMViewModel.VEMVEN)).Any())
                    {
                        VMRow.STATUS = "E";
                    }
                    else
                    {
                        VMRow.STATUS = "A";
                        db.INVVEMP0.Add(VMRow);
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #20
0
 public static bool UpdateSCMRecipe(SCMRecipeViewModel CSMViewModel, string user)
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         if (CSMViewModel.CSMDES == null || CSMViewModel.CSMDES.Equals(""))
         {
             return(false);
         }
         // Existing
         foreach (var v in CSMViewModel.RawItemList)
         {
             // Delete overwritten RIMRIC entry
             if (!v.PreviousRIMRIC.Equals(v.RIMRIC) && db.CSM_Master_Recipe.Where(o => o.CSMDES.ToString().Equals(CSMViewModel.CSMDES)).Any())
             {
                 SCM_Master_Recipe CSMRowToDelete = db.SCM_Master_Recipe.Single(o => o.CSMID.Equals(v.CSMID));
                 db.SCM_Master_Recipe.Remove(CSMRowToDelete);
                 db.SaveChanges();
             }
             SCM_Master_Recipe CSMRow = new SCM_Master_Recipe();
             CSMRow.CSMID  = v.CSMID;
             CSMRow.CSMDES = CSMViewModel.CSMDES;
             CSMRow.RIMRIC = int.Parse(v.RIMRIC);
             if (v.CSMSFQ != null)
             {
                 CSMRow.CSMSFQ = double.Parse(v.CSMSFQ);
             }
             CSMRow.CSMCWC = v.CSMCWC;
             try
             {
                 if (db.SCM_Master_Recipe.Where(o => o.CSMID.Equals(CSMRow.CSMID)).Any())
                 {
                     SCM_Master_Recipe rowToDelete = db.SCM_Master_Recipe.Single(o => o.CSMID.Equals(CSMRow.CSMID));
                     db.SCM_Master_Recipe.Remove(rowToDelete);
                     db.SCM_Master_Recipe.Add(CSMRow);
                 }
                 else
                 {
                     db.SCM_Master_Recipe.Add(CSMRow);
                 }
                 db.SaveChanges();
             }
             catch (Exception e)
             {
                 System.Diagnostics.Debug.WriteLine(e.Source);
                 System.Diagnostics.Debug.WriteLine(e.Message);
                 System.Diagnostics.Debug.WriteLine(e.StackTrace);
                 System.Diagnostics.Debug.WriteLine(e.Data);
                 foreach (var eve in ((DbEntityValidationException)e).EntityValidationErrors)
                 {
                     Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                       eve.Entry.Entity.GetType().Name, eve.Entry.State);
                     foreach (var ve in eve.ValidationErrors)
                     {
                         Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"",
                                           ve.PropertyName,
                                           eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName),
                                           ve.ErrorMessage);
                     }
                 }
                 return(false);
             }
         }
         // New
         if (!CSMViewModel.RIMRIC[0].Equals("") && !CSMViewModel.CSMDES.Equals(""))
         {
             for (int i = 0; i < CSMViewModel.RIMRIC.Count(); i++)
             {
                 string rimric = CSMViewModel.RIMRIC[i];
                 if (db.SCM_Master_Recipe.Where(o => (o.RIMRIC.ToString().Equals(rimric) && o.CSMDES.Equals(CSMViewModel.CSMDES))).Any())
                 {
                     continue;
                 }
                 SCM_Master_Recipe CSMRow = new SCM_Master_Recipe();
                 CSMRow.CSMID  = (new Random().Next(1, 999)).ToString() + CSMViewModel.RIMRIC[i];
                 CSMRow.CSMDES = CSMViewModel.CSMDES;
                 CSMRow.RIMRIC = int.Parse(CSMViewModel.RIMRIC[i]);
                 if (CSMViewModel.CSMSFQ[i] != null && !CSMViewModel.CSMSFQ[i].Equals(""))
                 {
                     CSMRow.CSMSFQ = double.Parse(CSMViewModel.CSMSFQ[i]);
                 }
                 CSMRow.CSMCWC = CSMViewModel.CSMCWC[i];
                 try
                 {
                     if (db.SCM_Master_Recipe.Where(o => o.CSMID.Equals(CSMRow.CSMID)).Any())
                     {
                         SCM_Master_Recipe rowToDelete = db.SCM_Master_Recipe.Single(o => o.CSMID.Equals(CSMRow.CSMID));
                         db.SCM_Master_Recipe.Remove(rowToDelete);
                         db.SCM_Master_Recipe.Add(CSMRow);
                     }
                     else
                     {
                         db.SCM_Master_Recipe.Add(CSMRow);
                     }
                     db.SaveChanges();
                 }
                 catch (Exception e)
                 {
                     System.Diagnostics.Debug.WriteLine(e.Source);
                     System.Diagnostics.Debug.WriteLine(e.Message);
                     System.Diagnostics.Debug.WriteLine(e.StackTrace);
                     System.Diagnostics.Debug.WriteLine(e.InnerException);
                     Exception f = e.InnerException;
                     while (f != null)
                     {
                         System.Diagnostics.Debug.WriteLine("INNER:");
                         System.Diagnostics.Debug.WriteLine(f.Message);
                         System.Diagnostics.Debug.WriteLine(f.Source);
                         f = f.InnerException;
                     }
                     System.Diagnostics.Debug.WriteLine(e.Data);
                     return(false);
                 }
             }
         }
         return(true);
     }
 }
コード例 #21
0
 public bool UpdateValueMeal(ValueMealViewModel VMViewModel, string user)
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         if (VMViewModel.VMLNUM == null || VMViewModel.VMLNUM.Equals(""))
         {
             return(false);
         }
         // Existing
         foreach (var v in VMViewModel.MenuItemList)
         {
             // Delete overwritten MIMMIC entry
             if (!v.PreviousMIMMIC.Equals(v.MIMMIC) && db.CSHVMLP0.Where(o => o.VMLNUM.ToString().Equals(VMViewModel.VMLNUM)).Any())
             {
                 CSHVMLP0 VMRowToDelete = db.CSHVMLP0.Single(o => o.VMLID.Equals(VMViewModel.VMLNUM + v.PreviousMIMMIC));
                 db.CSHVMLP0.Remove(VMRowToDelete);
                 db.SaveChanges();
             }
             // Skip if MIMMIC is null
             if (v.MIMMIC == null || v.MIMMIC.Equals(""))
             {
                 continue;
             }
             CSHVMLP0 VMRow = new CSHVMLP0();
             VMRow.VMLID  = VMViewModel.VMLNUM + v.MIMMIC;
             VMRow.VMLNUM = int.Parse(VMViewModel.VMLNUM);
             VMRow.VMLNAM = VMViewModel.VMLNAM.ToString();
             VMRow.VMLMIC = int.Parse(v.MIMMIC);
             if (v.VMLQUA != null && !v.VMLQUA.Equals(""))
             {
                 VMRow.VMLQUA = int.Parse(v.VMLQUA);
             }
             VMRow.VMLPRI = double.Parse(VMViewModel.VMLPRI);
             VMRow.VMLPRO = double.Parse(VMViewModel.VMLPRO);
             try
             {
                 if (db.CSHVMLP0.Where(o => o.VMLID.Equals(VMRow.VMLID)).Any())
                 {
                     CSHVMLP0 rowToDelete = db.CSHVMLP0.Single(o => o.VMLID.Equals(VMRow.VMLID));
                     db.CSHVMLP0.Remove(rowToDelete);
                     VMRow.STATUS = "E";
                     db.CSHVMLP0.Add(VMRow);
                 }
                 else
                 {
                     VMRow.STATUS = "A";
                     db.CSHVMLP0.Add(VMRow);
                 }
                 db.SaveChanges();
             }
             catch (Exception e)
             {
                 System.Diagnostics.Debug.WriteLine(e.Source);
                 System.Diagnostics.Debug.WriteLine(e.Message);
                 System.Diagnostics.Debug.WriteLine(e.StackTrace);
                 System.Diagnostics.Debug.WriteLine(e.InnerException);
                 Exception f = e.InnerException;
                 while (f != null)
                 {
                     System.Diagnostics.Debug.WriteLine("INNER:");
                     System.Diagnostics.Debug.WriteLine(f.Message);
                     System.Diagnostics.Debug.WriteLine(f.Source);
                     f = f.InnerException;
                 }
                 System.Diagnostics.Debug.WriteLine(e.Data);
                 return(false);
             }
         }
         // New
         if (!VMViewModel.MIMMIC[0].Equals(""))
         {
             for (int i = 0; i < VMViewModel.MIMMIC.Count(); i++)
             {
                 CSHVMLP0 VMRow = new CSHVMLP0();
                 VMRow.VMLID  = VMViewModel.VMLNUM + VMViewModel.MIMMIC[i];
                 VMRow.VMLNUM = int.Parse(VMViewModel.VMLNUM);
                 VMRow.VMLNAM = VMViewModel.VMLNAM.ToString();
                 VMRow.VMLMIC = int.Parse(VMViewModel.MIMMIC[i]);
                 if (VMViewModel.VMLQUA[i] != null && !VMViewModel.VMLQUA[i].Equals(""))
                 {
                     VMRow.VMLQUA = int.Parse(VMViewModel.VMLQUA[i]);
                 }
                 VMRow.VMLPRI = double.Parse(VMViewModel.VMLPRI);
                 VMRow.VMLPRO = double.Parse(VMViewModel.VMLPRO);
                 try
                 {
                     if (db.CSHVMLP0.Where(o => o.VMLID.Equals(VMRow.VMLID)).Any())
                     {
                         CSHVMLP0 rowToDelete = db.CSHVMLP0.Single(o => o.VMLID.Equals(VMRow.VMLID));
                         db.CSHVMLP0.Remove(rowToDelete);
                         VMRow.STATUS = "E";
                         db.CSHVMLP0.Add(VMRow);
                     }
                     else
                     {
                         VMRow.STATUS = "A";
                         db.CSHVMLP0.Add(VMRow);
                     }
                     db.SaveChanges();
                 }
                 catch (Exception e)
                 {
                     System.Diagnostics.Debug.WriteLine(e.Source);
                     System.Diagnostics.Debug.WriteLine(e.Message);
                     System.Diagnostics.Debug.WriteLine(e.StackTrace);
                     System.Diagnostics.Debug.WriteLine(e.InnerException);
                     Exception f = e.InnerException;
                     while (f != null)
                     {
                         System.Diagnostics.Debug.WriteLine("INNER:");
                         System.Diagnostics.Debug.WriteLine(f.Message);
                         System.Diagnostics.Debug.WriteLine(f.Source);
                         f = f.InnerException;
                     }
                     System.Diagnostics.Debug.WriteLine(e.Data);
                     return(false);
                 }
             }
         }
         return(true);
     }
 }
コード例 #22
0
        public static bool UpdateMenuItem(MenuRecipeViewModel MRViewModel, string user)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                if (MRViewModel.RIRMIC == null || MRViewModel.RIRMIC.Equals(""))
                {
                    return(false);
                }
                // Existing row
                foreach (var v in MRViewModel.MenuRecipeList)
                {
                    if (!v.PreviousRIRRIC.Equals(v.RIRRIC))
                    {
                        INVRIRP0 MRRowToDelete = db.INVRIRP0.Single(o => o.RIRRID.Equals(v.RIRRID));
                        db.INVRIRP0.Remove(MRRowToDelete);
                        db.SaveChanges();
                    }
                    if (!db.INVRIMP0.Where(o => o.RIMRIC.ToString().Equals(v.RIRRIC)).Any())
                    {
                        continue;
                    }
                    INVRIRP0 MRRow;
                    if (db.INVRIRP0.Where(o => o.RIRRID.Equals(MRViewModel.RIRMIC + v.RIRRIC)).Any())
                    {
                        MRRow = db.INVRIRP0.Single(o => o.RIRRID.Equals(MRViewModel.RIRMIC + v.RIRRIC));
                    }
                    else
                    {
                        MRRow = new INVRIRP0();
                    }

                    MRRow.RIRRID   = MRViewModel.RIRMIC + v.RIRRIC;
                    MRRow.RIRMIC   = int.Parse(MRViewModel.RIRMIC);
                    MRRow.RIRRIC   = int.Parse(v.RIRRIC);
                    MRRow.RIRVPC   = 0;
                    MRRow.LongName = MRViewModel.MIMLON;
                    if (v.RIRSFQ != null && !v.RIRSFQ.Equals(""))
                    {
                        MRRow.RIRSFQ = double.Parse(v.RIRSFQ);
                    }
                    MRRow.RIRCWC = v.RIRCWC;
                    MRRow.RIRSTA = "0";
                    MRRow.RIRVST = "";
                    MRRow.RIRUSR = user.Substring(0, 3).ToUpper();
                    MRRow.RIRDAT = DateTime.Now;
                    MRRow.RIRFLG = false;
                    // Group
                    var IGRowLookup = db.ITMGRPs.Where(o => o.Item_Code.ToString().Equals(MRViewModel.RIRMIC));
                    IGRowLookup = IGRowLookup.Where(o => o.Item_Type == 4);
                    if (IGRowLookup.Any())
                    {
                        if (MRViewModel.Group == 0)
                        {
                            int val = IGRowLookup.FirstOrDefault().Id;
                            ItemGroupManager.DeleteItem(val);
                        }
                        else
                        {
                            IGRowLookup.FirstOrDefault().Item_Code  = int.Parse(MRViewModel.RIRMIC);
                            IGRowLookup.FirstOrDefault().Item_Name  = MRViewModel.MIMDSC;
                            IGRowLookup.FirstOrDefault().Group_Id   = MRViewModel.Group;
                            IGRowLookup.FirstOrDefault().Group_Name = db.ITMGRPs.FirstOrDefault(o => o.Group_Id == MRViewModel.Group).Group_Name;
                        }
                    }
                    else
                    {
                        if (MRViewModel.Group != 0)
                        {
                            ItemGroupViewModel IGRow = new ItemGroupViewModel();
                            IGRow.GroupName = db.ITMGRPs.FirstOrDefault(o => o.Group_Id == MRViewModel.Group).Group_Name;
                            IGRow.GroupId   = MRViewModel.Group;
                            IGRow.ItemCode  = int.Parse(MRViewModel.RIRMIC);
                            IGRow.ItemName  = MRViewModel.MIMDSC;
                            IGRow.ItemType  = 4;
                            IGRow.GroupType = 4;
                            ItemGroupManager.UpdateGroup(IGRow);
                        }
                    }
                    MRRow.Group = MRViewModel.Group;
                    try
                    {
                        if (db.INVRIRP0.Where(o => o.RIRRID == MRRow.RIRRID).Any())
                        {
                            MRRow.STATUS = "E";
                        }
                        else
                        {
                            MRRow.STATUS = "A";
                            db.INVRIRP0.Add(MRRow);
                        }
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Source);
                        System.Diagnostics.Debug.WriteLine(e.Message);
                        System.Diagnostics.Debug.WriteLine(e.StackTrace);
                        System.Diagnostics.Debug.WriteLine(e.InnerException);
                        Exception f = e.InnerException;
                        while (f != null)
                        {
                            System.Diagnostics.Debug.WriteLine("INNER:");
                            System.Diagnostics.Debug.WriteLine(f.Message);
                            System.Diagnostics.Debug.WriteLine(f.Source);
                            f = f.InnerException;
                        }
                        System.Diagnostics.Debug.WriteLine(e.Data);
                        return(false);
                    }
                }
                // New created row
                for (int i = 0; i < MRViewModel.RIMRID.Count(); i++)
                {
                    if (MRViewModel.RIRRIC[i] == null || MRViewModel.RIRRIC[i].Equals(""))
                    {
                        continue;
                    }
                    INVRIRP0 MRRow = new INVRIRP0();
                    MRRow.RIRRID   = MRViewModel.RIRMIC + MRViewModel.RIRRIC[i];
                    MRRow.RIRMIC   = int.Parse(MRViewModel.RIRMIC);
                    MRRow.RIRRIC   = int.Parse(MRViewModel.RIRRIC[i]);
                    MRRow.RIRVPC   = 0;
                    MRRow.LongName = MRViewModel.MIMLON;
                    if (MRViewModel.RIRSFQ[i] != null && !MRViewModel.RIRSFQ[i].Equals(""))
                    {
                        MRRow.RIRSFQ = double.Parse(MRViewModel.RIRSFQ[i]);
                    }
                    MRRow.RIRCWC = MRViewModel.RIRCWC[i];
                    MRRow.RIRSTA = "0";
                    MRRow.RIRVST = "";
                    MRRow.RIRUSR = user.Substring(0, 3).ToUpper();
                    MRRow.RIRDAT = DateTime.Now;
                    MRRow.RIRFLG = false;
                    // Group
                    var IGRowLookup = db.ITMGRPs.Where(o => o.Item_Code.ToString().Equals(MRViewModel.RIRMIC));
                    IGRowLookup = IGRowLookup.Where(o => o.Item_Type == 4);
                    if (IGRowLookup.Any())
                    {
                        if (MRViewModel.Group == 0)
                        {
                            int val = IGRowLookup.FirstOrDefault().Id;
                            ItemGroupManager.DeleteItem(val);
                        }
                        else
                        {
                            IGRowLookup.FirstOrDefault().Item_Code  = int.Parse(MRViewModel.RIRMIC);
                            IGRowLookup.FirstOrDefault().Item_Name  = MRViewModel.MIMDSC;
                            IGRowLookup.FirstOrDefault().Group_Id   = MRViewModel.Group;
                            IGRowLookup.FirstOrDefault().Group_Name = db.ITMGRPs.FirstOrDefault(o => o.Group_Id == MRViewModel.Group).Group_Name;
                        }
                    }
                    else
                    {
                        if (MRViewModel.Group != 0)
                        {
                            ItemGroupViewModel IGRow = new ItemGroupViewModel();
                            IGRow.GroupName = db.ITMGRPs.FirstOrDefault(o => o.Group_Id == MRViewModel.Group).Group_Name;
                            IGRow.GroupId   = MRViewModel.Group;
                            IGRow.ItemCode  = int.Parse(MRViewModel.RIRMIC);
                            IGRow.ItemName  = MRViewModel.MIMDSC;
                            IGRow.ItemType  = 4;
                            IGRow.GroupType = 4;
                            ItemGroupManager.UpdateGroup(IGRow);
                        }
                    }
                    MRRow.Group = MRViewModel.Group;
                    try
                    {
                        if (db.INVRIRP0.Where(o => o.RIRRID == MRRow.RIRRID).Any())
                        {
                            INVRIRP0 rowToDelete = db.INVRIRP0.Single(o => o.RIRRID == MRRow.RIRRID);
                            db.INVRIRP0.Remove(rowToDelete);
                            MRRow.STATUS = "E";
                            db.INVRIRP0.Add(MRRow);
                        }
                        else
                        {
                            MRRow.STATUS = "A";
                            db.INVRIRP0.Add(MRRow);
                        }
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Source);
                        System.Diagnostics.Debug.WriteLine(e.Message);
                        System.Diagnostics.Debug.WriteLine(e.StackTrace);
                        System.Diagnostics.Debug.WriteLine(e.InnerException);
                        Exception f = e.InnerException;
                        while (f != null)
                        {
                            System.Diagnostics.Debug.WriteLine("INNER:");
                            System.Diagnostics.Debug.WriteLine(f.Message);
                            System.Diagnostics.Debug.WriteLine(f.Source);
                            f = f.InnerException;
                        }
                        System.Diagnostics.Debug.WriteLine(e.Data);
                        return(false);
                    }
                }
                List <INVRIRP0> MRRowList = db.INVRIRP0.Where(o => o.RIRMIC.ToString().Equals(MRViewModel.RIRMIC)).ToList();
                if (MRRowList.Count() == 0)
                {
                    var RIRRow = db.ITMGRPs.Where(o => o.Item_Code.ToString().Equals(MRViewModel.RIRMIC));
                    RIRRow = RIRRow.Where(o => o.Item_Type == 4);
                    if (RIRRow.Any())
                    {
                        db.ITMGRPs.RemoveRange(RIRRow);
                        db.SaveChanges();
                    }
                }
                return(true);
            }
        }
コード例 #23
0
        public static ReportViewModel ImportExcel(Stream file, string user)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                ReportViewModel error = new ReportViewModel();
                XLWorkbook      workBook;
                try
                {
                    workBook = new XLWorkbook(file);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    error.Result     = false;
                    error.Message    = "File format not supported";
                    error.ErrorLevel = 3;
                    return(error);
                }
                IXLWorksheet workSheet     = workBook.Worksheet(1);
                var          MIMRowList    = new List <CSHMIMP0>();
                bool         IsFirstRow    = true;
                int          succesfulRows = 0;
                int          blankCounter  = 0;
                IXLRow       FirstRow      = workSheet.Rows().ElementAt(0);
                if (FirstRow == null || FirstRow.CellCount() <= 0)
                {
                    error.Result     = false;
                    error.ErrorLevel = 3;
                    error.Message    = "File has incorrect or unsupported format";
                    return(error);
                }
                int index = 1;
                foreach (IXLRow row in workSheet.Rows())
                {
                    if (row == null)
                    {
                        break;
                    }

                    if (IsFirstRow)
                    {
                        FirstRow   = row;
                        IsFirstRow = false;
                    }
                    else
                    {
                        if (row.Cells() == null || row.CellCount() <= 0)
                        {
                            break;
                        }

                        Store_Profile SPRow      = new Store_Profile();
                        int           errorLevel = 0;
                        for (int i = 1; i < row.CellCount(); i++)
                        {
                            System.Diagnostics.Debug.WriteLine("Cell count: " + i);
                            System.Diagnostics.Debug.WriteLine("Cell header: " + FirstRow.Cell(i).Value.ToString().ToUpper());
                            System.Diagnostics.Debug.WriteLine("Cell data: " + row.Cell(i).Value.ToString());
                            System.Diagnostics.Debug.WriteLine("Row: " + index);

                            if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("STORE_NO") ||
                                FirstRow.Cell(i).Value.ToString().ToUpper().Contains("STORE NUMBER") ||
                                FirstRow.Cell(i).Value.ToString().ToUpper().Contains("STORE #"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.STORE_NO = int.Parse(row.Cell(i).Value.ToString());
                                }
                                else
                                {
                                    error.Message += "Store number [" + row.Cell(i).Value.ToString() + "] at {Row " + index + "} not in the correct format. | ";
                                    if (error.ErrorLevel != 3)
                                    {
                                        errorLevel = 2;
                                    }
                                    error.Result = false;
                                    break;
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("STORE_NAME") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("STORE NAME"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.STORE_NAME = row.Cell(i).Value.ToString();
                                }
                                else
                                {
                                    error.Result   = false;
                                    error.Message += "Store name [" + row.Cell(i).Value.ToString() + "]  at {Row " + index + "} not in the correct format. | ";
                                    if (error.ErrorLevel != 3)
                                    {
                                        errorLevel = 2;
                                    }
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("OWNERSHIP") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("OWNERSHIP"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.OWNERSHIP = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("PROFIT_CENTER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("PROFIT CENTER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.PROFIT_CENTER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("BREAKFAST_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("BREAKFAST PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.BREAKFAST_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("REGULAR_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("REGULAR PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.REGULAR_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("DC_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("DC PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.DC_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("MDS_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MDS PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.MDS_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("MCCAFE_LEVEL2_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MCCAFE LEVEL 2 PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.MCCAFE_LEVEL_2_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("MCCAFE_LEVEL3_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MCCAFE LEVEL 3 PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.MCCAFE_LEVEL_3_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("MCCAFE_BISTRO_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MCCAFE BISTRO PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.MCCAFE_BISTRO_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("PROJECT_GOLD_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("PROJECT GOLD PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.PROJECT_GOLD_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("BET") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("BUSINESS EXTENSION"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.BET = row.Cell(i).Value.ToString();
                                }
                            }


                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("REGION") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("REGION"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.REGION = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("PROVINCE") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("PROVINCE"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.PROVINCE = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("LOCATION") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("LOCATION"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.LOCATION = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("ADDRESS") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("ADDRESS"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.ADDRESS = row.Cell(i).Value.ToString();
                                }
                                ;
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("CITY") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("CITY"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.CITY = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("FRESH_OR_FROZEN") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("FRESH OR FROZEN"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.FRESH_OR_FROZEN = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("PAPER_OR_PLASTIC") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("PAPER OR PLASTIC"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.PAPER_OR_PLASTIC = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("SOFT_SERVE_OR_VANILLA_POWDER_MIX") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("SOFT SERVE OR VANILLA POWDER MIX"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.SOFT_SERVE_OR_VANILLA_POWDER_MIX = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("SIMPLOT_OR_MCCAIN") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("SIMPLOT OR MCCAIN"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.SIMPLOT_OR_MCCAIN = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("MCCORMICK_OR_GSF") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MCCORMICK OR GSF"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.MCCORMICK_OR_GSF = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("FRESHB_OR_FROZENB") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("FRESH BUNS OR FROZEN BUNS"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.SOFT_SERVE_OR_VANILLA_POWDER_MIX = row.Cell(i).Value.ToString();
                                }
                            }
                            else if (FirstRow.Cell(i).Value == null ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains(""))
                            {
                                blankCounter++;
                                if (blankCounter > 20)
                                {
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }

                        if (SPRow.STORE_NO == 0 || SPRow.STORE_NAME == null)
                        {
                            error.Result   = false;
                            error.Message += "{Row " + index + "} has incorrect format | ";
                            errorLevel     = 2;
                            break;
                        }

                        if (db.Store_Profile.Where(o => o.STORE_NO == SPRow.STORE_NO).Any())
                        {
                            error.Result   = false;
                            error.Message += "Store profile [" + SPRow.STORE_NO + "] at {Row " + index + "} is already defined | ";
                            errorLevel     = 2;
                        }

                        if (SPRow.OWNERSHIP != null && !SPRow.OWNERSHIP.Equals("") && !db.OWNERSHIPs.Where(o => o.Id == SPRow.OWNERSHIP).Any())
                        {
                            error.Result   = false;
                            error.Message += "Ownership with Id [" + SPRow.OWNERSHIP + "] at {Row " + index + "} not available | ";
                            errorLevel     = 2;
                        }

                        if (SPRow.PROFIT_CENTER != null && !SPRow.PROFIT_CENTER.Equals("") && !db.PROFIT_CEN.Where(o => o.Id == SPRow.PROFIT_CENTER).Any())
                        {
                            error.Result   = false;
                            error.Message += "Ownership with Id [" + SPRow.PROFIT_CENTER + "] at {Row " + index + "} not available | ";
                            errorLevel     = 2;
                        }

                        if (SPRow.LOCATION != null && !SPRow.PROFIT_CENTER.Equals("") && !db.LOCATIONs.Where(o => o.Id == SPRow.LOCATION).Any())
                        {
                            error.Result   = false;
                            error.Message += "Location with Id [" + SPRow.LOCATION + "] at {Row " + index + "} not available | ";
                            errorLevel     = 2;
                        }

                        if (errorLevel >= 2)
                        {
                            error.Message += "{Row " + index + "} not inserted | ";
                        }

                        if (errorLevel < 2)
                        {
                            db.Store_Profile.Add(SPRow);
                            try
                            {
                                db.SaveChanges();
                                // Special case for logging import
                                succesfulRows++;
                                new AuditLogManager().Audit(user, DateTime.Now, "Store profile", "Import", SPRow.STORE_NO.ToString(), SPRow.STORE_NAME);
                                System.Diagnostics.Debug.WriteLine(SPRow.STORE_NO);
                            }
                            catch (Exception e)
                            {
                                System.Diagnostics.Debug.WriteLine(e.Source);
                                System.Diagnostics.Debug.WriteLine(e.Message);
                                System.Diagnostics.Debug.WriteLine(e.StackTrace);
                                System.Diagnostics.Debug.WriteLine(e.InnerException);
                                Exception f = e.InnerException;
                                while (f != null)
                                {
                                    System.Diagnostics.Debug.WriteLine("INNER:");
                                    System.Diagnostics.Debug.WriteLine(f.Message);
                                    System.Diagnostics.Debug.WriteLine(f.Source);
                                    f = f.InnerException;
                                }
                                System.Diagnostics.Debug.WriteLine(e.Data);
                                error.Result   = false;
                                error.Message += "{Row " + index + "} failed to insert. | \n";
                                errorLevel     = 2;
                            }
                        }
                        error.ErrorLevel = errorLevel;
                        index++;
                    }
                }
                if (succesfulRows <= 0)
                {
                    error.Result     = false;
                    error.Message   += "No rows imported | ";
                    error.ErrorLevel = 3;
                }
                else if (succesfulRows >= index)
                {
                    error.ErrorLevel = 0;
                    error.Result     = true;
                }
                error.Message += "Imported " + index + " rows. ";
                return(error);
            }
        }
コード例 #24
0
        /*
         * Deletes a row in the `Store Profile` table
         *
         * Returns true if operation is successful.
         */
        public bool DeleteStore(StoreProfileViewModel SPViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                Store_Profile SPRow;
                if (db.Store_Profile.Where(o => o.STORE_NO.ToString().Equals(SPViewModel.STORE_NO)).Any())
                {
                    SPRow = db.Store_Profile.Single(sp => sp.STORE_NO.ToString().Equals(SPViewModel.STORE_NO));

                    // Remove from Menu Items
                    //      Remove from `Store`
                    if (db.CSHMIMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <CSHMIMP0> MIRow = db.CSHMIMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    //      Remove from `Except_Store`
                    if (db.CSHMIMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <CSHMIMP0> MIRow = db.CSHMIMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    // Remove from Raw Items
                    //      Remove from `Store`
                    if (db.INVRIMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <INVRIMP0> MIRow = db.INVRIMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    //      Remove from `Except_Store`
                    if (db.INVRIMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <INVRIMP0> MIRow = db.INVRIMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    // Remove from Vendors
                    //      Remove from `Store`
                    if (db.INVVEMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <INVVEMP0> MIRow = db.INVVEMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    //      Remove from `Except_Store`
                    if (db.INVVEMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <INVVEMP0> MIRow = db.INVVEMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    // Delete Group
                    if (db.ITMGRPs.Where(o => o.Item_Code == SPRow.STORE_NO).Any())
                    {
                        db.ITMGRPs.RemoveRange(db.ITMGRPs.Where(o => o.Item_Code == SPRow.STORE_NO));
                    }
                }
                else
                {
                    return(false);
                }

                try
                {
                    db.Store_Profile.Remove(SPRow);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #25
0
        public static bool UpdateGroup(ItemGroupViewModel IGViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                // Update
                if (IGViewModel.GroupName == null || IGViewModel.GroupName.Equals("") || IGViewModel.GroupType == 0)
                {
                    return(false);
                }

                var IGRowLookup = db.ITMGRPs.Where(o => o.Item_Code == IGViewModel.ItemCode);
                IGRowLookup = IGRowLookup.Where(o => o.Item_Type == IGViewModel.ItemType);
                if (IGRowLookup.Any())
                {
                    return(false);
                }

                ITMGRP IGRow = new ITMGRP();
                IGRow.Id = new Random().Next(1, 999999999);
                // Get new Id if it exist
                for (int i = 0; (i < 10 && db.ITMGRPs.Where(o => o.Id == IGRow.Id).Any()); i++)
                {
                    IGRow.Id = new Random().Next(1, 999999999);
                }
                // If Group is already created
                if (db.ITMGRPs.Where(o => o.Group_Name.Equals(IGViewModel.GroupName)).Any())
                {
                    IGRow.Group_Id   = IGViewModel.GroupId;
                    IGRow.Group_Name = IGViewModel.GroupName;
                    IGRow.Item_Code  = IGViewModel.ItemCode;
                    IGRow.Item_Name  = IGViewModel.ItemName;
                    IGRow.Item_Type  = IGViewModel.ItemType;
                    IGRow.Group_Type = IGViewModel.GroupType;
                    // Add Group to Item table
                    if (IGRow.Item_Type == 1 && db.CSHMIMP0.Where(o => o.MIMMIC == IGViewModel.ItemCode).Any())
                    {
                        db.CSHMIMP0.Single(o => o.MIMMIC == IGViewModel.ItemCode).Group = IGViewModel.GroupId;
                    }
                    else if (IGRow.Item_Type == 2 && db.INVRIMP0.Where(o => o.RIMRIC == IGViewModel.ItemCode).Any())
                    {
                        db.INVRIMP0.Single(o => o.RIMRIC == IGViewModel.ItemCode).Group = IGViewModel.GroupId;
                    }
                    else if (IGRow.Item_Type == 3 && db.Store_Profile.Where(o => o.STORE_NO == IGViewModel.ItemCode).Any())
                    {
                        db.Store_Profile.Single(o => o.STORE_NO == IGViewModel.ItemCode).Group = IGViewModel.GroupId;
                    }
                    else if (IGRow.Item_Type == 4 && db.INVRIRP0.Where(o => o.RIRMIC == IGViewModel.ItemCode).Any())
                    {
                        foreach (var v in db.INVRIRP0.Where(o => o.RIRMIC == IGViewModel.ItemCode))
                        {
                            v.Group = IGViewModel.GroupId;
                        }
                    }
                }
                else
                {
                    IGRow.Group_Id = new Random().Next(1, 999999);
                    // Get new Group_Id if it exist
                    for (int i = 0; (i < 10 && db.ITMGRPs.Where(o => o.Group_Id == IGRow.Group_Id).Any()); i++)
                    {
                        IGRow.Group_Id = new Random().Next(1, 999999);
                    }
                    IGRow.Group_Name = IGViewModel.GroupName;
                    IGRow.Item_Code  = 0;
                    IGRow.Item_Name  = "";
                    IGRow.Item_Type  = IGViewModel.ItemType;
                    IGRow.Group_Type = IGViewModel.GroupType;
                }
                db.ITMGRPs.Add(IGRow);

                // Save DB
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
                return(true);
            }
        }
コード例 #26
0
        /*
         * Combined Create and Update Store profile method.
         * Creates a Store_Profile instance (which will be a new table row)
         * and instantiates each SPViewModel property to the respective property of the former.
         * Also checks if the given Store profile number is already in the table,
         * if true, the method performs an update, otherwise, creation.
         *
         * Returns true if the operation is successful.
         * */
        public bool UpdateStore(StoreProfileViewModel SPViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                Store_Profile SPRow;
                bool          isUpdating = false;
                if (db.Store_Profile.Where(o => o.STORE_NO.ToString().Equals(SPViewModel.STORE_NO)).Any())
                {
                    SPRow      = db.Store_Profile.Single(o => o.STORE_NO.ToString().Equals(SPViewModel.STORE_NO));
                    isUpdating = true;
                }
                else
                {
                    SPRow = new Store_Profile();
                }

                if (SPViewModel.STORE_NO != null && !SPViewModel.STORE_NO.Equals(""))
                {
                    SPRow.STORE_NO = int.Parse(SPViewModel.STORE_NO);
                }
                else
                {
                    return(false);
                }

                if (SPViewModel.STORE_NAME != null && !SPViewModel.STORE_NAME.Equals(""))
                {
                    SPRow.STORE_NAME = SPViewModel.STORE_NAME;
                }
                else
                {
                    return(false);
                }

                if (SPViewModel.OWNERSHIP != null)
                {
                    SPRow.OWNERSHIP = int.Parse(SPViewModel.OWNERSHIP);
                }
                if (SPViewModel.BREAKFAST_PRICE_TIER != null)
                {
                    SPRow.BREAKFAST_PRICE_TIER = int.Parse(SPViewModel.BREAKFAST_PRICE_TIER);
                }
                if (SPViewModel.REGULAR_PRICE_TIER != null)
                {
                    SPRow.REGULAR_PRICE_TIER = int.Parse(SPViewModel.REGULAR_PRICE_TIER);
                }
                if (SPViewModel.DC_PRICE_TIER != null)
                {
                    SPRow.DC_PRICE_TIER = int.Parse(SPViewModel.DC_PRICE_TIER);
                }
                if (SPViewModel.MDS_PRICE_TIER != null)
                {
                    SPRow.MDS_PRICE_TIER = int.Parse(SPViewModel.MDS_PRICE_TIER);
                }
                if (SPViewModel.MCCAFE_LEVEL_2_PRICE_TIER != null)
                {
                    SPRow.MCCAFE_LEVEL_2_PRICE_TIER = int.Parse(SPViewModel.MCCAFE_LEVEL_2_PRICE_TIER);
                }
                if (SPViewModel.MCCAFE_LEVEL_3_PRICE_TIER != null)
                {
                    SPRow.MCCAFE_LEVEL_3_PRICE_TIER = int.Parse(SPViewModel.MCCAFE_LEVEL_3_PRICE_TIER);
                }
                if (SPViewModel.MCCAFE_BISTRO_PRICE_TIER != null)
                {
                    SPRow.MCCAFE_BISTRO_PRICE_TIER = int.Parse(SPViewModel.MCCAFE_BISTRO_PRICE_TIER);
                }
                if (SPViewModel.PROJECT_GOLD_PRICE_TIER != null)
                {
                    SPRow.PROJECT_GOLD_PRICE_TIER = int.Parse(SPViewModel.PROJECT_GOLD_PRICE_TIER);
                }
                if (SPViewModel.BusinessExtList != null)
                {
                    SPRow.BET = SetBusinessExtention(SPViewModel.BET, SPViewModel.BusinessExtList);
                }
                if (SPViewModel.PROFIT_CENTER != null)
                {
                    SPRow.PROFIT_CENTER = int.Parse(SPViewModel.PROFIT_CENTER);
                }
                if (SPViewModel.REGION != null)
                {
                    SPRow.REGION = SPViewModel.REGION;
                }
                if (SPViewModel.PROVINCE != null)
                {
                    SPRow.PROVINCE = SPViewModel.PROVINCE;
                }
                if (SPViewModel.LOCATION != null && !SPViewModel.LOCATION.Equals(""))
                {
                    SPRow.LOCATION = int.Parse(SPViewModel.LOCATION);
                }
                if (SPViewModel.ADDRESS != null)
                {
                    SPRow.ADDRESS = SPViewModel.ADDRESS;
                }
                if (SPViewModel.CITY != null)
                {
                    SPRow.CITY = SPViewModel.CITY;
                }
                if (SPViewModel.FRESH_OR_FROZEN != null)
                {
                    SPRow.FRESH_OR_FROZEN = SPViewModel.FRESH_OR_FROZEN;
                }
                if (SPViewModel.PAPER_OR_PLASTIC != null)
                {
                    SPRow.PAPER_OR_PLASTIC = SPViewModel.PAPER_OR_PLASTIC;
                }
                if (SPViewModel.SOFT_SERVE_OR_VANILLA_POWDER_MIX != null)
                {
                    SPRow.SOFT_SERVE_OR_VANILLA_POWDER_MIX = SPViewModel.SOFT_SERVE_OR_VANILLA_POWDER_MIX;
                }
                if (SPViewModel.SIMPLOT_OR_MCCAIN != null)
                {
                    SPRow.SIMPLOT_OR_MCCAIN = SPViewModel.SIMPLOT_OR_MCCAIN;
                }
                if (SPViewModel.MCCORMICK_OR_GSF != null)
                {
                    SPRow.MCCORMICK_OR_GSF = SPViewModel.MCCORMICK_OR_GSF;
                }
                if (SPViewModel.FRESHB_OR_FROZENB != null)
                {
                    SPRow.FRESHB_OR_FROZENB = SPViewModel.FRESHB_OR_FROZENB;
                }
                SPRow.STATUS = "A";
                // Group
                if (db.ITMGRPs.Where(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Any())
                {
                    if (SPViewModel.Group == 0)
                    {
                        int val = db.ITMGRPs.FirstOrDefault(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Id;
                        ItemGroupManager.DeleteItem(val);
                    }
                    else
                    {
                        db.ITMGRPs.Single(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Item_Code  = int.Parse(SPViewModel.STORE_NO);
                        db.ITMGRPs.Single(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Item_Name  = SPViewModel.STORE_NAME;
                        db.ITMGRPs.Single(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Group_Id   = SPViewModel.Group;
                        db.ITMGRPs.Single(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Group_Name = db.ITMGRPs.FirstOrDefault(o => o.Group_Id == SPViewModel.Group).Group_Name;
                    }
                }
                else
                {
                    if (SPViewModel.Group != 0)
                    {
                        ItemGroupViewModel IGRow = new ItemGroupViewModel();
                        IGRow.GroupName = db.ITMGRPs.FirstOrDefault(o => o.Group_Id == SPViewModel.Group).Group_Name;
                        IGRow.GroupId   = SPViewModel.Group;
                        IGRow.ItemCode  = int.Parse(SPViewModel.STORE_NO);
                        IGRow.ItemName  = SPViewModel.STORE_NAME;
                        IGRow.ItemType  = 3;
                        IGRow.GroupType = 3;
                        ItemGroupManager.UpdateGroup(IGRow);
                    }
                }
                SPRow.Group = SPViewModel.Group;
                try
                {
                    // Check if STORE_NO already exists in the database, perform an update if true
                    if (isUpdating)
                    {
                        SPRow.STATUS = "E";
                    }
                    else
                    {
                        db.Store_Profile.Add(SPRow);
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
コード例 #27
0
        /*
         * Creates a new `Accounts` row and inserts it in the table
         */
        public bool UpdateUserAccount(AccountViewModel account)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                Account accRow = new Account();
                if (account.Username == null || account.Username.Equals(""))
                {
                    return(false);
                }
                if (account.AccountId != null && !account.AccountId.Equals(""))
                {
                    accRow = db.Accounts.Single(o => o.UserId.ToString().Equals(account.AccountId));
                    // Password
                    if (account.Password == null || account.Password.Equals("")) // If password is unchanged
                    {
                        accRow.Password = db.Accounts.Single(o => o.UserId.ToString().Equals(account.AccountId)).Password;
                    }
                    else
                    {
                        string keys = GenerateKeys(15);
                        string pass = keys + EncodePassword(account.Password, keys);
                        accRow.Password = pass;
                    }
                }
                else
                {
                    accRow.UserId = int.Parse(DateTime.Now.ToString("yyMMdd")) + new Random().Next(999) + new Random().Next(999); // To be changed soon
                    // Create new password
                    string keys = GenerateKeys(15);
                    string pass = keys + EncodePassword(account.Password, keys);
                    accRow.Password = pass;
                }
                // Set user name
                accRow.Username = account.Username;
                // Set User access
                accRow.UserAccess = "";
                accRow.UserAccess = new AccountManager().GetUserAccessString(account);
                if (!accRow.UserAccess.Contains("True"))
                {
                    accRow.UserAccess = account.UserAccess;
                }
                if (account.AllExceptUAC)
                {
                    accRow.UserAccess = "True,True,True,True,True,True,True,False,True,True,True,True,True,True,True,True,True,True,True";
                }

                try
                {
                    if (!db.Accounts.Where(o => o.Username.Equals(account.OldUsername)).Any())
                    {
                        db.Accounts.Add(accRow);
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }