Пример #1
0
        public static List <WorkTable> GetWorkInfo(int empid, DateTime date1)
        {
            db = new DbDataContext();
            var LST = (from p in db.WorkTables where p.EmpId == empid && p.WorkDate == date1.Date select p).ToList();

            return(LST);
        }
Пример #2
0
        public List <ViewMenuItem> GetAdminMenu(string sOrgId)
        {
            int                 orgId    = Convert.ToInt32(sOrgId);
            DbDataContext       db       = new DbDataContext("CloudAppWebSite");
            List <ViewMenuItem> MenuList = new List <ViewMenuItem>();
            var                 query    = db.AdminMenus.Where(p => p.ActiveStatus == EActiveStatus.Active && p.OrganizationId == orgId && p.SubMenuId == null).OrderBy(s => s.Order).ToList();

            foreach (var item in query)
            {
                ViewMenuItem mm = new ViewMenuItem();
                mm.Name = item.MenuName;
                mm.Url  = item.MenuUrl;
                //var subQuery = db.AdminMenus.Where(s => s.SubMenuId == item.Id && s.ActiveStatus == EActiveStatus.Active && s.OrganizationId == orgId).ToList();
                if (item.SubMenu != null)
                {
                    mm.SubMenu = new List <ViewMenuItem>();
                    var subQuery = item.SubMenu.Where(s => s.ActiveStatus == EActiveStatus.Active && s.OrganizationId == orgId).OrderBy(s => s.Order).ToList();
                    foreach (var subItem in subQuery)
                    {
                        ViewMenuItem mms = new ViewMenuItem();
                        mms.Name = subItem.MenuName;
                        mms.Url  = subItem.MenuUrl;
                        mm.SubMenu.Add(mms);
                    }
                }
                MenuList.Add(mm);
            }

            return(MenuList);
        }
Пример #3
0
 public void Destroy(TData data)
 {
     Logger.LogDebug("Removing data from the Sql database", "SqlDataStore\\Destroy");
     try
     {
         DateTime start = DateTime.Now;
         try
         {
             Table.DeleteOnSubmit(data);
         }
         catch (InvalidOperationException exception)
         {
             if (exception.Message != "Cannot remove an entity that has not been attached.")
             {
                 throw;
             }
             Table.Attach(data);
             DbDataContext.Refresh(RefreshMode.KeepCurrentValues, data);
             Table.DeleteOnSubmit(data);
         }
         DbDataContext.SubmitChanges();
         DateTime end = DateTime.Now;
         Logger.LogDebug(string.Format("Removing data from the Sql database took {0}.", end - start), "SqlDataStore\\Destroy");
     }
     finally
     {
         Logger.LogDebug("Removing data from the Sql database... Done", "SqlDataStore\\Destroy");
     }
 }
Пример #4
0
 public static Basket GetBasketById(int id)
 {
     using (var db = new DbDataContext()) {
         AbonentBasket b = db.AbonentBaskets.SingleOrDefault(t => t.id == id);
         return(null == b ? null : new Basket());
     }
 }
Пример #5
0
        /// <summary>
        /// Create Db connection to Query attach LazyLoad property
        /// </summary>
        /// <param name="bolLazyLoad">LazyLoad property to Enable or Disable</param>
        /// <returns></returns>
        public static DbDataContext Create(bool bolLazyLoad)
        {
            DbDataContext dbCreate = new DbDataContext(getConnectionString());

            dbCreate.DeferredLoadingEnabled = bolLazyLoad;
            return(dbCreate);
        }
Пример #6
0
 public bool NewClient(Client client)
 {
     DbContext = new DbDataContext();
     DbContext.Clients.InsertOnSubmit(client);
     DbContext.SubmitChanges();
     return true;
 }
Пример #7
0
        public ActionResult FormList(string id, string page)
        {
            int           realId     = Convert.ToInt32(id);
            DbDataContext db         = new DbDataContext();
            CForm         cf         = db.Forms.FirstOrDefault(s => s.Id == realId);
            List <String> headerList = cf.ViewProperties.Split(',').ToList();

            ViewBag.HeaderList = headerList;
            ViewBag.PageHeader = cf.Name;

            List <FormViewListModel> mdList = new List <FormViewListModel>();
            var cfList = db.FormLists.Where(h => h.FormId == realId && h.ActiveStatus == EActiveStatus.Active);

            ViewBag.ListCount   = cfList.Count();
            ViewBag.CurrentPage = page;
            int intPage = Convert.ToInt32(page);

            foreach (var h in cfList.OrderByDescending(g => g.Id).Skip((intPage - 1) * PageSize).Take(PageSize))
            {
                FormViewListModel md = new FormViewListModel();
                md.Parameters = new List <KeyValuePair <string, string> >();

                dynamic d = JObject.Parse(h.JsonData);
                foreach (var item in headerList)
                {
                    md.Parameters.Add(new KeyValuePair <string, string>(item, d[item].ToString()));
                }
                md.FormListId = h.Id;
                mdList.Add(md);
            }
            return(View(mdList));
        }
Пример #8
0
        public ActionResult GetSubMenuItem(string menuId, string Id, string page)
        {
            int orgId = GetOrganizationId();

            if (orgId == 0)
            {
                return(Redirect("/blog/Admin/Home/Index"));
            }
            int userId    = GetUserId();
            int intPage   = Convert.ToInt32(page);
            int intMenuId = Convert.ToInt32(menuId);
            int intId     = Convert.ToInt32(Id);

            List <CMenuItem> menuItemList = new List <CMenuItem>();
            DbDataContext    db           = new DbDataContext("CloudAppWebSite");

            ViewBag.CurrentPage = page;
            List <ViewBreadCrumb> breadCrumbList = new List <ViewBreadCrumb>();

            if (intMenuId != 0)
            {
                menuItemList      = db.MenuItems.Where(item => item.OrganizationId == orgId && item.MenuId == intMenuId && item.ActiveStatus == EActiveStatus.Active).ToList();
                ViewBag.ListCount = db.MenuItems.Where(item => item.OrganizationId == orgId && item.MenuId == intMenuId && item.ActiveStatus == EActiveStatus.Active).Count();
            }
            if (intId != 0)
            {
                menuItemList      = db.MenuItems.Where(item => item.OrganizationId == orgId && item.SubMenuId == intId && item.ActiveStatus == EActiveStatus.Active).ToList();
                ViewBag.ListCount = db.MenuItems.Where(item => item.OrganizationId == orgId && item.SubMenuId == intId && item.ActiveStatus == EActiveStatus.Active).Count();
            }

            ViewBag.BreadCrumbList = GetBreadCrumbList(Id, menuId).OrderBy(item => item.Level).ToList();
            return(View(menuItemList));
        }
 public void GetData()
 {
     using (DbDataContext db = new DbDataContext())
     {
         // DO STUFF
     }
 }
Пример #10
0
 public bool NewEmployee(Employee employee)
 {
     context = new DbDataContext();
     context.Employees.InsertOnSubmit(employee);
     context.SubmitChanges();
     return true;
 }
Пример #11
0
 public void PerformLogicallyAtomicAction()
 {
     using (DbDataContext db = new DbDataContext())
     {
         // DO STUFF
     }
 }
Пример #12
0
 // Go Do It 
 /// <summary>
 /// This Method to add new lowyer
 /// </summary>
 /// <param name="lo">Object</param>
 /// <returns> Return true  or false </returns>
 public bool NewLowyer(Lawyer lo)
 {
     context =new DbDataContext();
     context.Lawyers.InsertOnSubmit(lo);
     context.SubmitChanges();
     return true;
 }
        public IEnumerable <Event1> GetBodyEvents(int bodyID)
        {
            var db = new DbDataContext();

            return
                (db.CelestialObjects.Single(x => x.CelestialObjectID == bodyID).CelestialObjectEvents.Select(x => x.Event1).OrderByDescending(x => x.Time).ToList());
        }
Пример #14
0
 public CheckUrlService(ILogger<UrlController> logger, DbDataContext context, INotifacationService notifacationService, IUserService userService)
 {
     _logger = logger;
     _context = context;
     _notifacationService = notifacationService;
     _userService = userService;
 }
Пример #15
0
        public ActionResult CreateForm(CForm model)
        {
            DbDataContext ctx = new DbDataContext();

            if (model.Id == 0)
            {
                model.OrganizationId = GetOrganizationId();
                model.CreatedUserId  = GetUserId();
                model.CreatedDate    = DateTime.Now;
                model.ActiveStatus   = EActiveStatus.Active;
                ctx.Forms.Add(model);
                ctx.SaveChanges();
                InsertAlert(new ViewAlert {
                    AlertType = EAlertType.Success, Desc = "Form Başarılı Bir Şekilde Eklendi", Title = "Başarılı"
                });
            }
            else
            {
                var forms = ctx.Forms.FirstOrDefault(e => e.Id == model.Id);
                forms.Name           = model.Name;
                forms.Properties     = model.Properties;
                forms.ViewProperties = model.ViewProperties;
                ctx.SaveChanges();
                InsertAlert(new ViewAlert {
                    AlertType = EAlertType.Success, Desc = "Form Başarılı Bir Şekilde Güncellendi", Title = "Başarılı"
                });
            }

            return(Redirect("/blog/Admin/Form/List?Page=1"));
        }
Пример #16
0
        // GET: Employees
        public ActionResult Details(int id)
        {
            var empContext       = new DbDataContext();
            var selectedEmployee = empContext.Employees.Single(emp => emp.IdEmployee == id);

            return(View(selectedEmployee));
        }
        public async Task <IHttpActionResult> UpdateUser(UpdateUserBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string idUser = User.Identity.GetUserId();
            ApplicationDbContext   applicationDbContext = new ApplicationDbContext();
            List <ApplicationUser> applicationUsers     = applicationDbContext.Users.Where(x => x.Id == idUser).ToList();

            if (!applicationUsers.Any())
            {
                return(NotFound());
            }

            DbDataContext   dbDataContext = new DbDataContext();
            List <UserInfo> userInfos     = dbDataContext.UserInfo.Where(x => x.IdAspNetUser == new Guid(idUser)).ToList();

            //Controllo se c'è il record dentro dbData
            if (!userInfos.Any())
            {
                return(NotFound());
            }

            userInfos[0].Nome          = model.Name;
            userInfos[0].Cognome       = model.Surname;
            userInfos[0].DataDiNascita = (model.DataNascita ?? null);
            userInfos[0].FotoProfilo   = (model.ImmagineProfilo ?? null);
            dbDataContext.SaveChanges();

            //TODO: devo modificare anche la Email?

            return(Ok());
        }
Пример #18
0
       // [Test]
        public void HistoryLogUpdate()
        {
            DbDataContext db = new DbDataContext();
            db.HistoryLogs.DeleteAllOnSubmit(db.HistoryLogs);

            const string roleName = "TestRole";
            const string roleNameUpdated = "NewRoleName";

            Role role = new Role();
            role.Name = roleName;
            db.Roles.InsertOnSubmit(role);
            db.SubmitChanges();

            db.Dispose();
            db = new DbDataContext();
            role = db.Roles.Where(r => r.ID == role.ID).First();
            role.Name = roleNameUpdated;
            db.SubmitChanges();

            List<HistoryLog> logs = db.HistoryLogs.Where(h => h.KeyValue == role.ID && h.TypeOfUpdate == "Update").ToList();
            HistoryLog hlName = logs.Where(h => h.FieldName == "Name").FirstOrDefault();
            Assert.IsNotNull(hlName, "No new record in history table with FieldName = 'Name' was found.");
            Assert.AreEqual(hlName.TableName, "Role");
            Assert.AreEqual(hlName.FieldName, "Name");
            Assert.AreEqual(hlName.NewValue, roleNameUpdated);
            Assert.AreEqual(hlName.TypeOfUpdate, "Update");
            Assert.AreEqual(hlName.OldValue, roleName);
            Assert.IsNotNull(hlName.ModifiedDate);

            //db.HistoryLogs.DeleteAllOnSubmit(db.HistoryLogs);
            //db.Roles.DeleteOnSubmit(role);
            //db.SubmitChanges();
        }
Пример #19
0
 public DomainEventsDispatcher(IMediator mediator, ILifetimeScope scope, DbDataContext db, IEventBus eventBus)
 {
     _eventBus      = eventBus;
     this._mediator = mediator;
     this._scope    = scope;
     this._db       = db;
 }
Пример #20
0
        public GenCodesForm()
        {
            InitializeComponent();

            db = new DbDataContext();
            CSS.LoadData(db);
        }
Пример #21
0
        public int GetOrganizationId(HttpRequestBase req)
        {
            DbDataContext dt  = new DbDataContext("CloudAppWebSiteView");
            string        prt = req.Url.Port.ToString();

            return(dt.AddressBindings.Where(a => a.Address.ToLower().Equals(req.Url.Host.ToLower()) && a.Port == prt && a.ActiveStatus == Data.Enum.EActiveStatus.Active).Select(t => t.OrganizationId).FirstOrDefault().Value);
        }
Пример #22
0
        public ActionResult GetSlider(string id, string page)
        {
            DbDataContext db    = new DbDataContext("CloudAppWebSite");
            int           orgId = GetOrganizationId();

            if (orgId == 0)
            {
                return(Redirect("/blog/Admin/Home/Index"));
            }
            int            intId   = Convert.ToInt32(id);
            int            intPage = Convert.ToInt32(page);
            List <CSlider> SliderList;

            SliderList          = db.Sliders.Where(p => p.OrganizationId == orgId && p.ActiveStatus == EActiveStatus.Active).OrderByDescending(item => item.Id).Skip((intPage - 1) * PageSize).Take(PageSize).ToList();
            ViewBag.ListCount   = db.Sliders.Where(p => p.OrganizationId == orgId && p.ActiveStatus == EActiveStatus.Active).Count();
            ViewBag.CurrentPage = page;


            List <ViewBreadCrumb> breadCrumbList = new List <ViewBreadCrumb>();
            ViewBreadCrumb        breadCrumb3    = new ViewBreadCrumb();

            breadCrumb3.Name  = "";
            breadCrumb3.Url   = "";
            breadCrumb3.Level = -1;
            breadCrumbList.Add(breadCrumb3);

            ViewBreadCrumb breadCrumbAll = new ViewBreadCrumb();

            breadCrumbAll.Name  = "Slider";
            breadCrumbAll.Url   = "";
            breadCrumbAll.Level = 999999;
            breadCrumbList.Add(breadCrumbAll);
            ViewBag.BreadCrumbList = breadCrumbList.OrderBy(item => item.Level).ToList();
            return(View(SliderList));
        }
