//Report No.7 - daily directive for making toners which quantity is bellow the minimal requirement
        public ActionResult DailyDirective()
        {
            //var differences = ControllerMethods.DifferencesBetweenSoldAndMadeToners().Where(c => c.TonerTotalCount <= c.TonerTotalMin && c.TonerTotalCount != c.TonerTotalMin).OrderByDescending(c => c.TonerTotalMin - c.TonerTotalCount).ThenBy(c => c.TotalTonerModel);
            var differences = ControllerMethods.DifferencesBetweenSoldAndMadeToners().Where(c => c.TonerTotalCount <= c.TonerTotalMin && c.TonerTotalCount != c.TonerTotalMin).OrderBy(c => c.TotalTonerModel);

            return(View(differences));
        }
        public bool GetEmployeAuth(string userName, string password)
        {
            try
            { conn.Open();

              SqlCommand NewCmd = conn.CreateCommand();
              NewCmd.CommandType = CommandType.Text;
              NewCmd.CommandText = "SELECT SEC_HDR_CODE, SEC_HDR_USR_NAME, SEC_HDR_PWD FROM SECURITY_HEADER WHERE (SEC_HDR_USR_NAME = '" + userName + "') AND (SEC_HDR_PWD = '" + password + "')";

              SqlDataReader dr = NewCmd.ExecuteReader();
              if (dr.HasRows)
              {
                  while (dr.Read())
                  {
                      UserInfo ui = new UserInfo(dr["SEC_HDR_CODE"].ToString(), dr["SEC_HDR_USR_NAME"].ToString(), dr["SEC_HDR_PWD"].ToString());

                      int i = Convert.ToInt32(dr["SEC_HDR_CODE"]);
                      Settings.Default.UserID = i;
                      Settings.Default.Save();
                      ControllerMethods dba = new ControllerMethods(Convert.ToInt32(dr["SEC_HDR_CODE"]));
                  }
                  NewCmd.Dispose();

                  return(true);
              }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString() + " " + ex.Data.ToString(), "Error while accessing database", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally { conn.Close(); }

            return(false);
        }
        //Report No.6 - total sum of sold toners by sorted by model
        public ActionResult TotalTonerSale(string dateFromString, string dateToString)
        {
            #region za brisati
            //var soldToners = db.SaleToners.GroupBy(r => r.Toner.TonerModel).Select(r => new TonerTotal()
            //{
            //    TotalTonerModel = r.Key,
            //    TonerTotalCount = r.Sum(c => c.TonerQuantity),
            //}).OrderByDescending(c => c.TonerTotalCount).ToList();

            ////TODO: missing part of the code which will do TryParse DateTime input
            //if (!String.IsNullOrEmpty(dateFromString) || !String.IsNullOrEmpty(dateToString))
            //{
            //    DateTime dateFrom = Convert.ToDateTime(dateFromString);
            //    //if (DateTime.TryParse(dateFromString, out dateFrom))
            //    //{

            //    //}
            //    DateTime dateTo = Convert.ToDateTime(dateToString);
            //    var soldTonersInPeriod = db.SaleToners.Where(c => c.SaleTonerDate >= dateFrom && c.SaleTonerDate <= dateTo).GroupBy(r => r.Toner.TonerModel).Select(r => new TonerTotal()
            //    {
            //        TotalTonerModel = r.Key,
            //        TonerTotalCount = r.Sum(c => c.TonerQuantity),
            //    }).OrderByDescending(c => c.TonerTotalCount).ToList();

            //    soldToners = soldTonersInPeriod;
            //}
            #endregion
            var soldToners = ControllerMethods.ListOfAllSoldTonersInPeriod(dateFromString, dateToString);

            //Puts total sum of sold toners in period to ViewData
            ViewData["CountSoldToners"] = ControllerMethods.SumOfAllSoldTonersInPeriod(soldToners);

            return(View(soldToners.ToList()));
        }
        //private ApplicationDbContext db = new ApplicationDbContext();

        public ActionResult Index()
        {
            //returns ordered list of sold toners first by date and then by owner
            var saleToners = ControllerMethods.OrderedListOfSoldTonersFirstByDateAndThenByOwner();

            return(View(saleToners.ToList()));
        }
예제 #5
0
 public ClientSession(IChannel channel, bool isWorldClient) : base(channel)
 {
     // set last received
     lastPacketReceive = DateTime.Now.Ticks;
     _random           = new Random((int)ClientId);
     _isWorldClient    = isWorldClient;
     foreach (var controller in PacketControllerFactory.GenerateControllers())
     {
         controller.RegisterSession(this);
         foreach (MethodInfo methodInfo in controller.GetType().GetMethods().Where(x => x.GetParameters().FirstOrDefault()?.ParameterType.BaseType == typeof(PacketDefinition)))
         {
             var type = methodInfo.GetParameters().FirstOrDefault()?.ParameterType;
             PacketHeaderAttribute packetheader = (PacketHeaderAttribute)Array.Find(type.GetCustomAttributes(true), ca => ca.GetType().Equals(typeof(PacketHeaderAttribute)));
             HeaderMethod.Add(packetheader, new Tuple <IPacketController, Type>(controller, type));
             ControllerMethods.Add(packetheader, DelegateBuilder.BuildDelegate <Action <object, object> >(methodInfo));
         }
     }
 }
        //Report No.4
        public ActionResult LastTonerSale(string searchByOwner, string searchByToner)
        {
            #region za brisati
            //var lastTonerSale = db.SaleToners.Where(c => c.Owner.OwnerIsActive == true).GroupBy(g => new { g.Owner.OwnerName, g.TonerID })
            //    .Select(s => s.OrderByDescending(x => x.SaleTonerDate).FirstOrDefault()).OrderBy(s => s.Owner.OwnerName).ThenBy(s => s.Toner.TonerModel).ToList();

            //if (!String.IsNullOrEmpty(searchByOwner))
            //{
            //    lastTonerSale = lastTonerSale.Where(o => o.Owner.OwnerName.Contains(searchByOwner)).OrderBy(s => s.Owner.OwnerName).ThenBy(s => s.Toner.TonerModel).ThenBy(s => s.SaleTonerDate);
            //}

            //if (!String.IsNullOrEmpty(searchByToner))
            //{
            //    lastTonerSale = lastTonerSale.Where(o => o.Toner.TonerModel.Contains(searchByToner)).OrderBy(s => s.Owner.OwnerName).ThenBy(s => s.Toner.TonerModel).ThenBy(s => s.SaleTonerDate);
            //}
            #endregion
            var lastTonerSale = ControllerMethods.LastTonerSoldByOwnerOrTonerModel(searchByOwner, searchByToner);
            return(View(lastTonerSale.ToList()));
        }
        //Report No.5 - Returns list of owners (companies) that didn't order toners in last X (periodInMonths) months
        public ActionResult TonerAlarm(string periodInMonths)
        {
            #region za brisati
            //var ownersWithNoAlarmOrder = db.SaleToners
            //      .Where(c => c.Owner.OwnerIsActive == true)
            //      .GroupBy(c => c.OwnerID)
            //      .Select(s => s.OrderByDescending(x => x.SaleTonerDate).FirstOrDefault()).OrderBy(c => c.SaleTonerDate);


            //if (!String.IsNullOrEmpty(periodInMonths))
            //{
            //    int period = Int16.Parse(periodInMonths);
            //    var LimitDate = DateTime.Now.Date;
            //    LimitDate = LimitDate.AddMonths(-period);
            //    ownersWithNoAlarmOrder = ownersWithNoAlarmOrder.Where(o => o.SaleTonerDate < LimitDate).OrderBy(s => s.SaleTonerDate);
            //}
            #endregion
            var ownersWithNoAlarmOrder = ControllerMethods.OwnersWithNoTonerOrderInSomePeriod(periodInMonths);
            return(View(ownersWithNoAlarmOrder.ToList()));
        }
예제 #8
0
        public void TestSumOfAllSoldTonersInPeriod()
        {
            // arrange
            List <TonerTotal> testList = new List <TonerTotal>();

            testList.Add(new TonerTotal {
                TotalTonerModel = "model1", TonerTotalCount = 1, TonerTotalMin = 1
            });
            testList.Add(new TonerTotal {
                TotalTonerModel = "model2", TonerTotalCount = 3, TonerTotalMin = 1
            });
            testList.Add(new TonerTotal {
                TotalTonerModel = "model1", TonerTotalCount = 6, TonerTotalMin = 1
            });

            int expected = 10;
            // act
            int realNumberOfSoldToners = ControllerMethods.SumOfAllSoldTonersInPeriod(testList);

            Assert.AreEqual(expected, realNumberOfSoldToners, 0, "Account not debited correctly");
        }
        //Report No.5a - list of companies that didn't order any toner
        public ActionResult TonerAlarm2()
        {
            var ownersListWithNoOrder = ControllerMethods.OwnersWithNoTonerOrder();

            return(View(ownersListWithNoOrder.ToList()));
        }
        //Report No.8 - number of all toner models in warehouse
        public ActionResult WarehouseToner()
        {
            var differences = ControllerMethods.DifferencesBetweenSoldAndMadeToners().OrderBy(c => c.TotalTonerModel);

            return(View(differences));
        }