Пример #23
0
    public ActionResult Index()
    {
      using (var context = new DbDataContext())
      {
        var index = (from p in context.ThisMemberPages
                     where p.Name == "Index"
                     select p).SingleOrDefault();

        if (index == null)
        {
          index = new Core.Models.ThisMemberPage
          {
            Content = "Empty so far!",
            Name = "Index"
          };
        }

        return View(new ThisMemberIndexModel
        {
          Content = index.Content
        });

      }

    }
Пример #24
0
        public async Task <ActionResult> Index(string username, string password)
        {
            UtilitiesControl ut = new UtilitiesControl();
            var usr             = await UserManager.FindAsync(username, ut.CalculateMD5Hash(password));

            if (usr != null)
            {
                DbDataContext dt  = new DbDataContext("CloudAppWebSite");
                string        prt = Request.Url.Port.ToString();
                if (dt.AddressBindings.FirstOrDefault(a => a.Address.ToLower().Equals(Request.Url.Host.ToLower()) && a.Port == prt && a.ActiveStatus == Data.Enum.EActiveStatus.Active).OrganizationId == usr.OrganizationId && usr.ActiveStatus == EActiveStatus.Active)
                {
                    var identity = await UserManager.CreateIdentityAsync(usr, DefaultAuthenticationTypes.ApplicationCookie);

                    identity.AddClaim(new Claim("OrganizationId", usr.OrganizationId.ToString()));
                    identity.AddClaim(new System.Security.Claims.Claim("UserId", usr.UserId.ToString()));
                    identity.AddClaim(new System.Security.Claims.Claim("UserName", usr.UserName.ToString()));
                    identity.AddClaim(new System.Security.Claims.Claim("FullName", usr.Name.ToString()));
                    identity.AddClaim(new System.Security.Claims.Claim("ImageUrl", usr.Organization.ImageUrl != null ? usr.Organization.ImageUrl.ToString() : ""));
                    identity.AddClaim(new System.Security.Claims.Claim("Address", String.Join(",", usr.Organization.AdressBindings.Select(f => f.Address).ToList())));
                    identity.AddClaim(new System.Security.Claims.Claim("Port", String.Join(",", usr.Organization.AdressBindings.Select(f => f.Port).ToList())));
                    GetAuthenticationManager().SignIn(identity);
                    return(RedirectToAction("Dashboard", "Home"));
                }
            }
            //SignInManager.PasswordSignIn("33","22",false,false);
            //LoginViewModel Identity = userManager.Find("123", "321");

            return(RedirectToAction("Index", "Home"));
        }
Пример #25
0
        public static List <EmpTable> GetEMpInfo(int PID)
        {
            db = new DbDataContext();
            var LST = (from p in db.EmpTables where p.Id == PID select p).ToList();

            return(LST);
        }
Пример #26
0
        public ActionResult InsertMenu(string id)
        {
            if (!String.IsNullOrEmpty(id))
            {
                List <ViewBreadCrumb> breadCrumbList = new List <ViewBreadCrumb>();
                ViewBreadCrumb        breadCrumb3    = new ViewBreadCrumb();
                breadCrumb3.Name  = "";
                breadCrumb3.Url   = "";
                breadCrumb3.Level = -1;
                breadCrumbList.Add(breadCrumb3);

                ViewBreadCrumb breadCrumbAll = new ViewBreadCrumb();
                breadCrumbAll.Name  = "Menü Düzenle";
                breadCrumbAll.Url   = "";
                breadCrumbAll.Level = 999999;
                breadCrumbList.Add(breadCrumbAll);
                ViewBag.BreadCrumbList = breadCrumbList.OrderBy(item => item.Level).ToList();
                int reelId = Convert.ToInt32(id);
                int orgId  = GetOrganizationId();
                if (orgId == 0)
                {
                    return(Redirect("/blog/Admin/Home/Index"));
                }
                DbDataContext db   = new DbDataContext("CloudAppWebSite");
                CMenu         menu = db.Menus.Where(p => p.Id == reelId && p.ActiveStatus == EActiveStatus.Active && p.OrganizationId == orgId).FirstOrDefault();
                if (menu != null)
                {
                    ViewBag.ItemThemeId = menu.ItemThemeId;
                    return(View(menu));
                }
                else
                {
                    InsertAlert(new ViewAlert {
                        AlertType = EAlertType.Warning, Title = "Uyarı", Desc = "Yetkisiz Giriş"
                    });
                    return(RedirectToAction("Dashboard", "Home"));
                }
            }
            else
            {
                List <ViewBreadCrumb> breadCrumbList = new List <ViewBreadCrumb>();
                ViewBreadCrumb        breadCrumb3    = new ViewBreadCrumb();
                breadCrumb3.Name  = "";
                breadCrumb3.Url   = "";
                breadCrumb3.Level = -1;
                breadCrumbList.Add(breadCrumb3);

                ViewBreadCrumb breadCrumbAll = new ViewBreadCrumb();
                breadCrumbAll.Name  = "Menü Ekle";
                breadCrumbAll.Url   = "";
                breadCrumbAll.Level = 999999;
                breadCrumbList.Add(breadCrumbAll);
                ViewBag.BreadCrumbList = breadCrumbList.OrderBy(item => item.Level).ToList();

                ViewBag.ItemThemeId = 0;
                CMenu menu = new CMenu();
                return(View(menu));
            }
        }
        public Player GetPlayerData(string playerName)
        {
            var db = new DbDataContext();
            var p  = db.Players.SingleOrDefault(x => x.SpringAccount.Name == playerName);

            p.MothershipStructures.Load();
            return(p);
        }
Пример #28
0
 /// <summary>
 /// Получить URL обработчика из БД по префиксу
 /// </summary>
 /// <param name="prefix">Префикс SMS</param>
 /// <returns></returns>
 public static PHP_SMS Get_by_Prefix(string prefix) {
   using (var db = new DbDataContext()) {
     PHP_SM handler = db.PHP_SMs.SingleOrDefault(t => t.prefix == prefix);
     if (handler == null)
       return null;
     return new PHP_SMS {URL = handler.URL, Encoding = Encoding.GetEncoding(handler.Encoding.Trim())};
   }
 }
Пример #29
0
        public static bool addEmp(EmpTable tb)
        {
            db = new DbDataContext();

            db.EmpTables.InsertOnSubmit(tb);
            db.SubmitChanges();
            return(true);
        }
Пример #30
0
        /// <summary>
        ///  This Method Saved New Lowyer 
        /// </summary>
        /// <param name="law"> "أيمن شوف كيف ممكن الكومنت يساعد في حالة التيم وورك"Insert Lowyer Object Table </param>
        /// <returns>return Boolean Value </returns>
        public bool NewLawyer(Lowyer law)
        {
            DbContext = new DbDataContext();
            DbContext.Lowyers.InsertOnSubmit(law);
            DbContext.SubmitChanges();

            return true;
        }
Пример #31
0
        public ActionResult SiteMap(string lang)
        {
            int              orgId  = GetOrganizationId(Request);
            DbDataContext    db     = new DbDataContext("CloudAppWebSiteView");
            SeoUrlController sc     = new SeoUrlController();
            COrganization    cg     = db.Organizations.Where(k => k.OrganizationId == orgId).FirstOrDefault();
            string           adress = cg.AdressBindings.OrderByDescending(s => s.Address.Length).FirstOrDefault().Address;

            if (cg != null)
            {
                Response.Clear();
                Response.ContentType = "text/xml";
                XmlTextWriter xr = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
                xr.WriteStartDocument();
                xr.WriteStartElement("urlset");//urlset etiketi açıyoruz
                xr.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
                xr.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
                xr.WriteAttributeString("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd");
                /* sitemap dosyamızın olmazsa olmazını ekledik. Şeması bu dedik buraya kadar.  */

                //--------1-----------//
                xr.WriteStartElement("url");
                xr.WriteElementString("loc", "http://" + adress);
                xr.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd"));
                xr.WriteElementString("changefreq", "daily");
                xr.WriteElementString("priority", "1");
                xr.WriteEndElement();
                //------2---------//

                foreach (var p in cg.Texts.Where(p => p.ActiveStatus == EActiveStatus.Active && p.Category.ActiveStatus == EActiveStatus.Active))
                {
                    xr.WriteStartElement("url");
                    xr.WriteElementString("loc", "http://" + adress + "/" + sc.GetUrlString(p.Id, EMenuType.Text, orgId, lang));
                    xr.WriteElementString("lastmod", p.CreatedDate != null ? p.CreatedDate.ToString("yyyy-MM-dd") : DateTime.Now.ToString("yyyy-MM-dd"));
                    xr.WriteElementString("priority", "0.5");
                    xr.WriteElementString("changefreq", "monthly");
                    xr.WriteEndElement();
                }

                foreach (var p in cg.Categories.Where(p => p.ActiveStatus == EActiveStatus.Active))
                {
                    xr.WriteStartElement("url");
                    xr.WriteElementString("loc", "http://" + adress + "/" + sc.GetUrlString(p.Id, EMenuType.Category, orgId, lang));
                    xr.WriteElementString("lastmod", p.CreatedDate != null ? p.CreatedDate.ToString("yyyy-MM-dd") : DateTime.Now.ToString("yyyy-MM-dd"));
                    xr.WriteElementString("priority", "0.5");
                    xr.WriteElementString("changefreq", "monthly");
                    xr.WriteEndElement();
                }


                xr.WriteEndDocument();
                //urlset etiketini kapattık
                xr.Flush();
                xr.Close();
                Response.End();
            }
            return(View());
        }
Пример #32
0
        public static List <HoldyTable> GetByIDAndDate(int ID, DateTime dat1, DateTime date2)
        {
            db = new DbDataContext();
            var q = (from i in db.HoldyTables
                     where i.HoldyDate >= dat1 && i.HoldyDate <= date2 && i.EmpID == ID
                     select i).ToList();

            return(q);
        }
Пример #33
0
        //أرشيف البحث
        public static List <LeaveTable> GetByEmpID(int ID)
        {
            db = new DbDataContext();
            var q = (from i in db.LeaveTables
                     where i.EmpId == ID
                     select i).ToList();

            return(q);
        }
Пример #34
0
 public bool CheckFilename(string filename)
 {
     throw new NotImplementedException("Not tested");
     using (var db = new DbDataContext()) {
         MeFile meFile = db.MeFiles.SingleOrDefault(
             t => t.id == id && t.filename == filename);
         return(meFile != null);
     }
 }
Пример #35
0
        public static List <LeaveTable> GetByDate(DateTime dat1, DateTime date2)
        {
            db = new DbDataContext();
            var q = (from i in db.LeaveTables
                     where i.LeaveDate >= dat1 && i.LeaveDate <= date2
                     select i).ToList();

            return(q);
        }
Пример #36
0
 public static Basket GetBasketByHash(string hash)
 {
     using (var db = new DbDataContext()) {
         AbonentBasket b = db.AbonentBaskets.SingleOrDefault(t => t.hash == hash);
         return(null != b ? new Basket {
             id = b.id, idBasketCollection = b.idBasketCollection, msisdn = b.MSISDN
         } : null);
     }
 }
Пример #37
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public virtual void Dispose(bool disposing)

        {
            if (disposing)
            {
                Table = null;
                DbDataContext.Dispose();
                DbDataContext = null;
            }
        }
Пример #38
0
    /// <summary>
    /// Срабатывание таймера
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void timer_Tick(object sender, EventArgs e) {
      LastTime = DateTime.Now;
      UpdateCaption();

      // Получаем данные о работоспособности программы SMPP
      using (var db = new DbDataContext()) {
        // Получить поcледнюю запись о работоспособности сервера
        var tt = db.Logs.Last( t => t.program == "SRV02" );
        // Записать на форму последнее время, когда программа работала
        // Проверяем, сколько прошло времени с последней записи
        // Если времени прошло много => отправляем e-mail
      }
    }
Пример #39
0
 /// <summary>
 /// Конструктор, которому передаётся контекст 
 /// Чтобы этот самый контекст можно было откатить при модульном тестировании
 /// </summary>
 /// <param name="db"></param>
 public SMS_Series_Form(DbDataContext db) {
   this.db = db;
   InitializeComponent();
   SN_Code.SN.Focus();
   SN_Code.SN.SelectedIndexChanged += Update_PropertyGrid;
   SN_Code.Code.TextChanged += Update_PropertyGrid;
   Error.SetError(SN_Code.SN, "Выберите короткий номер");
   map = null;
   SMSDataGrid.CellValueChanged += texts_CellValueChanged;
   SN_Code_Publish.SN.TextChanged += update_PublishButtonState;
   SN_Code_Publish.Code.TextChanged += update_PublishButtonState;
   LoadSMSSeries();
   chooseSellSection.LoadData(db);
 }
Пример #40
0
        public SqlRepositoryBase(string connectionString)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("connectionString");
            }

            if (DataContext != null)
            {
                return;
            }

            IDbConnection connection = new SqlConnection(connectionString);
            DataContext = new DbDataContext(connection);
        }
Пример #41
0
    public List<MePhoneInfo> GetSupportedPhones(int idMe) {
      using (var db = new DbDataContext()) {
        ISingleResult<GetSupportedPhonesResult> result = db.GetSupportedPhones(idMe);
        var res = new List<MePhoneInfo>();

        foreach (GetSupportedPhonesResult item in result) {
          var i = new MePhoneInfo {
                                    filename = item.filename,
                                    idModel = item.idModel,
                                    idVendor = item.idVendor,
                                    ModelName = item.ModelName,
                                    VendorName = item.VendorName
                                  };
          res.Add(i);
        }
        return res;
      }
    }
Пример #42
0
        //[Test]
        public void HistoryLogNewRecord()
        {
            DbDataContext db = new DbDataContext();
            db.HistoryLogs.DeleteAllOnSubmit(db.HistoryLogs);

            const string roleName = "TestRole";
            const int roleColumnsCount = 2;

            Role role = new Role();
            role.Name = roleName;
            db.Roles.InsertOnSubmit(role);
            db.SubmitChanges();

            
            List<HistoryLog> logs = db.HistoryLogs.Where(h => h.KeyValue == role.ID).ToList();

            Assert.Greater(logs.Count, 0, "No record was created in history log table.");
            Assert.AreEqual(logs.Count, roleColumnsCount, string.Format("Number of new records in history log table should be {0}, but is {1}.", roleColumnsCount, logs.Count));

            HistoryLog hlId = logs.Where(h=>h.FieldName == "ID").FirstOrDefault();
            Assert.IsNotNull(hlId, "No new record in history table with FieldName = 'ID' was found.");
            Assert.AreEqual(hlId.TableName, "Role");
            Assert.AreEqual(hlId.FieldName, "ID");
            Assert.AreEqual(hlId.NewValue.ToString(), role.ID.ToString());
            Assert.AreEqual(hlId.TypeOfUpdate, "Insert");
            Assert.AreEqual(hlId.OldValue, null);

            HistoryLog hlName = logs.Where(h => h.FieldName == "Name").FirstOrDefault();
            Assert.IsNotNull(hlName, "No new record in history table with FieldName = 'Name' was found.");
            Assert.AreEqual(hlName.TableName, "Role");
            Assert.AreEqual(hlName.FieldName, "Name");
            Assert.AreEqual(hlName.NewValue, roleName);
            Assert.AreEqual(hlName.TypeOfUpdate, "Insert");
            Assert.AreEqual(hlName.OldValue, null);
            Assert.IsNotNull(hlName.ModifiedDate);

            //db.HistoryLogs.DeleteAllOnSubmit(db.HistoryLogs);
            //db.Roles.DeleteOnSubmit(role);
            //db.SubmitChanges();
        }
Пример #43
0
    /// <summary>
    /// Creates new BasketItem in database
    /// </summary>        
    public BasketItem(int idAbonentBasket, int idMe, SellTypeEnum sellType, decimal price) {
      this.idAbonentBasket = idAbonentBasket;
      this.idMe = idMe;
      this.sellType = sellType;
      this.price = price;

      using (var db = new DbDataContext()) {
        var bi = new Raidb.BasketItem {
                                        idAbonentBaskets = idAbonentBasket,
                                        idMe = idMe,
                                        idSellType = ((int) sellType),
                                        isPurchased = false,
                                        isRetrieved = false,
                                        price = price,
                                        dateModified = DateTime.Now,
                                        datePurchased = DateTime.Now
                                      };
        db.BasketItems.InsertOnSubmit(bi);
        db.SubmitChanges();
        id = bi.id;
      }
    }
Пример #44
0
        public void Allocation()
        {
            DeleteData();


            // Divisions            
            Division division1 = CreateDivision();
            Db.Divisions.InsertOnSubmit(division1);
            Db.SubmitChanges();

            // Distribution Channel            
            DistributionChannel channel1 = CreateDistributionChannel();
            Db.DistributionChannels.InsertOnSubmit(channel1);
            Db.SubmitChanges();

            // Animation Type            
            AnimationType animationType1 = CreateAnimationType(division1, "Promotion");
            AnimationType animationType2 = CreateAnimationType(division1, "Launch");
            Db.AnimationTypes.InsertOnSubmit(animationType1);
            Db.AnimationTypes.InsertOnSubmit(animationType2);
            Db.SubmitChanges();

            // Priorities
            Priority priorityA = CreatePriority(division1, "A");
            Priority priorityB = CreatePriority(division1, "B");
            Priority priorityC = CreatePriority(division1, "C");
            Db.Priorities.InsertOnSubmit(priorityA);
            Db.Priorities.InsertOnSubmit(priorityB);
            Db.Priorities.InsertOnSubmit(priorityC);
            Db.SubmitChanges();

            // Animation            
            Animation animation1 = CreateAnimation(division1, channel1, animationType1);
            Db.Animations.InsertOnSubmit(animation1);
            Db.SubmitChanges();

            // Sales Area           
            SalesArea salesArea = CreateSalesArea(channel1, division1);
            Db.SalesAreas.InsertOnSubmit(salesArea);
            Db.SubmitChanges();

            // Signature
            Signature signature = CreateSignature(division1);
            Db.Signatures.InsertOnSubmit(signature);
            Db.SubmitChanges();

            // Customer Group            
            CustomerGroup group1 = CreateCustomerGroup(salesArea, "Boots", "4545");
            group1.SalesArea = salesArea;        
            CustomerGroup group2 = CreateCustomerGroup(salesArea, "Debenhams", "11232");
            group2.SalesArea = salesArea;
            CustomerGroup group3 = CreateCustomerGroup(salesArea, "John Lewis", "1232");
            group3.SalesArea = salesArea;
            Db.CustomerGroups.InsertOnSubmit(group1);
            Db.CustomerGroups.InsertOnSubmit(group2);
            Db.CustomerGroups.InsertOnSubmit(group3);
            Db.SubmitChanges();

            // Animation Customer Group
            AnimationCustomerGroup animationGroup1 = CreateAnimationCustomerGroup(animation1, group1, division1);
            AnimationCustomerGroup animationGroup2 = CreateAnimationCustomerGroup(animation1, group2, division1);
            AnimationCustomerGroup animationGroup3 = CreateAnimationCustomerGroup(animation1, group3, division1);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup1);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup2);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup3);
            Db.SubmitChanges();
                        

            // Customers            
            Customer customerB1 = CreateCustomer(group1, "Boots 1", "5454", division1);
            Customer customerB2 = CreateCustomer(group1, "Boots 2", "4278", division1);
            Customer customerB3 = CreateCustomer(group1, "Boots 3", "54615", division1);
            Customer customerB1W = CreateCustomer(group1, "Boots Warehouse 1", "54754", division1);
            Customer customerB2W = CreateCustomer(group1, "Boots Warehouse 2", "34278", division1);
            Customer customerB3W = CreateCustomer(group1, "Boots Warehouse 3", "54644515", division1);
            Customer customerD1 = CreateCustomer(group2, "Debenhams 1", "879487", division1);
            Customer customerD2 = CreateCustomer(group2, "Debenhams 2", "65626", division1);
            Customer customerD1W = CreateCustomer(group2, "Debenhams Warehouse 1", "8797487", division1);
            Customer customerD2W = CreateCustomer(group2, "Debenhams Warehouse 2", "656256", division1);
            Customer customerD3 = CreateCustomer(group2, "Debenhams 3", "42718", division1);
            Customer customerJ1 = CreateCustomer(group3, "John Lewis 1", "54165", division1);
            Customer customerJ2 = CreateCustomer(group3, "John Lewis 2", "879817", division1);
            Customer customerJ3 = CreateCustomer(group3, "John Lewis 3", "65606", division1);
            Customer customerJ1W = CreateCustomer(group3, "John Lewis Warehouse 1", "540165", division1);
            Db.Customers.InsertOnSubmit(customerB1);
            Db.Customers.InsertOnSubmit(customerB2);
            Db.Customers.InsertOnSubmit(customerB3);
            Db.Customers.InsertOnSubmit(customerB1W);
            Db.Customers.InsertOnSubmit(customerB2W);
            Db.Customers.InsertOnSubmit(customerB3W);
            Db.Customers.InsertOnSubmit(customerD1);
            Db.Customers.InsertOnSubmit(customerD2);
            Db.Customers.InsertOnSubmit(customerD3);
            Db.Customers.InsertOnSubmit(customerD1W);
            Db.Customers.InsertOnSubmit(customerD2W);
            Db.Customers.InsertOnSubmit(customerJ1);
            Db.Customers.InsertOnSubmit(customerJ2);
            Db.Customers.InsertOnSubmit(customerJ3);
            Db.Customers.InsertOnSubmit(customerJ1W);
            Db.SubmitChanges();

            // All category
            Db.ExecuteCommand("exec [up_insertMissingAllCategory]");
            Db.SubmitChanges();

            // Category ALL
            Category categoryAll = (from p in Db.Categories
                                    where p.Name == "All"
                                    select p).Single();

            // BrandAxes
            BrandAxe brandAxeX = CreateBrandAxe(signature, "BrandAxe X", "123");
            BrandAxe brandAxeY = CreateBrandAxe(signature, "BrandAxe Y", "1123");
            BrandAxe brandAxeZ = CreateBrandAxe(signature, "BrandAxe Z", "1423");           
            Db.BrandAxes.InsertOnSubmit(brandAxeX);
            Db.BrandAxes.InsertOnSubmit(brandAxeY);
            Db.BrandAxes.InsertOnSubmit(brandAxeZ);          
            Db.SubmitChanges();

            // Sales - X
            Sale sale11X = CreateSale(customerB1, brandAxeX, 100);
            Sale sale12X = CreateSale(customerB2, brandAxeX, 100);
            Sale sale13X = CreateSale(customerB3, brandAxeX, 100);
            Sale sale21X = CreateSale(customerD1, brandAxeX, 100);
            Sale sale22X = CreateSale(customerD2, brandAxeX, 100);
            Sale sale23X = CreateSale(customerD3, brandAxeX, 100);
            Sale sale31X = CreateSale(customerJ1, brandAxeX, 100);
            Sale sale32X = CreateSale(customerJ2, brandAxeX, 100);
            Sale sale33X = CreateSale(customerJ3, brandAxeX, 100);
            Db.Sales.InsertOnSubmit(sale11X);
            Db.Sales.InsertOnSubmit(sale12X);
            Db.Sales.InsertOnSubmit(sale13X);
            Db.Sales.InsertOnSubmit(sale21X);
            Db.Sales.InsertOnSubmit(sale22X);
            Db.Sales.InsertOnSubmit(sale23X);
            Db.Sales.InsertOnSubmit(sale31X);
            Db.Sales.InsertOnSubmit(sale32X);
            Db.Sales.InsertOnSubmit(sale33X);
            Db.SubmitChanges();

            // Sales - Y
            Sale sale11Y = CreateSale(customerB1, brandAxeY, 100);
            Sale sale12Y = CreateSale(customerB2, brandAxeY, 100);
            Sale sale13Y = CreateSale(customerB3, brandAxeY, 100);
            Sale sale21Y = CreateSale(customerD1, brandAxeY, 100);
            Sale sale22Y = CreateSale(customerD2, brandAxeY, 100);
            Sale sale23Y = CreateSale(customerD3, brandAxeY, 100);
            Sale sale31Y = CreateSale(customerJ1, brandAxeY, 100);
            Sale sale32Y = CreateSale(customerJ2, brandAxeY, 100);
            Sale sale33Y = CreateSale(customerJ3, brandAxeY, 100);
            Db.Sales.InsertOnSubmit(sale11Y);
            Db.Sales.InsertOnSubmit(sale12Y);
            Db.Sales.InsertOnSubmit(sale13Y);
            Db.Sales.InsertOnSubmit(sale21Y);
            Db.Sales.InsertOnSubmit(sale22Y);
            Db.Sales.InsertOnSubmit(sale23Y);
            Db.Sales.InsertOnSubmit(sale31Y);
            Db.Sales.InsertOnSubmit(sale32Y);
            Db.Sales.InsertOnSubmit(sale33Y);
            Db.SubmitChanges();

            // Sales - Z
            Sale sale11Z = CreateSale(customerB1, brandAxeZ, 100);
            Sale sale12Z = CreateSale(customerB2, brandAxeZ, 100);
            Sale sale13Z = CreateSale(customerB3, brandAxeZ, 100);
            Sale sale21Z = CreateSale(customerD1, brandAxeZ, 100);
            Sale sale22Z = CreateSale(customerD2, brandAxeZ, 100);
            Sale sale23Z = CreateSale(customerD3, brandAxeZ, 100);
            Sale sale31Z = CreateSale(customerJ1, brandAxeZ, 100);
            Sale sale32Z = CreateSale(customerJ2, brandAxeZ, 100);
            Sale sale33Z = CreateSale(customerJ3, brandAxeZ, 100);
            Db.Sales.InsertOnSubmit(sale11Z);
            Db.Sales.InsertOnSubmit(sale12Z);
            Db.Sales.InsertOnSubmit(sale13Z);
            Db.Sales.InsertOnSubmit(sale21Z);
            Db.Sales.InsertOnSubmit(sale22Z);
            Db.Sales.InsertOnSubmit(sale23Z);
            Db.Sales.InsertOnSubmit(sale31Z);
            Db.Sales.InsertOnSubmit(sale32Z);
            Db.Sales.InsertOnSubmit(sale33Z);
            Db.SubmitChanges();

            // Animation Product           

            AnimationProduct animationProduct3 = CreateAnimationProduct(division1, animation1, 5, 50, brandAxeX, signature);
            animationProduct3.Category = categoryAll;
            Db.AnimationProducts.InsertOnSubmit(animationProduct3);
            Db.SubmitChanges();          

        
           

            // Customer Capacity - AnimationProduct3
            CustomerCapacity customerCapacity311 = CreateCustomerCapacity(customerB1, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 1000);
            CustomerCapacity customerCapacity312 = CreateCustomerCapacity(customerB2, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 1000);
            CustomerCapacity customerCapacity313 = CreateCustomerCapacity(customerB3, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 1000);
            CustomerCapacity customerCapacity321 = CreateCustomerCapacity(customerD1, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 1000);
            CustomerCapacity customerCapacity322 = CreateCustomerCapacity(customerD2, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 1000);
            CustomerCapacity customerCapacity323 = CreateCustomerCapacity(customerD3, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 1000);
            CustomerCapacity customerCapacity331 = CreateCustomerCapacity(customerJ1, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 1000);
            CustomerCapacity customerCapacity332 = CreateCustomerCapacity(customerJ2, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 1000);
            CustomerCapacity customerCapacity333 = CreateCustomerCapacity(customerJ3, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 1000);
            CustomerCapacity customerCapacity311W = CreateCustomerCapacity(customerB1W, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 10000);
            CustomerCapacity customerCapacity312W = CreateCustomerCapacity(customerB2W, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 10000);
            CustomerCapacity customerCapacity313W = CreateCustomerCapacity(customerB3W, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 10000);
            CustomerCapacity customerCapacity321W = CreateCustomerCapacity(customerD1W, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 10000);
            CustomerCapacity customerCapacity322W = CreateCustomerCapacity(customerD2W, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 10000);
            CustomerCapacity customerCapacity323W = CreateCustomerCapacity(customerJ1W, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 10000);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity311);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity312);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity313);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity321);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity322);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity323);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity331);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity332);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity333);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity311W);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity312W);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity313W);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity321W);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity322W);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity323W);
            Db.SubmitChanges();

            // Categories
            Category category1 = CreateCategory("Consultant", division1);
            Category category2 = CreateCategory("VIP", division1);
            Category category3 = CreateCategory("Non-Consultant", division1);
            Category category4 = CreateCategory("Flagship", division1);
            Category category5 = CreateCategory("SkinExpert", division1);
            Category category6 = CreateCategory("Warehouse", division1);
            Db.Categories.InsertOnSubmit(category1);
            Db.Categories.InsertOnSubmit(category2);
            Db.Categories.InsertOnSubmit(category3);
            Db.Categories.InsertOnSubmit(category4);
            Db.Categories.InsertOnSubmit(category5);
            Db.Categories.InsertOnSubmit(category6);
            Db.SubmitChanges();

            // CustomerCategorie
            CustomerCategory customerCategory1 = CreateCustomerCategory(customerB1W, category6);
            CustomerCategory customerCategory2 = CreateCustomerCategory(customerB2W, category6);
            CustomerCategory customerCategory3 = CreateCustomerCategory(customerB3W, category6);
            CustomerCategory customerCategory4 = CreateCustomerCategory(customerB1, category1);
            CustomerCategory customerCategory5 = CreateCustomerCategory(customerB1, category2);
            CustomerCategory customerCategory6 = CreateCustomerCategory(customerB2, category3);
            CustomerCategory customerCategory7 = CreateCustomerCategory(customerD1W, category6);
            CustomerCategory customerCategory8 = CreateCustomerCategory(customerD2W, category6);
            CustomerCategory customerCategory9 = CreateCustomerCategory(customerD1, category1);
            CustomerCategory customerCategory10 = CreateCustomerCategory(customerD1, category4);
            CustomerCategory customerCategory11 = CreateCustomerCategory(customerD3, category3);
            CustomerCategory customerCategory12 = CreateCustomerCategory(customerD3, category2);
            CustomerCategory customerCategory13 = CreateCustomerCategory(customerJ2, category5);
            CustomerCategory customerCategory14 = CreateCustomerCategory(customerJ2, category4);
            CustomerCategory customerCategory15 = CreateCustomerCategory(customerJ3, category1);
            Db.SubmitChanges();
          
            // CustomerGroupItemTypes
            CustomerGroupItemType cgit3 = CreateCustomerGroupItemType(group1, animationProduct3.ItemType, customerB3W);

            Db.SubmitChanges();

            // Animation Product Details            
            AnimationProductDetail animationProductDetail1 = (from p in Db.AnimationProductDetails
                                                              where p.AnimationProduct == animationProduct3
                                                              select p).Single();
            animationProductDetail1.AllocationQuantity = 900;

            // Group Allocation
            CustomerGroupAllocation groupAllocation = (from p in Db.CustomerGroupAllocations
                                                       where p.CustomerGroup == group1
                                                       select p).Single();
            groupAllocation.ManualFixedAllocation = 500;

            Db.SubmitChanges();


            Db.ExecuteCommand("exec dbo.uf_allocate_animationID '" + animation1.ID + "'");

            Db = new DbDataContext();
            CustomerAllocation result1 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerB1.ID
                                          select ca).FirstOrDefault();

            Assert.IsNotNull(result1, "Customer allocation for customerB1 does not exists");
            Assert.AreEqual(170, result1.CalculatedAllocation);

            CustomerAllocation result2 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerB2.ID
                                          select ca).FirstOrDefault();

            Assert.IsNotNull(result2, "Customer allocation for customerB1 does not exists");
            Assert.AreEqual(165, result2.CalculatedAllocation);

            CustomerAllocation result3 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerB3.ID
                                          select ca).FirstOrDefault();

            Assert.IsNotNull(result3, "Customer allocation for customerB1 does not exists");
            Assert.AreEqual(165, result3.CalculatedAllocation);

            CustomerAllocation result4 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerD1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result4, "Customer allocation for customerD1 does not exists");
            Assert.AreEqual(70, result4.CalculatedAllocation);

            CustomerAllocation result5 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerD2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result5, "Customer allocation for customerD2 does not exists");
            Assert.AreEqual(70, result5.CalculatedAllocation);

            CustomerAllocation result6 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerD3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result6, "Customer allocation for customerD3 does not exists");
            Assert.AreEqual(65, result6.CalculatedAllocation);

            CustomerAllocation result7 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerJ1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result7, "Customer allocation for customerJ1 does not exists");
            Assert.AreEqual(65, result7.CalculatedAllocation);

            CustomerAllocation result8 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerJ2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result8, "Customer allocation for customerJ2 does not exists");
            Assert.AreEqual(65, result8.CalculatedAllocation);

            CustomerAllocation result9 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerJ3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result9, "Customer allocation for customerJ3 does not exists");
            Assert.AreEqual(65, result9.CalculatedAllocation);
         
        }
Пример #45
0
        public void Allocation()
        {
            DeleteData();

            // Divisions            
            Division division1 = CreateDivision();
            Db.Divisions.InsertOnSubmit(division1);
            Db.SubmitChanges();

            // Distribution Channel            
            DistributionChannel channel1 = CreateDistributionChannel();
            Db.DistributionChannels.InsertOnSubmit(channel1);
            Db.SubmitChanges();

            // Animation Type            
            AnimationType animationType1 = CreateAnimationType(division1);
            Db.AnimationTypes.InsertOnSubmit(animationType1);
            Db.SubmitChanges();

            // Animation            
            Animation animation1 = CreateAnimation(division1, channel1, animationType1);
            Db.Animations.InsertOnSubmit(animation1);
            Db.SubmitChanges();

            // Sales Area           
            SalesArea salesArea = CreateSalesArea(channel1, division1);
            Db.SalesAreas.InsertOnSubmit(salesArea);
            Db.SubmitChanges();

            // Signature
            Signature signature = CreateSignature(division1);

            // Brand Axe
            BrandAxe brandAxe = CreateBrandAxe(signature, "BrandAxe", "BA");

            // Category
            Category category1 = CreateCategory("Category 1", division1);
            Db.Categories.InsertOnSubmit(category1);
            Db.SubmitChanges();

            // ItemType
            ItemType itemType = CreateItemType(division1);
            Db.SubmitChanges();

            // Customer Group            
            CustomerGroup group1 = CreateCustomerGroup(salesArea, "Boots", "4545");
            group1.SalesArea = salesArea;
            CustomerGroup group2 = CreateCustomerGroup(salesArea, "Debenhams", "11232");
            group2.SalesArea = salesArea;
            CustomerGroup group3 = CreateCustomerGroup(salesArea, "John Lewis", "1232");
            group3.SalesArea = salesArea;
            Db.CustomerGroups.InsertOnSubmit(group1);
            Db.CustomerGroups.InsertOnSubmit(group2);
            Db.CustomerGroups.InsertOnSubmit(group3);
            Db.SubmitChanges();

            // Animation Customer Group
            AnimationCustomerGroup animationGroup1 = CreateAnimationCustomerGroup(animation1, group1, division1);
            AnimationCustomerGroup animationGroup2 = CreateAnimationCustomerGroup(animation1, group2, division1);
            AnimationCustomerGroup animationGroup3 = CreateAnimationCustomerGroup(animation1, group3, division1);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup1);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup2);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup3);
            Db.SubmitChanges();


            // Customers            
            Customer customerB1 = CreateCustomer(group1, "Boots 1", "5454", division1, category1);
            Customer customerB2 = CreateCustomer(group1, "Boots 2", "4278", division1, category1);
            Customer customerB3 = CreateCustomer(group1, "Boots 3", "54615", division1, category1);
            Customer customerD1 = CreateCustomer(group2, "Debenhams 1", "879487", division1, category1);
            Customer customerD2 = CreateCustomer(group2, "Debenhams 2", "65626", division1, category1);
            Customer customerD3 = CreateCustomer(group2, "Debenhams 3", "42718", division1, category1);
            Customer customerJ1 = CreateCustomer(group3, "John Lewis 1", "54165", division1, category1);
            Customer customerJ2 = CreateCustomer(group3, "John Lewis 2", "879817", division1, category1);
            Customer customerJ3 = CreateCustomer(group3, "John Lewis 3", "65606", division1, category1);
            Db.SubmitChanges();



            // Customer Capacity
            CustomerCapacity customerCapacity11 = CreateCustomerCapacity(customerB1, animation1.AnimationType, animation1.Priority, itemType, 9999);
            CustomerCapacity customerCapacity12 = CreateCustomerCapacity(customerB2, animation1.AnimationType, animation1.Priority, itemType, 9999);
            CustomerCapacity customerCapacity13 = CreateCustomerCapacity(customerB3, animation1.AnimationType, animation1.Priority, itemType, 9999);
            CustomerCapacity customerCapacity21 = CreateCustomerCapacity(customerD1, animation1.AnimationType, animation1.Priority, itemType, 9999);
            CustomerCapacity customerCapacity22 = CreateCustomerCapacity(customerD2, animation1.AnimationType, animation1.Priority, itemType, 9999);
            CustomerCapacity customerCapacity23 = CreateCustomerCapacity(customerD3, animation1.AnimationType, animation1.Priority, itemType, 9999);
            CustomerCapacity customerCapacity31 = CreateCustomerCapacity(customerJ1, animation1.AnimationType, animation1.Priority, itemType, 9999);
            CustomerCapacity customerCapacity32 = CreateCustomerCapacity(customerJ2, animation1.AnimationType, animation1.Priority, itemType, 9999);
            CustomerCapacity customerCapacity33 = CreateCustomerCapacity(customerJ3, animation1.AnimationType, animation1.Priority, itemType, 9999);
            Db.SubmitChanges();



            // Sales
            Sale sale11 = CreateSale(customerB1, brandAxe, 100);
            Sale sale12 = CreateSale(customerB2, brandAxe, 100);
            Sale sale13 = CreateSale(customerB3, brandAxe, 100);
            Sale sale21 = CreateSale(customerD1, brandAxe, 100);
            Sale sale22 = CreateSale(customerD2, brandAxe, 100);
            Sale sale23 = CreateSale(customerD3, brandAxe, 100);
            Sale sale31 = CreateSale(customerJ1, brandAxe, 100);
            Sale sale32 = CreateSale(customerJ2, brandAxe, 100);
            Sale sale33 = CreateSale(customerJ3, brandAxe, 100);
            Db.SubmitChanges();


            // Animation Product           
            AnimationProduct animationProduct1 = CreateAnimationProduct(division1, animation1, 1, 1, category1, brandAxe, itemType);
            Db.AnimationProducts.InsertOnSubmit(animationProduct1);
            Db.SubmitChanges();


            // update store allocations
            CustomerAllocation allocationB1 = (from p in Db.CustomerAllocations
                                               where p.Customer == customerB1
                                               select p).Single();

            CustomerAllocation allocationB2 = (from p in Db.CustomerAllocations
                                               where p.Customer == customerB2
                                               select p).Single();

            CustomerAllocation allocationB3 = (from p in Db.CustomerAllocations
                                               where p.Customer == customerB3
                                               select p).Single();

            CustomerAllocation allocationD1 = (from p in Db.CustomerAllocations
                                               where p.Customer == customerD1
                                               select p).Single();

            CustomerAllocation allocationD2 = (from p in Db.CustomerAllocations
                                               where p.Customer == customerD2
                                               select p).Single();

            CustomerAllocation allocationD3 = (from p in Db.CustomerAllocations
                                               where p.Customer == customerD3
                                               select p).Single();

            CustomerAllocation allocationJL1 = (from p in Db.CustomerAllocations
                                                where p.Customer == customerJ1
                                                select p).Single();

            CustomerAllocation allocationJL2 = (from p in Db.CustomerAllocations
                                                where p.Customer == customerJ2
                                                select p).Single();

            CustomerAllocation allocationJL3 = (from p in Db.CustomerAllocations
                                                where p.Customer == customerJ3
                                                select p).Single();

            //allocationB1.FixedAllocation = 600;
            allocationB2.RetailUplift = 2;
            allocationB3.RetailUplift = 3;
            allocationD1.RetailUplift = 4;
            allocationD2.RetailUplift = 5;
            allocationD3.RetailUplift = 6;
            allocationJL1.RetailUplift = 7;
            allocationJL2.RetailUplift = 8;
            allocationJL3.RetailUplift = 9;

            Db.SubmitChanges();

            // update allocation quantity
            AnimationProductDetail apd = (from p in Db.AnimationProductDetails
                                          select p).Single();
            apd.AllocationQuantity = 900;
            Db.SubmitChanges();


            Db.ExecuteCommand("exec dbo.uf_allocate_animationID '" + animation1.ID + "'");


            Db = new DbDataContext();



            CustomerAllocation result1 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == apd.ID &&
                                          ca.IDCustomer == customerB1.ID
                                          select ca).FirstOrDefault();

            Assert.IsNotNull(result1, "Customer allocation for customerB1 does not exists");
            Assert.AreEqual(20, result1.CalculatedAllocation);

            CustomerAllocation result2 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == apd.ID &&
                                          ca.IDCustomer == customerB2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result2, "Customer allocation for customerB2 does not exists");
            Assert.AreEqual(40, result2.CalculatedAllocation);

            CustomerAllocation result3 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == apd.ID &&
                                          ca.IDCustomer == customerB3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result3, "Customer allocation for customerB3 does not exists");
            Assert.AreEqual(60, result3.CalculatedAllocation);

            CustomerAllocation result4 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == apd.ID &&
                                          ca.IDCustomer == customerD1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result4, "Customer allocation for customerD1 does not exists");
            Assert.AreEqual(80, result4.CalculatedAllocation);

            CustomerAllocation result5 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == apd.ID &&
                                          ca.IDCustomer == customerD2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result5, "Customer allocation for customerD2 does not exists");
            Assert.AreEqual(100, result5.CalculatedAllocation);

            CustomerAllocation result6 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == apd.ID &&
                                          ca.IDCustomer == customerD3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result6, "Customer allocation for customerD3 does not exists");
            Assert.AreEqual(120, result6.CalculatedAllocation);

            CustomerAllocation result7 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == apd.ID &&
                                          ca.IDCustomer == customerJ1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result7, "Customer allocation for customerJ1 does not exists");
            Assert.AreEqual(140, result7.CalculatedAllocation);

            CustomerAllocation result8 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == apd.ID &&
                                          ca.IDCustomer == customerJ2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result8, "Customer allocation for customerJ2 does not exists");
            Assert.AreEqual(160, result8.CalculatedAllocation);

            CustomerAllocation result9 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == apd.ID &&
                                          ca.IDCustomer == customerJ3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result9, "Customer allocation for customerJ3 does not exists");
            Assert.AreEqual(180, result9.CalculatedAllocation);

            
        }
Пример #46
0
        //
        // GET: /Home/
        public ActionResult Index()
        {
            DbDataContext dt = new DbDataContext();

             //Fetching data from db:
            var voltageValues = dt.Values.Where(v => v.FieldName == "Voltage").OrderBy(v => v.Datetime).ToList<Value>();
            var currentValues = dt.Values.Where(v => v.FieldName == "Current").OrderBy(v => v.Datetime).ToList<Value>();

            Highcharts Chart = new Highcharts("Chart");
            // Initiizing chart
            // Making month and days persian, however it is not accurate at all!
            Chart.SetOptions(new GlobalOptions
            {
                Lang = new DotNet.Highcharts.Helpers.Lang
                {
                    Loading = "در حال بارگذاری",
                    Months = new string[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند" },
                    Weekdays = new string[] { "شنبه", "یک شنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنج شنبه", "جمعه" },
                    ShortMonths = new string[] { "فرور", "اردی", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند" }
                }
            });
            Chart.InitChart(new Chart
                {
                    DefaultSeriesType = ChartTypes.Line,
                    MarginRight = 130,
                    MarginBottom = 55,
                    ClassName = "chart",
                    ZoomType = ZoomTypes.X
                })
            .SetTitle(new Title
                {
                    Text = "نمودار تغییرات داده ها "
                })
            .SetSubtitle(new Subtitle
                {
                    Text = "نمونه استفاده نمودار",
                    X = -20
                })
            .SetXAxis(new XAxis
                {
                    Type = AxisTypes.Datetime,
                    Title = new XAxisTitle
                    {
                        Text = "بازه زمانی از ... تا..."
                    },
                    MinorTickInterval = 3600 * 1000,
                    TickLength = 1,
                    MinRange = 3600 * 1000,
                    MinTickInterval = 3600 * 1000,
                    GridLineWidth = 1,
                    Labels = new XAxisLabels
                    {
                        Align = HorizontalAligns.Right,
                        Rotation = -30,
                    },
                    DateTimeLabelFormats = new DateTimeLabel
                    {
                        Second = "%H:%M:%S",
                        Minute = "%H:%M",
                        Hour = "%H:%M",
                        Day = "%e %b",
                        Week = "%e %b",
                        Month = "%b",
                        Year = "%Y",
                    },
                    ShowEmpty = false,

                })
                .SetLegend(new Legend
                {
                    Layout = Layouts.Vertical,
                    Align = HorizontalAligns.Left,
                    X = 20,
                    VerticalAlign = VerticalAligns.Top,
                    Y = 80,
                    BackgroundColor = new BackColorOrGradient(System.Drawing.ColorTranslator.FromHtml("#FFFFFF"))
                });

            YAxis[] yAxis = new YAxis[2];
            yAxis[0] = (new YAxis
            {
                Title = new YAxisTitle
                {
                    Text = string.Format("{0} ({1})", "Voltage", "V"),

                },
                Labels = new YAxisLabels
                {
                    //Align = HorizontalAligns.Right,
                    Formatter = "function() { return this.value; }",
                },
                Opposite = true,
                GridLineWidth = 0
            });
            yAxis[1] = (new YAxis
            {
                Title = new YAxisTitle
                {
                    Text = string.Format("{0} ({1})", "Current", "A"),

                },
                Labels = new YAxisLabels
                {
                    //Align = HorizontalAligns.Left,
                    Formatter = "function() { return this.value; }",
                },
                Opposite = false,
                GridLineWidth = 1
            });

            Chart.SetYAxis(yAxis);

            Series[] seriesOfData = new Series[2];

            object[,] x1 = new object[voltageValues.Count(), 2];
            for (int i = 0; i < voltageValues.Count(); i++)
            {

                x1[i, 0] = PersianDateTime.ParseFromDateTime(voltageValues[i].Datetime).ToString("Date.parse('MM/dd/yyyy HH:mm:ss')");
                x1[i, 1] = voltageValues[i].Value1;
            }

            DotNet.Highcharts.Helpers.Data data1 = new DotNet.Highcharts.Helpers.Data(x1);
            Series series1 = new Series
            {
                Name = "Voltage",
                Data = data1,
                Type = ChartTypes.Line,
            };
            series1.YAxis = "0";
            seriesOfData[0] = series1;

            object[,] x2 = new object[currentValues.Count(), 2];
            for (int i = 0; i < voltageValues.Count(); i++)
            {
                x2[i, 0] = PersianDateTime.ParseFromDateTime(voltageValues[i].Datetime).ToString("Date.parse('MM/dd/yyyy HH:mm:ss')");
                x2[i, 1] = currentValues[i].Value1;
            }
            DotNet.Highcharts.Helpers.Data data2 = new DotNet.Highcharts.Helpers.Data(x2);
            Series series2 = new Series
            {
                Name = "Current",
                Data = data2,
                Type = ChartTypes.Spline,
            };
            series1.YAxis = "1";
            seriesOfData[1] = series2;

            Chart.SetSeries(seriesOfData);
            ViewBag.Chart = Chart;

            return View();
        }
Пример #47
0
        public void Allocation()
        {
            DeleteData();


            // Divisions            
            Division division1 = CreateDivision();
            Db.Divisions.InsertOnSubmit(division1);
            Db.SubmitChanges();

            // Signature
            Signature signature = CreateSignature(division1);
            Signature signature2 = CreateSignature(division1);
            Db.Signatures.InsertOnSubmit(signature);
            Db.Signatures.InsertOnSubmit(signature2);
            Db.SubmitChanges();

            // Distribution Channel            
            DistributionChannel channel1 = CreateDistributionChannel();
            Db.DistributionChannels.InsertOnSubmit(channel1);
            Db.SubmitChanges();

            // Animation Type            
            AnimationType animationType1 = CreateAnimationType(division1, "Promotion");
            AnimationType animationType2 = CreateAnimationType(division1, "Launch");
            Db.AnimationTypes.InsertOnSubmit(animationType1);
            Db.AnimationTypes.InsertOnSubmit(animationType2);
            Db.SubmitChanges();

            // Priorities
            Priority priorityA = CreatePriority(division1, "A");
            Priority priorityB = CreatePriority(division1, "B");
            Priority priorityC = CreatePriority(division1, "C");
            Db.Priorities.InsertOnSubmit(priorityA);
            Db.Priorities.InsertOnSubmit(priorityB);
            Db.Priorities.InsertOnSubmit(priorityC);
            Db.SubmitChanges();

            // Sales Area           
            SalesArea salesArea = CreateSalesArea(channel1, division1);
            Db.SalesAreas.InsertOnSubmit(salesArea);
            Db.SubmitChanges();

            // Customer Group            
            CustomerGroup group1 = CreateCustomerGroup(salesArea, "Boots", "4545");
            group1.SalesArea = salesArea;
            CustomerGroup group2 = CreateCustomerGroup(salesArea, "Debenhams", "11232");
            group2.SalesArea = salesArea;
            CustomerGroup group3 = CreateCustomerGroup(salesArea, "John Lewis", "1232");
            group3.SalesArea = salesArea;
            Db.CustomerGroups.InsertOnSubmit(group1);
            Db.CustomerGroups.InsertOnSubmit(group2);
            Db.CustomerGroups.InsertOnSubmit(group3);
            Db.SubmitChanges();

            // Categories
            Category category1 = CreateCategory("Consultant", division1);
            Category category2 = CreateCategory("VIP", division1);
            Category category3 = CreateCategory("Non-Consultant", division1);
            Category category4 = CreateCategory("Flagship", division1);
            Category category5 = CreateCategory("SkinExpert", division1);
            Db.Categories.InsertOnSubmit(category1);
            Db.Categories.InsertOnSubmit(category2);
            Db.Categories.InsertOnSubmit(category3);
            Db.Categories.InsertOnSubmit(category4);
            Db.Categories.InsertOnSubmit(category5);
            Db.SubmitChanges();

            // Customers            
            Customer customerB1 = CreateCustomer(group1, "Boots 1", "5454", division1);
            Customer customerB2 = CreateCustomer(group1, "Boots 2", "4278", division1);
            Customer customerB3 = CreateCustomer(group1, "Boots 3", "54615", division1);
            Customer customerD1 = CreateCustomer(group2, "Debenhams 1", "879487", division1);
            Customer customerD2 = CreateCustomer(group2, "Debenhams 2", "65626", division1);
            Customer customerD3 = CreateCustomer(group2, "Debenhams 3", "42718", division1);
            Customer customerJ1 = CreateCustomer(group3, "John Lewis 1", "54165", division1);
            Customer customerJ2 = CreateCustomer(group3, "John Lewis 2", "879817", division1);
            Customer customerJ3 = CreateCustomer(group3, "John Lewis 3", "65606", division1);
            Db.Customers.InsertOnSubmit(customerB1);
            Db.Customers.InsertOnSubmit(customerB2);
            Db.Customers.InsertOnSubmit(customerB3);
            Db.Customers.InsertOnSubmit(customerD1);
            Db.Customers.InsertOnSubmit(customerD2);
            Db.Customers.InsertOnSubmit(customerD3);
            Db.Customers.InsertOnSubmit(customerJ1);
            Db.Customers.InsertOnSubmit(customerJ2);
            Db.Customers.InsertOnSubmit(customerJ3);
            Db.SubmitChanges();

            // CustomerCategorie
            CustomerCategory customerCategory1 = CreateCustomerCategory(customerB1, category1);
            CustomerCategory customerCategory2 = CreateCustomerCategory(customerB1, category2);
            CustomerCategory customerCategory3 = CreateCustomerCategory(customerB2, category3);
            CustomerCategory customerCategory4 = CreateCustomerCategory(customerD1, category1);
            CustomerCategory customerCategory5 = CreateCustomerCategory(customerD1, category4);
            CustomerCategory customerCategory6 = CreateCustomerCategory(customerD3, category3);
            CustomerCategory customerCategory7 = CreateCustomerCategory(customerD3, category2);
            CustomerCategory customerCategory8 = CreateCustomerCategory(customerJ2, category4);
            CustomerCategory customerCategory9 = CreateCustomerCategory(customerJ2, category5);
            CustomerCategory customerCategory10 = CreateCustomerCategory(customerJ3, category1);
            Db.SubmitChanges();

            // All category
            Db.ExecuteCommand("exec [up_insertMissingAllCategory]");
            Db.SubmitChanges();

            // Category ALL
            Category categoryAll = (from p in Db.Categories
                                    where p.Name == "All"
                                    select p).Single();

            // BrandAxes
            BrandAxe brandAxeX = CreateBrandAxe(signature, "BrandAxe X", "123");
            BrandAxe brandAxeY = CreateBrandAxe(signature, "BrandAxe Y", "1123");
            BrandAxe brandAxeZ = CreateBrandAxe(signature, "BrandAxe Z", "1423");
            BrandAxe brandAxeQ = CreateBrandAxe(signature2, "Brand Axe Q", "456");
            Db.BrandAxes.InsertOnSubmit(brandAxeX);
            Db.BrandAxes.InsertOnSubmit(brandAxeY);
            Db.BrandAxes.InsertOnSubmit(brandAxeZ);
            Db.BrandAxes.InsertOnSubmit(brandAxeQ);
            Db.SubmitChanges();

            // Sales - X
            Sale sale11X = CreateSale(customerB1, brandAxeX, 100);
            Sale sale12X = CreateSale(customerB2, brandAxeX, 300);
            Sale sale13X = CreateSale(customerB3, brandAxeX, 200);
            Sale sale21X = CreateSale(customerD1, brandAxeX, 200);
            Sale sale22X = CreateSale(customerD2, brandAxeX, 600);
            Sale sale23X = CreateSale(customerD3, brandAxeX, 400);
            Sale sale31X = CreateSale(customerJ1, brandAxeX, 150);
            Sale sale32X = CreateSale(customerJ2, brandAxeX, 250);
            Sale sale33X = CreateSale(customerJ3, brandAxeX, 350);
            Db.Sales.InsertOnSubmit(sale11X);
            Db.Sales.InsertOnSubmit(sale12X);
            Db.Sales.InsertOnSubmit(sale13X);
            Db.Sales.InsertOnSubmit(sale21X);
            Db.Sales.InsertOnSubmit(sale22X);
            Db.Sales.InsertOnSubmit(sale23X);
            Db.Sales.InsertOnSubmit(sale31X);
            Db.Sales.InsertOnSubmit(sale32X);
            Db.Sales.InsertOnSubmit(sale33X);
            Db.SubmitChanges();

            // Sales - Y
            Sale sale11Y = CreateSale(customerB1, brandAxeY, 200);
            Sale sale12Y = CreateSale(customerB2, brandAxeY, 100);
            Sale sale13Y = CreateSale(customerB3, brandAxeY, 300);
            Sale sale21Y = CreateSale(customerD1, brandAxeY, 200);
            Sale sale22Y = CreateSale(customerD2, brandAxeY, 400);
            Sale sale23Y = CreateSale(customerD3, brandAxeY, 600);
            Sale sale31Y = CreateSale(customerJ1, brandAxeY, 250);
            Sale sale32Y = CreateSale(customerJ2, brandAxeY, 0);
            Sale sale33Y = CreateSale(customerJ3, brandAxeY, 150);
            Db.Sales.InsertOnSubmit(sale11Y);
            Db.Sales.InsertOnSubmit(sale12Y);
            Db.Sales.InsertOnSubmit(sale13Y);
            Db.Sales.InsertOnSubmit(sale21Y);
            Db.Sales.InsertOnSubmit(sale22Y);
            Db.Sales.InsertOnSubmit(sale23Y);
            Db.Sales.InsertOnSubmit(sale31Y);
            Db.Sales.InsertOnSubmit(sale32Y);
            Db.Sales.InsertOnSubmit(sale33Y);
            Db.SubmitChanges();

            // Sales - Z
            Sale sale11Z = CreateSale(customerB1, brandAxeZ, 300);
            Sale sale12Z = CreateSale(customerB2, brandAxeZ, 200);
            Sale sale13Z = CreateSale(customerB3, brandAxeZ, 100);
            Sale sale21Z = CreateSale(customerD1, brandAxeZ, 600);
            Sale sale22Z = CreateSale(customerD2, brandAxeZ, 0);
            Sale sale23Z = CreateSale(customerD3, brandAxeZ, 0);
            Sale sale31Z = CreateSale(customerJ1, brandAxeZ, 0);
            Sale sale32Z = CreateSale(customerJ2, brandAxeZ, 250);
            Sale sale33Z = CreateSale(customerJ3, brandAxeZ, 150);
            Db.Sales.InsertOnSubmit(sale11Z);
            Db.Sales.InsertOnSubmit(sale12Z);
            Db.Sales.InsertOnSubmit(sale13Z);
            Db.Sales.InsertOnSubmit(sale21Z);
            Db.Sales.InsertOnSubmit(sale22Z);
            Db.Sales.InsertOnSubmit(sale23Z);
            Db.Sales.InsertOnSubmit(sale31Z);
            Db.Sales.InsertOnSubmit(sale32Z);
            Db.Sales.InsertOnSubmit(sale33Z);
            Db.SubmitChanges();

            // Sales Q
            Sale sale11Q = CreateSale(customerB1, brandAxeQ, 100);
            Sale sale12Q = CreateSale(customerB2, brandAxeQ, 500);
            Sale sale13Q = CreateSale(customerB3, brandAxeQ, 1000);
            Sale sale21Q = CreateSale(customerD1, brandAxeQ, 300);
            Sale sale22Q = CreateSale(customerD2, brandAxeQ, 700);
            Sale sale23Q = CreateSale(customerD3, brandAxeQ, 0);
            Sale sale31Q = CreateSale(customerJ1, brandAxeQ, 0);
            Sale sale32Q = CreateSale(customerJ2, brandAxeQ, 0);
            Sale sale33Q = CreateSale(customerJ3, brandAxeQ, 0);
            Db.Sales.InsertOnSubmit(sale11Q);
            Db.Sales.InsertOnSubmit(sale12Q);
            Db.Sales.InsertOnSubmit(sale13Q);
            Db.Sales.InsertOnSubmit(sale21Q);
            Db.Sales.InsertOnSubmit(sale22Q);
            Db.Sales.InsertOnSubmit(sale23Q);
            Db.Sales.InsertOnSubmit(sale31Q);
            Db.Sales.InsertOnSubmit(sale32Q);
            Db.Sales.InsertOnSubmit(sale33Q);
            Db.SubmitChanges();

            // Animation            
            Animation animation1 = CreateAnimation(division1, channel1, animationType1, priorityA);
            Db.Animations.InsertOnSubmit(animation1);
            Db.SubmitChanges();           

            

            // Animation Customer Group
            AnimationCustomerGroup animationGroup1 = CreateAnimationCustomerGroup(animation1, group1, division1);
            AnimationCustomerGroup animationGroup2 = CreateAnimationCustomerGroup(animation1, group2, division1);
            AnimationCustomerGroup animationGroup3 = CreateAnimationCustomerGroup(animation1, group3, division1);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup1);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup2);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup3);
            Db.SubmitChanges();



            // Animation Product           
            AnimationProduct animationProduct1 = CreateAnimationProduct(division1, animation1, 1, 1, signature);
            animationProduct1.Category = categoryAll;
            AnimationProduct animationProduct2 = CreateAnimationProduct(division1, animation1, 1, 1, signature2);
            animationProduct2.Category = categoryAll;
            AnimationProduct animationProduct3 = CreateAnimationProduct(division1, animation1, 3, 1, signature);
            animationProduct3.Category = categoryAll;
            Db.AnimationProducts.InsertOnSubmit(animationProduct1);
            Db.AnimationProducts.InsertOnSubmit(animationProduct2);
            Db.AnimationProducts.InsertOnSubmit(animationProduct3);
            Db.SubmitChanges();          

           

            // Customer Capacity - AnimationProduct1
            CustomerCapacity customerCapacity11 = CreateCustomerCapacity(customerB1, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 100);
            CustomerCapacity customerCapacity12 = CreateCustomerCapacity(customerB2, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 100);
            CustomerCapacity customerCapacity13 = CreateCustomerCapacity(customerB3, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 100);
            CustomerCapacity customerCapacity21 = CreateCustomerCapacity(customerD1, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 100);
            CustomerCapacity customerCapacity22 = CreateCustomerCapacity(customerD2, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 100);
            CustomerCapacity customerCapacity23 = CreateCustomerCapacity(customerD3, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 100);
            CustomerCapacity customerCapacity31 = CreateCustomerCapacity(customerJ1, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 100);
            CustomerCapacity customerCapacity32 = CreateCustomerCapacity(customerJ2, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 100);
            CustomerCapacity customerCapacity33 = CreateCustomerCapacity(customerJ3, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 100);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity11);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity12);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity13);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity21);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity22);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity23);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity31);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity32);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity33);
            Db.SubmitChanges();

            // Customer Capacity - AnimationProduct2
            CustomerCapacity customerCapacity211 = CreateCustomerCapacity(customerB1, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 100);
            CustomerCapacity customerCapacity212 = CreateCustomerCapacity(customerB2, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 100);
            CustomerCapacity customerCapacity213 = CreateCustomerCapacity(customerB3, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 100);
            CustomerCapacity customerCapacity221 = CreateCustomerCapacity(customerD1, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 100);
            CustomerCapacity customerCapacity222 = CreateCustomerCapacity(customerD2, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 100);
            CustomerCapacity customerCapacity223 = CreateCustomerCapacity(customerD3, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 100);
            CustomerCapacity customerCapacity231 = CreateCustomerCapacity(customerJ1, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 100);
            CustomerCapacity customerCapacity232 = CreateCustomerCapacity(customerJ2, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 100);
            CustomerCapacity customerCapacity233 = CreateCustomerCapacity(customerJ3, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 100);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity211);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity212);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity213);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity221);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity222);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity223);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity231);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity232);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity233);
            Db.SubmitChanges();

            // Customer Capacity - AnimationProduct1
            CustomerCapacity customerCapacity311 = CreateCustomerCapacity(customerB1, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 100);
            CustomerCapacity customerCapacity312 = CreateCustomerCapacity(customerB2, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 100);
            CustomerCapacity customerCapacity313 = CreateCustomerCapacity(customerB3, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 100);
            CustomerCapacity customerCapacity321 = CreateCustomerCapacity(customerD1, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 100);
            CustomerCapacity customerCapacity322 = CreateCustomerCapacity(customerD2, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 100);
            CustomerCapacity customerCapacity323 = CreateCustomerCapacity(customerD3, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 100);
            CustomerCapacity customerCapacity331 = CreateCustomerCapacity(customerJ1, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 100);
            CustomerCapacity customerCapacity332 = CreateCustomerCapacity(customerJ2, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 100);
            CustomerCapacity customerCapacity333 = CreateCustomerCapacity(customerJ3, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 100);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity311);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity312);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity313);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity321);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity322);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity323);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity331);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity332);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity333);
            Db.SubmitChanges();

            // Animation Product Details            
            AnimationProductDetail animationProductDetail1 = (from p in Db.AnimationProductDetails
                                                              where p.AnimationProduct == animationProduct1
                                                              select p).Single();
            animationProductDetail1.AllocationQuantity = 90;

            AnimationProductDetail animationProductDetail2 = (from p in Db.AnimationProductDetails
                                                              where p.AnimationProduct == animationProduct2
                                                              select p).Single();
            animationProductDetail2.AllocationQuantity = 50;

            AnimationProductDetail animationProductDetail3 = (from p in Db.AnimationProductDetails
                                                              where p.AnimationProduct == animationProduct3
                                                              select p).Single();
            animationProductDetail3.AllocationQuantity = 90;
            Db.SubmitChanges();
           

           

            Db.ExecuteCommand("exec dbo.uf_allocate_animationID '" + animation1.ID + "'");

            
            Db = new DbDataContext();
            
            
            CustomerAllocation result1 = (from ca in Db.CustomerAllocations.ToList()
                                         where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                         ca.IDCustomer == customerB1.ID
                                         select ca).FirstOrDefault();

            Assert.IsNotNull(result1, "Customer allocation for customerB1 does not exists");
            Assert.AreEqual(8, result1.CalculatedAllocation);

            CustomerAllocation result2 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerB2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result2, "Customer allocation for customerB2 does not exists");
            Assert.AreEqual(8, result2.CalculatedAllocation);

            CustomerAllocation result3 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerB3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result3, "Customer allocation for customerB3 does not exists");
            Assert.AreEqual(8, result3.CalculatedAllocation);

            CustomerAllocation result4 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerD1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result4, "Customer allocation for customerD1 does not exists");
            Assert.AreEqual(15, result4.CalculatedAllocation);

            CustomerAllocation result5 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerD2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result5, "Customer allocation for customerD2 does not exists");
            Assert.AreEqual(15, result5.CalculatedAllocation);

            CustomerAllocation result6 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerD3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result6, "Customer allocation for customerD3 does not exists");
            Assert.AreEqual(15, result6.CalculatedAllocation);

            CustomerAllocation result7 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerJ1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result7, "Customer allocation for customerJ1 does not exists");
            Assert.AreEqual(5, result7.CalculatedAllocation);

            CustomerAllocation result8 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerJ2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result8, "Customer allocation for customerJ2 does not exists");
            Assert.AreEqual(7, result8.CalculatedAllocation);

            CustomerAllocation result9 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerJ3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result9, "Customer allocation for customerJ3 does not exists");
            Assert.AreEqual(9, result9.CalculatedAllocation);

            
            


            CustomerAllocation result21 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerB1.ID
                                          select ca).FirstOrDefault();

            Assert.IsNotNull(result21, "Customer allocation for customerB1 does not exists");
            Assert.AreEqual(1, result21.CalculatedAllocation);

            CustomerAllocation result22 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerB2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result22, "Customer allocation for customerB2 does not exists");
            Assert.AreEqual(9, result22.CalculatedAllocation); // 10 in excel

            CustomerAllocation result23 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerB3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result23, "Customer allocation for customerB3 does not exists");
            Assert.AreEqual(21, result23.CalculatedAllocation); //20 in excel

            CustomerAllocation result24 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerD1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result24, "Customer allocation for customerD1 does not exists");
            Assert.AreEqual(5, result24.CalculatedAllocation);

            CustomerAllocation result25 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerD2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result25, "Customer allocation for customerD2 does not exists");
            Assert.AreEqual(14, result25.CalculatedAllocation);

            CustomerAllocation result26 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerD3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result26, "Customer allocation for customerD3 does not exists");
            Assert.AreEqual(0, result26.CalculatedAllocation); 

            CustomerAllocation result27 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerJ1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result27, "Customer allocation for customerJ1 does not exists");
            Assert.AreEqual(0, result27.CalculatedAllocation); 

            CustomerAllocation result28 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerJ2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result28, "Customer allocation for customerJ2 does not exists");
            Assert.AreEqual(0, result28.CalculatedAllocation);

            CustomerAllocation result29 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerJ3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result29, "Customer allocation for customerJ3 does not exists");
            Assert.AreEqual(0, result29.CalculatedAllocation);


            
            
            CustomerAllocation result321 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerB1.ID
                                           select ca).FirstOrDefault();

            Assert.IsNotNull(result321, "Customer allocation for customerB1 does not exists");
            Assert.AreEqual(9, result321.CalculatedAllocation);

            CustomerAllocation result322 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerB2.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result322, "Customer allocation for customerB2 does not exists");
            Assert.AreEqual(9, result322.CalculatedAllocation);

            CustomerAllocation result323 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerB3.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result323, "Customer allocation for customerB3 does not exists");
            Assert.AreEqual(6, result323.CalculatedAllocation);

            CustomerAllocation result324 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerD1.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result324, "Customer allocation for customerD1 does not exists");
            Assert.AreEqual(15, result324.CalculatedAllocation); 

            CustomerAllocation result325 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerD2.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result325, "Customer allocation for customerD2 does not exists");
            Assert.AreEqual(15, result325.CalculatedAllocation);

            CustomerAllocation result326 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerD3.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result326, "Customer allocation for customerD3 does not exists");
            Assert.AreEqual(15, result326.CalculatedAllocation);

            CustomerAllocation result327 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerJ1.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result327, "Customer allocation for customerJ1 does not exists");
            Assert.AreEqual(3, result327.CalculatedAllocation);

            CustomerAllocation result328 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerJ2.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result328, "Customer allocation for customerJ2 does not exists");
            Assert.AreEqual(6, result328.CalculatedAllocation); 

            CustomerAllocation result329 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerJ3.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result329, "Customer allocation for customerJ3 does not exists");
            Assert.AreEqual(12, result329.CalculatedAllocation);

           
        

        }
Пример #48
0
 void Reload() {
   using (var db = new DbDataContext()) {
     Raidb.BasketItem bi = db.BasketItems.SingleOrDefault(t => t.id == id);
     if (null != bi)
       LoadFromDbBasketItem(bi);
   }
 }
Пример #49
0
    public GenCodesForm() {
      InitializeComponent();

      db = new DbDataContext();
      CSS.LoadData(db);
    }
Пример #50
0
 public void Delete() {
   using (var db = new DbDataContext()) {
     Raidb.BasketItem bi = db.BasketItems.SingleOrDefault(t => t.id == id);
     if (null != bi) {
       db.BasketItems.DeleteOnSubmit(bi);
       db.SubmitChanges();
     }
   }
 }
Пример #51
0
        public void ProductInsertUpdate(AnimationProduct entity)
        {
            if (entity.IDBrandAxe == Guid.Empty)
            {
                entity.IDBrandAxe = null;
            }
            if (entity.IDCategory == Guid.Empty)
            {
                entity.IDCategory = null;
            }
            if (entity.IDSignature == Guid.Empty)
            {
                entity.IDSignature = null;
            }
            if (entity.IDItemType == Guid.Empty)
            {
                entity.IDItemType = null;
            }
            if (entity.IDMultipleNormal == Guid.Empty)
            {
                entity.IDMultipleNormal = null;
            }
            if (entity.IDMultipleWarehouse == Guid.Empty)
            {
                entity.IDMultipleWarehouse = null;
            }

            if (entity.ID == Guid.Empty)
            {
                Db.AnimationProducts.InsertOnSubmit(entity);
            }

            try
            {
                bool isInsert = entity.ID == Guid.Empty;

                submitDBChanges();
                //Db.SubmitChanges();

                if (isInsert)
                {
                    //TV: Allocations are recreated in trigger
                    recreateAllocationsForProduct(entity);
                }
            }
            catch (SqlException exc)
            {
                SqlException sqlExc = exc as SqlException;
                if (sqlExc.Number == 50000 && sqlExc.Class == 16)
                {
                    AnimationProduct originalEntity = new DbDataContext().AnimationProducts.Single(ap => ap.ID == entity.ID);
                    if (originalEntity != null)
                    {
                        switch(sqlExc.State)
                        {
                            case 28:
                                entity.CleanEntityRef("IDItemType");
                                entity.IDItemType = originalEntity.IDItemType;

                                entity.CleanEntityRef("IDSignature");
                                entity.IDSignature = originalEntity.IDSignature;

                                entity.CleanEntityRef("IDBrandAxe");
                                entity.IDBrandAxe = originalEntity.IDBrandAxe;

                                entity.CleanEntityRef("IDCategory");
                                entity.IDCategory = originalEntity.IDCategory;
                                break;
                            case 30: case 32: case 33: case 34: case 35:
                                entity.CleanEntityRef("IDMultipleNormal");
                                entity.IDMultipleNormal = originalEntity.IDMultipleNormal;
                                entity.IDMultipleWarehouse = originalEntity.IDMultipleWarehouse;
                                break;
                        }
                        
                        Db.SubmitChanges();
                    }
                    else
                    {
                        ProductDelete(entity);
                        Animation.AnimationProducts.Remove(entity);
                    }
                }
                throw;
            }
            catch (LorealChangeConflictException exc)
            {
                ResolveChangeConflict(exc);
            }
            catch (Exception exc)
            {
                if (entity.ID == Guid.Empty)
                {
                    Db.AnimationProducts.DeleteOnSubmit(entity);
                }
                MessageBox.Show(SystemMessagesManager.Instance.GetMessage("TableViewExceptionSql", Utility.GetExceptionsMessages(exc)));
            }
        }
Пример #52
0
        public void Allocation()
        {
            DeleteData();


            // Divisions            
            Division division1 = CreateDivision();
            Db.Divisions.InsertOnSubmit(division1);
            Db.SubmitChanges();

            // Signature
            Signature signature = CreateSignature(division1);
            Db.Signatures.InsertOnSubmit(signature);
            Db.SubmitChanges();

            // Distribution Channel            
            DistributionChannel channel1 = CreateDistributionChannel();
            Db.DistributionChannels.InsertOnSubmit(channel1);
            Db.SubmitChanges();

            // Category
            Category category1 = CreateCategory("Category 1", division1);
            Db.Categories.InsertOnSubmit(category1);
            Db.SubmitChanges();

            // ItemType
            ItemType itemType1 = CreateItemType(division1);
            ItemType itemType2 = CreateItemType(division1);
            ItemType itemType3 = CreateItemType(division1);
            Db.SubmitChanges();

            // Animation Type            
            AnimationType animationType1 = CreateAnimationType(division1, "Promotion");
            AnimationType animationType2 = CreateAnimationType(division1, "Launch");
            Db.AnimationTypes.InsertOnSubmit(animationType1);
            Db.AnimationTypes.InsertOnSubmit(animationType2);
            Db.SubmitChanges();

            // Priorities
            Priority priorityA = CreatePriority(division1, "A");
            Priority priorityB = CreatePriority(division1, "B");
            Priority priorityC = CreatePriority(division1, "C");
            Db.Priorities.InsertOnSubmit(priorityA);
            Db.Priorities.InsertOnSubmit(priorityB);
            Db.Priorities.InsertOnSubmit(priorityC);
            Db.SubmitChanges();

            // Sales Area           
            SalesArea salesArea = CreateSalesArea(channel1, division1);
            Db.SalesAreas.InsertOnSubmit(salesArea);
            Db.SubmitChanges();

            // Customer Group            
            CustomerGroup group1 = CreateCustomerGroup(salesArea, "Boots", "4545");
            group1.SalesArea = salesArea;
            CustomerGroup group2 = CreateCustomerGroup(salesArea, "Debenhams", "11232");
            group2.SalesArea = salesArea;
            CustomerGroup group3 = CreateCustomerGroup(salesArea, "John Lewis", "1232");
            group3.SalesArea = salesArea;
            Db.CustomerGroups.InsertOnSubmit(group1);
            Db.CustomerGroups.InsertOnSubmit(group2);
            Db.CustomerGroups.InsertOnSubmit(group3);
            Db.SubmitChanges();



            // Customers            
            Customer customerB1 = CreateCustomer(group1, "Boots 1", "5454", division1, category1);
            Customer customerB2 = CreateCustomer(group1, "Boots 2", "4278", division1, category1);
            Customer customerB3 = CreateCustomer(group1, "Boots 3", "54615", division1, category1);
            Customer customerD1 = CreateCustomer(group2, "Debenhams 1", "879487", division1, category1);
            Customer customerD2 = CreateCustomer(group2, "Debenhams 2", "65626", division1, category1);
            Customer customerD3 = CreateCustomer(group2, "Debenhams 3", "42718", division1, category1);
            Customer customerJ1 = CreateCustomer(group3, "John Lewis 1", "54165", division1, category1);
            Customer customerJ2 = CreateCustomer(group3, "John Lewis 2", "879817", division1, category1);
            Customer customerJ3 = CreateCustomer(group3, "John Lewis 3", "65606", division1, category1);
            Db.Customers.InsertOnSubmit(customerB1);
            Db.Customers.InsertOnSubmit(customerB2);
            Db.Customers.InsertOnSubmit(customerB3);
            Db.Customers.InsertOnSubmit(customerD1);
            Db.Customers.InsertOnSubmit(customerD2);
            Db.Customers.InsertOnSubmit(customerD3);
            Db.Customers.InsertOnSubmit(customerJ1);
            Db.Customers.InsertOnSubmit(customerJ2);
            Db.Customers.InsertOnSubmit(customerJ3);
            Db.SubmitChanges();

            // BrandAxes
            BrandAxe brandAxeX = CreateBrandAxe(signature, "BrandAxe X", "123");
            BrandAxe brandAxeY = CreateBrandAxe(signature, "BrandAxe Y", "1123");
            BrandAxe brandAxeZ = CreateBrandAxe(signature, "BrandAxe Z", "1423");
            Db.BrandAxes.InsertOnSubmit(brandAxeX);
            Db.BrandAxes.InsertOnSubmit(brandAxeY);
            Db.BrandAxes.InsertOnSubmit(brandAxeZ);
            Db.SubmitChanges();

            // Sales - X
            Sale sale11X = CreateSale(customerB1, brandAxeX, 100);
            Sale sale12X = CreateSale(customerB2, brandAxeX, 100);
            Sale sale13X = CreateSale(customerB3, brandAxeX, 100);
            Sale sale21X = CreateSale(customerD1, brandAxeX, 100);
            Sale sale22X = CreateSale(customerD2, brandAxeX, 100);
            Sale sale23X = CreateSale(customerD3, brandAxeX, 100);
            Sale sale31X = CreateSale(customerJ1, brandAxeX, 100);
            Sale sale32X = CreateSale(customerJ2, brandAxeX, 100);
            Sale sale33X = CreateSale(customerJ3, brandAxeX, 100);
            Db.Sales.InsertOnSubmit(sale11X);
            Db.Sales.InsertOnSubmit(sale12X);
            Db.Sales.InsertOnSubmit(sale13X);
            Db.Sales.InsertOnSubmit(sale21X);
            Db.Sales.InsertOnSubmit(sale22X);
            Db.Sales.InsertOnSubmit(sale23X);
            Db.Sales.InsertOnSubmit(sale31X);
            Db.Sales.InsertOnSubmit(sale32X);
            Db.Sales.InsertOnSubmit(sale33X);
            Db.SubmitChanges();

            // Sales - Y
            Sale sale11Y = CreateSale(customerB1, brandAxeY, 100);
            Sale sale12Y = CreateSale(customerB2, brandAxeY, 100);
            Sale sale13Y = CreateSale(customerB3, brandAxeY, 100);
            Sale sale21Y = CreateSale(customerD1, brandAxeY, 100);
            Sale sale22Y = CreateSale(customerD2, brandAxeY, 100);
            Sale sale23Y = CreateSale(customerD3, brandAxeY, 100);
            Sale sale31Y = CreateSale(customerJ1, brandAxeY, 100);
            Sale sale32Y = CreateSale(customerJ2, brandAxeY, 100);
            Sale sale33Y = CreateSale(customerJ3, brandAxeY, 100);
            Db.Sales.InsertOnSubmit(sale11Y);
            Db.Sales.InsertOnSubmit(sale12Y);
            Db.Sales.InsertOnSubmit(sale13Y);
            Db.Sales.InsertOnSubmit(sale21Y);
            Db.Sales.InsertOnSubmit(sale22Y);
            Db.Sales.InsertOnSubmit(sale23Y);
            Db.Sales.InsertOnSubmit(sale31Y);
            Db.Sales.InsertOnSubmit(sale32Y);
            Db.Sales.InsertOnSubmit(sale33Y);
            Db.SubmitChanges();

            // Sales - Z
            Sale sale11Z = CreateSale(customerB1, brandAxeZ, 100);
            Sale sale12Z = CreateSale(customerB2, brandAxeZ, 100);
            Sale sale13Z = CreateSale(customerB3, brandAxeZ, 100);
            Sale sale21Z = CreateSale(customerD1, brandAxeZ, 100);
            Sale sale22Z = CreateSale(customerD2, brandAxeZ, 100);
            Sale sale23Z = CreateSale(customerD3, brandAxeZ, 100);
            Sale sale31Z = CreateSale(customerJ1, brandAxeZ, 100);
            Sale sale32Z = CreateSale(customerJ2, brandAxeZ, 100);
            Sale sale33Z = CreateSale(customerJ3, brandAxeZ, 100);
            Db.Sales.InsertOnSubmit(sale11Z);
            Db.Sales.InsertOnSubmit(sale12Z);
            Db.Sales.InsertOnSubmit(sale13Z);
            Db.Sales.InsertOnSubmit(sale21Z);
            Db.Sales.InsertOnSubmit(sale22Z);
            Db.Sales.InsertOnSubmit(sale23Z);
            Db.Sales.InsertOnSubmit(sale31Z);
            Db.Sales.InsertOnSubmit(sale32Z);
            Db.Sales.InsertOnSubmit(sale33Z);
            Db.SubmitChanges();



            // Animation            
            Animation animation1 = CreateAnimation(division1, channel1, animationType1, priorityB);
            Db.Animations.InsertOnSubmit(animation1);
            Db.SubmitChanges();           

            

            // Animation Customer Group
            AnimationCustomerGroup animationGroup1 = CreateAnimationCustomerGroup(animation1, group1, division1);
            AnimationCustomerGroup animationGroup2 = CreateAnimationCustomerGroup(animation1, group2, division1);
            AnimationCustomerGroup animationGroup3 = CreateAnimationCustomerGroup(animation1, group3, division1);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup1);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup2);
            Db.AnimationCustomerGroups.InsertOnSubmit(animationGroup3);
            Db.SubmitChanges();



            // Animation Product           
            AnimationProduct animationProduct1 = CreateAnimationProduct(division1, animation1, 1, 1, category1, brandAxeX, itemType1);
            AnimationProduct animationProduct2 = CreateAnimationProduct(division1, animation1, 1, 1, category1, brandAxeY, itemType2);
            AnimationProduct animationProduct3 = CreateAnimationProduct(division1, animation1, 1, 1, category1, brandAxeZ, itemType3);
            Db.AnimationProducts.InsertOnSubmit(animationProduct1);
            Db.AnimationProducts.InsertOnSubmit(animationProduct2);
            Db.AnimationProducts.InsertOnSubmit(animationProduct3);
            Db.SubmitChanges();

           
            // Customer Capacity - AnimationProduct1
            CustomerCapacity customerCapacity11 = CreateCustomerCapacity(customerB1, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 5);
            CustomerCapacity customerCapacity12 = CreateCustomerCapacity(customerB2, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 5);
            CustomerCapacity customerCapacity13 = CreateCustomerCapacity(customerB3, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 5);
            CustomerCapacity customerCapacity21 = CreateCustomerCapacity(customerD1, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 5);
            CustomerCapacity customerCapacity22 = CreateCustomerCapacity(customerD2, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 5);
            CustomerCapacity customerCapacity23 = CreateCustomerCapacity(customerD3, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 5);
            CustomerCapacity customerCapacity31 = CreateCustomerCapacity(customerJ1, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 5);
            CustomerCapacity customerCapacity32 = CreateCustomerCapacity(customerJ2, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 5);
            CustomerCapacity customerCapacity33 = CreateCustomerCapacity(customerJ3, animation1.AnimationType, animation1.Priority, animationProduct1.ItemType, 5);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity11);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity12);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity13);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity21);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity22);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity23);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity31);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity32);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity33);
            Db.SubmitChanges();

            // Customer Capacity - AnimationProduct2
            CustomerCapacity customerCapacity211 = CreateCustomerCapacity(customerB1, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 2);
            CustomerCapacity customerCapacity212 = CreateCustomerCapacity(customerB2, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 2);
            CustomerCapacity customerCapacity213 = CreateCustomerCapacity(customerB3, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 2);
            CustomerCapacity customerCapacity221 = CreateCustomerCapacity(customerD1, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 2);
            CustomerCapacity customerCapacity222 = CreateCustomerCapacity(customerD2, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 2);
            CustomerCapacity customerCapacity223 = CreateCustomerCapacity(customerD3, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 2);
            CustomerCapacity customerCapacity231 = CreateCustomerCapacity(customerJ1, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 2);
            CustomerCapacity customerCapacity232 = CreateCustomerCapacity(customerJ2, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 2);
            CustomerCapacity customerCapacity233 = CreateCustomerCapacity(customerJ3, animation1.AnimationType, animation1.Priority, animationProduct2.ItemType, 2);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity211);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity212);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity213);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity221);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity222);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity223);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity231);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity232);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity233);
            Db.SubmitChanges();

            // Customer Capacity - AnimationProduct1
            CustomerCapacity customerCapacity311 = CreateCustomerCapacity(customerB1, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 3);
            CustomerCapacity customerCapacity312 = CreateCustomerCapacity(customerB2, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 3);
            CustomerCapacity customerCapacity313 = CreateCustomerCapacity(customerB3, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 3);
            CustomerCapacity customerCapacity321 = CreateCustomerCapacity(customerD1, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 3);
            CustomerCapacity customerCapacity322 = CreateCustomerCapacity(customerD2, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 3);
            CustomerCapacity customerCapacity323 = CreateCustomerCapacity(customerD3, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 3);
            CustomerCapacity customerCapacity331 = CreateCustomerCapacity(customerJ1, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 3);
            CustomerCapacity customerCapacity332 = CreateCustomerCapacity(customerJ2, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 3);
            CustomerCapacity customerCapacity333 = CreateCustomerCapacity(customerJ3, animation1.AnimationType, animation1.Priority, animationProduct3.ItemType, 3);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity311);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity312);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity313);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity321);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity322);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity323);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity331);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity332);
            Db.CustomerCapacities.InsertOnSubmit(customerCapacity333);
            Db.SubmitChanges();

            // Animation Product Details            
            AnimationProductDetail animationProductDetail1 = (from p in Db.AnimationProductDetails
                                                              where p.AnimationProduct == animationProduct1
                                                              select p).Single();
            animationProductDetail1.AllocationQuantity = 27;

            AnimationProductDetail animationProductDetail2 = (from p in Db.AnimationProductDetails
                                                              where p.AnimationProduct == animationProduct2
                                                              select p).Single();
            animationProductDetail2.AllocationQuantity = 18;

            AnimationProductDetail animationProductDetail3 = (from p in Db.AnimationProductDetails
                                                              where p.AnimationProduct == animationProduct3
                                                              select p).Single();
            animationProductDetail3.AllocationQuantity = 4;
            Db.SubmitChanges();
           

            Db.ExecuteCommand("exec dbo.uf_allocate_animationID '" + animation1.ID + "'");


            Db = new DbDataContext();

            
            CustomerAllocation result1 = (from ca in Db.CustomerAllocations.ToList()
                                         where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                         ca.IDCustomer == customerB1.ID
                                         select ca).FirstOrDefault();

            Assert.IsNotNull(result1, "Customer allocation for customerB1 does not exists");
            Assert.AreEqual(3, result1.CalculatedAllocation);

            CustomerAllocation result2 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerB2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result2, "Customer allocation for customerB2 does not exists");
            Assert.AreEqual(3, result2.CalculatedAllocation);

            CustomerAllocation result3 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerB3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result3, "Customer allocation for customerB3 does not exists");
            Assert.AreEqual(3, result3.CalculatedAllocation);

            CustomerAllocation result4 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerD1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result4, "Customer allocation for customerD1 does not exists");
            Assert.AreEqual(3, result4.CalculatedAllocation);

            CustomerAllocation result5 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerD2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result5, "Customer allocation for customerD2 does not exists");
            Assert.AreEqual(3, result5.CalculatedAllocation);

            CustomerAllocation result6 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerD3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result6, "Customer allocation for customerD3 does not exists");
            Assert.AreEqual(3, result6.CalculatedAllocation);

            CustomerAllocation result7 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerJ1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result7, "Customer allocation for customerJ1 does not exists");
            Assert.AreEqual(3, result7.CalculatedAllocation);

            CustomerAllocation result8 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerJ2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result8, "Customer allocation for customerJ2 does not exists");
            Assert.AreEqual(3, result8.CalculatedAllocation);

            CustomerAllocation result9 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail1.ID &&
                                          ca.IDCustomer == customerJ3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result9, "Customer allocation for customerJ3 does not exists");
            Assert.AreEqual(3, result9.CalculatedAllocation);





            CustomerAllocation result21 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerB1.ID
                                          select ca).FirstOrDefault();

            Assert.IsNotNull(result21, "Customer allocation for customerB1 does not exists");
            Assert.AreEqual(2, result21.CalculatedAllocation);

            CustomerAllocation result22 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerB2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result22, "Customer allocation for customerB2 does not exists");
            Assert.AreEqual(2, result22.CalculatedAllocation);

            CustomerAllocation result23 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerB3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result23, "Customer allocation for customerB3 does not exists");
            Assert.AreEqual(2, result23.CalculatedAllocation);

            CustomerAllocation result24 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerD1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result24, "Customer allocation for customerD1 does not exists");
            Assert.AreEqual(2, result24.CalculatedAllocation);

            CustomerAllocation result25 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerD2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result25, "Customer allocation for customerD2 does not exists");
            Assert.AreEqual(2, result25.CalculatedAllocation);

            CustomerAllocation result26 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerD3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result26, "Customer allocation for customerD3 does not exists");
            Assert.AreEqual(2, result26.CalculatedAllocation);

            CustomerAllocation result27 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerJ1.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result27, "Customer allocation for customerJ1 does not exists");
            Assert.AreEqual(2, result27.CalculatedAllocation);

            CustomerAllocation result28 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerJ2.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result28, "Customer allocation for customerJ2 does not exists");
            Assert.AreEqual(2, result28.CalculatedAllocation);

            CustomerAllocation result29 = (from ca in Db.CustomerAllocations.ToList()
                                          where ca.IDAnimationProductDetail == animationProductDetail2.ID &&
                                          ca.IDCustomer == customerJ3.ID
                                          select ca).FirstOrDefault();
            Assert.IsNotNull(result29, "Customer allocation for customerJ3 does not exists");
            Assert.AreEqual(2, result29.CalculatedAllocation);




            CustomerAllocation result321 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerB1.ID
                                           select ca).FirstOrDefault();

            Assert.IsNotNull(result321, "Customer allocation for customerB1 does not exists");
            Assert.AreEqual(1, result321.CalculatedAllocation);

            CustomerAllocation result322 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerB2.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result322, "Customer allocation for customerB2 does not exists");
            Assert.AreEqual(1, result322.CalculatedAllocation);

            CustomerAllocation result323 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerB3.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result323, "Customer allocation for customerB3 does not exists");
            Assert.AreEqual(1, result323.CalculatedAllocation);

            CustomerAllocation result324 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerD1.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result324, "Customer allocation for customerD1 does not exists");
            Assert.AreEqual(1, result324.CalculatedAllocation);

            CustomerAllocation result325 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerD2.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result325, "Customer allocation for customerD2 does not exists");
            Assert.AreEqual(0, result325.CalculatedAllocation);

            CustomerAllocation result326 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerD3.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result326, "Customer allocation for customerD3 does not exists");
            Assert.AreEqual(0, result326.CalculatedAllocation);

            CustomerAllocation result327 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerJ1.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result327, "Customer allocation for customerJ1 does not exists");
            Assert.AreEqual(0, result327.CalculatedAllocation);

            CustomerAllocation result328 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerJ2.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result328, "Customer allocation for customerJ2 does not exists");
            Assert.AreEqual(0, result328.CalculatedAllocation);

            CustomerAllocation result329 = (from ca in Db.CustomerAllocations.ToList()
                                           where ca.IDAnimationProductDetail == animationProductDetail3.ID &&
                                           ca.IDCustomer == customerJ3.ID
                                           select ca).FirstOrDefault();
            Assert.IsNotNull(result329, "Customer allocation for customerJ3 does not exists");
            Assert.AreEqual(0, result329.CalculatedAllocation);

           
            

        }
Пример #53
0
 public void Setup() {
   db = new DbDataContext();
   db.Connection.Open();
   db.Transaction = db.Connection.BeginTransaction();
 }
Пример #54
0
 public static void Write(string type, string text) {
   using (var db = new DbDataContext())
     db.Log(Program, type, text);
 }
Пример #55
0
        // generating capacities
        private void btnGenerate_Click(object sender, RoutedEventArgs e)
        {
            int capacityValue = 0;
            int.TryParse(txtCapacityValue.Text, out capacityValue);

            IEnumerable<Customer> selectedCustomers = customers.Where(c => c.IsSelected);

            #region Validation warning
            if (capacityValue == 0)
            {
                MessageBox.Show("Please set positive capacity value");
                return;
            }

            if (cboAnimationType.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select animation type");
                return;
            }

            if (cboItemType.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select item type");
                return;
            }

            if (cboPriority.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select priority");
                return;
            }

            if (selectedCustomers.Count() == 0)
            {
                MessageBox.Show("Please select at least one customer");
                return;
            }
            #endregion

            // warning before ovewriting
            DbDataContext simpleContext = new DbDataContext(false);
            LongTaskExecutor createCapacity = new LongTaskExecutor("");
  

            IEnumerable<Customer> customersWithCapacitiesAlreadyInDB = simpleContext.CustomerCapacities.Where(ca => ca.IDAnimationType == ((AnimationType)cboAnimationType.SelectedItem).ID
                && ca.IDItemType == ((ItemType)cboItemType.SelectedItem).ID               
                && ca.IDPriority == ((Priority)cboPriority.SelectedItem).ID
                && selectedCustomers.Contains((Customer)ca.Customer)).Select(ca => ca.Customer).Distinct().ToList();

            if (customersWithCapacitiesAlreadyInDB.Count() > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Customer a in customersWithCapacitiesAlreadyInDB)
                {
                    sb.AppendLine(String.Format("{0} {1}", a.AccountNumber, a.Name));
                }

                String warningMessage = String.Format("{0} \r\n{1}", SystemMessagesManager.Instance.GetMessage("OverwriteCustomerCapacity"), sb.ToString());

                if (MessageBox.Show(warningMessage, "Warning", MessageBoxButton.YesNo) == MessageBoxResult.No)
                {
                    return;
                }                    
                else
                {                    
                    createCapacity.DoWork += createCapacity_DoWork;
                    createCapacity.Run(selectedCustomers);
                }  
            }
           

            createCapacity.DoWork += createCapacity_DoWork;
            createCapacity.Run(selectedCustomers);

           
        }
Пример #56
0
 public string GetFullFileName(string filename) {
   using (var db = new DbDataContext()) {
     MeFile meFile = db.MeFiles.SingleOrDefault(
       t => t.idMe == idMe && t.filename == filename);
     if (meFile == null)
       return string.Empty;
     return FileStorage.GetFullFileName(meFile.id);
   }
 }
Пример #57
0
 public bool CheckFilename(string filename) {
   throw new NotImplementedException("Not tested");
   using (var db = new DbDataContext()) {
     MeFile meFile = db.MeFiles.SingleOrDefault(
       t => t.id == id && t.filename == filename);
     return (meFile != null);
   }
 }
Пример #58
0
 public void Buy() {
   try {
     using (var db = new DbDataContext()) {
       AbonentBasket basket = db.AbonentBaskets.SingleOrDefault(t => t.id == IdAbonentBasket);
       if (null != basket)
         if (!(basket.balans < Price)) {
           db.BuyBasketItem(id, idAbonentBasket);
           Reload();
         }
     }
   }
   catch {
   }
   ;
 }