protected void Button1_Click(object sender, EventArgs e)
        {
            User sUser = (User)Session["user"];
            if (sUser == null || sUser.user_type != 1)
            {
                Response.Redirect("~/m/Login.aspx");
            }

            User dUser = new UserController().actionGetUserByID(sUser.id);

            RequisitionController requisitionController = new RequisitionController();
            ApplicationLayer.Requisition requisition = new ApplicationLayer.Requisition();
            requisition.user_obj = dUser.id;
            requisition.stationery = Convert.ToInt32(ui_id_hidden.Value);
            requisition.quantity = Convert.ToInt32(ui_quantity.Text);
            requisition.department = Convert.ToInt32(dUser.department);
            Message message = requisitionController.actionCreateRequisition(requisition);

            if (message.condition)
            {
                Response.Cookies.Add(new HttpCookie("flash_message", "Successfully Requested.") { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-success") { Path = "/" });
                Response.Redirect("~/m/DepartmentEmployee/Stationeries.aspx");
            }
            else {
                Response.Cookies.Add(new HttpCookie("flash_message", "Requisition Fail. <br />" + message.message) { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-error") { Path = "/" });
                return;
            }
        }
        public string makeRequisition(int userId, string stationeryName, int quantity)
        {
            StationeryController stController = new StationeryController();
            Requisition requisition = new Requisition();

            // System.Diagnostics.Debug.WriteLine("inside actionGetStationeryIdByName::" + name);
            string newstationeryName = stationeryName.Replace('_', ' ');
            //  System.Diagnostics.Debug.WriteLine("inside actionGetStationeryIdByName::" + newstationeryName);

            int stationeryId = Convert.ToInt32(stController.actionGetStationeryIdByName(newstationeryName));
            requisition.stationery = stationeryId;
            requisition.quantity = quantity;
            requisition.user_obj = userId;
            //hardcoded department id
            requisition.department = 8;
            requisition.user_approved_by = null;
            RequisitionController requisitionController = new RequisitionController();
            Message msg = requisitionController.actionCreateRequisition(requisition);
            if (msg.condition)
            {
                System.Diagnostics.Debug.WriteLine("success");
                return "success";
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("fail");
                return "fail";
            }
        }
Esempio n. 3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            User sUser = (User)Session["user"];

            if (sUser == null || sUser.user_type != 1)
            {
                Response.Redirect("~/m/Login.aspx");
            }

            User dUser = new UserController().actionGetUserByID(sUser.id);

            RequisitionController requisitionController = new RequisitionController();

            ApplicationLayer.Requisition requisition = new ApplicationLayer.Requisition();
            requisition.user_obj   = dUser.id;
            requisition.stationery = Convert.ToInt32(ui_id_hidden.Value);
            requisition.quantity   = Convert.ToInt32(ui_quantity.Text);
            requisition.department = Convert.ToInt32(dUser.department);
            Message message = requisitionController.actionCreateRequisition(requisition);

            if (message.condition)
            {
                Response.Cookies.Add(new HttpCookie("flash_message", "Successfully Requested.")
                {
                    Path = "/"
                });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-success")
                {
                    Path = "/"
                });
                Response.Redirect("~/m/DepartmentEmployee/Stationeries.aspx");
            }
            else
            {
                Response.Cookies.Add(new HttpCookie("flash_message", "Requisition Fail. <br />" + message.message)
                {
                    Path = "/"
                });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-error")
                {
                    Path = "/"
                });
                return;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            DataContext db = new DataContext();

            List<Requisition> rl = db.Requisitions.Where(o => (o.id >= 141 && o.id <= 225)).ToList();

            List<PurchaseOrder> po = db.PurchaseOrders.Where( o => (o.id >= 1 && o.id <=300)).ToList();
            foreach (PurchaseOrder p in po) {
                if(p.po_reordered_quantity > 60){
                    p.po_reordered_quantity -= 20;
                }
            }
            db.SaveChanges();

            return;
            foreach (Requisition r2 in rl) {
                Requisition r1 = new Requisition();
                //copier
                Department department = db.Departments.Where(o => o.id == r2.department).SingleOrDefault();
                r1.stationery = r2.stationery;
                r1.quantity = GetRandomNumber(1, 3);
                r1.user_obj = r2.user_obj;
                r1.status = 1;
                r1.department = department.id;

                r1.datetime_requested = DateTime.Now;
                db.Requisitions.AddObject(r1);
            }

            db.SaveChanges();

            return;
            //Requisition r1 = new Requisition();
            //Requisition r2 = new Requisition();

            ////copier
            //Department department = db.Departments.Where(o => o.id == r2.department).SingleOrDefault();
            //r1.stationery = r2.stationery;
            //r1.quantity = r2.quantity;
            //r1.user_obj = r2.user_obj;
            ////r1.status = r2.status;
            //r1.department = department.id;
            ////r1.user_approved_by = department.department_head;
        }
        public string showAllRejectedRequisitions(string accessToken)
        {
            OAuthController oAuth = new OAuthController();
            User user = oAuth.actionGetUserByToken(accessToken);
            RequisitionController requisitionController = new RequisitionController();

            List<RequisitionView> requisitionDepartmentWise = requisitionController.actionGetRejectedRequisitionViewsByDepartmentID(Convert.ToInt32(user.department));

            List<Requisition> requisitions = new List<Requisition>();
            foreach (RequisitionView rView in requisitionDepartmentWise)
            {
                Requisition requisition = new Requisition();
                requisition.EmployeeName = rView.firstname + " " + rView.lastname;
                requisition.Quantity = rView.quantity;
                requisition.RequisitionDate = rView.datetime_requested;
                requisition.ReqDate = rView.datetime_requested.ToString("MMMM dd, yyyy");
                requisition.StationaryName = rView.stationery_name;
                requisitions.Add(requisition);
            }
            return JsonConvert.SerializeObject(requisitions);
        }
        public string showAllPendingRequisition(string accessToken)
        {
            RequisitionController requisitionController = new RequisitionController();
            JavaScriptSerializer js = new JavaScriptSerializer();
            OAuthController oAuth = new OAuthController();
            User user = oAuth.actionGetUserByToken(accessToken);
            // int userId = user.id;
            List<RequisitionView> requisitionDepartmentWise = requisitionController.actionGetPendingRequisitionViewsByDepartmentID(Convert.ToInt32(user.department));
            List<UserRequisition> userRequisitionsList = new List<UserRequisition>();
            foreach (RequisitionView r in requisitionDepartmentWise)
            {
                if (userRequisitionsList.Count == 0)
                {
                    UserRequisition userRequisition = new UserRequisition();
                    userRequisition.EmployeeName = r.firstname + " " + r.lastname;
                    userRequisition.UserId = r.user_obj;
                    Requisition requisition = new Requisition();
                    requisition.ReqId = r.requisition_id;
                    requisition.Quantity = r.quantity;
                    requisition.StationaryName = r.stationery_name;
                    userRequisition.UserRequisitions.Add(requisition);
                    userRequisitionsList.Add(userRequisition);
                }
                else
                {
                    bool found = false;
                    //check if requisition from the same user is pending, if yes group the requisition based on that user id
                    foreach (UserRequisition uR in userRequisitionsList)
                    {
                        if (r.user_obj == uR.UserId)
                        {
                            found = true;
                            Requisition requisition = new Requisition();
                            requisition.ReqId = r.requisition_id;
                            requisition.Quantity = r.quantity;
                            requisition.StationaryName = r.stationery_name;
                            requisition.RequisitionDate = r.datetime_requested;
                            uR.UserRequisitions.Add(requisition);
                            break;
                        }

                    }//foreach
                    //else simply add the userrequisition to the list, grouping not required
                    if (!found)
                    {
                        UserRequisition userRequisition = new UserRequisition();
                        userRequisition.EmployeeName = r.firstname + " " + r.lastname;
                        userRequisition.UserId = r.user_obj;
                        Requisition requisition = new Requisition();
                        requisition.ReqId = r.requisition_id;
                        requisition.Quantity = r.quantity;
                        requisition.StationaryName = r.stationery_name;
                        userRequisition.UserRequisitions.Add(requisition);
                        userRequisitionsList.Add(userRequisition);
                    }//if
                }//else
            }//forEach

            System.Diagnostics.Debug.WriteLine("json serialized:" + JsonConvert.SerializeObject(userRequisitionsList));
            return JsonConvert.SerializeObject(userRequisitionsList);
            /// return js.Serialize(userRequisitionsList);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Requisitions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRequisitions(Requisition requisition)
 {
     base.AddObject("Requisitions", requisition);
 }
 /// <summary>
 /// Create a new Requisition object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="stationery">Initial value of the stationery property.</param>
 /// <param name="quantity">Initial value of the quantity property.</param>
 /// <param name="user_obj">Initial value of the user_obj property.</param>
 /// <param name="status">Initial value of the status property.</param>
 /// <param name="datetime_requested">Initial value of the datetime_requested property.</param>
 /// <param name="department">Initial value of the department property.</param>
 public static Requisition CreateRequisition(global::System.Int32 id, global::System.Int32 stationery, global::System.Int32 quantity, global::System.Int32 user_obj, global::System.Int32 status, global::System.DateTime datetime_requested, global::System.Int32 department)
 {
     Requisition requisition = new Requisition();
     requisition.id = id;
     requisition.stationery = stationery;
     requisition.quantity = quantity;
     requisition.user_obj = user_obj;
     requisition.status = status;
     requisition.datetime_requested = datetime_requested;
     requisition.department = department;
     return requisition;
 }
        public static string LoadAllApprovedRequests()
        {
            User sUser = (User)HttpContext.Current.Session["user"];
            if (sUser == null)
            {
                return null;
            }

            UserController userController = new UserController();
            User dUser = userController.actionGetUserByID(sUser.id);

            RequisitionController requisitionController = new RequisitionController();
            JavaScriptSerializer js = new JavaScriptSerializer();
            List<RequisitionView> requisitionDepartmentWise = requisitionController.actionGetApprovedRequisitionViewsByDepartmentID(Convert.ToInt32(dUser.department));
            System.Diagnostics.Debug.WriteLine("check @@@@@@@@@@@@ requisitions by department wise:" + requisitionDepartmentWise.Count());
            List<UserRequisition> userRequisitionsList = new List<UserRequisition>();
            foreach (RequisitionView r in requisitionDepartmentWise)
            {
                if (userRequisitionsList.Count == 0)
                {
                    UserRequisition userRequisition = new UserRequisition();
                    //Since there are no requisitions made so no question of grouping based on user id
                    userRequisition.EmployeeName = r.firstname + " " + r.lastname;
                    userRequisition.UserId = r.user_obj;
                    Requisition requisition = new Requisition();
                    requisition.ReqId = r.requisition_id;
                    requisition.Quantity = r.quantity;
                    requisition.StationaryName = r.stationery_name;
                    // requisition.RequisitionDate = r.r
                    userRequisition.UserRequisitions.Add(requisition);
                    userRequisitionsList.Add(userRequisition);
                }
                else
                {
                    bool found = false;
                    //check if requisition from the same user is pending, if yes group the requisition based on that user id
                    foreach (UserRequisition uR in userRequisitionsList)
                    {
                        if (r.user_obj == uR.UserId)
                        {
                            found = true;
                            Requisition requisition = new Requisition();
                            requisition.ReqId = r.requisition_id;
                            requisition.Quantity = r.quantity;
                            requisition.StationaryName = r.stationery_name;
                            // requisition.RequisitionDate = r.r
                            uR.UserRequisitions.Add(requisition);
                            break;
                        }

                    }//foreach
                    //else simply add the userrequisition to the list, grouping not required
                    if (!found)
                    {
                        UserRequisition userRequisition = new UserRequisition();
                        userRequisition.EmployeeName = r.firstname + " " + r.lastname;
                        userRequisition.UserId = r.user_obj;

                        Requisition requisition = new Requisition();
                        requisition.ReqId = r.requisition_id;
                        requisition.Quantity = r.quantity;
                        requisition.StationaryName = r.stationery_name;
                        userRequisition.UserRequisitions.Add(requisition);
                        userRequisitionsList.Add(userRequisition);
                    }
                }
            }
            System.Diagnostics.Debug.WriteLine("check @@@@@@@@@@@@ loadAllPendingRequests:" + js.Serialize(userRequisitionsList));
            return js.Serialize(userRequisitionsList);
        }
        public static string MakeRequisition(object jsonParam)
        {
            User user = (User)HttpContext.Current.Session["user"];
            if (user == null)
            {
                return null;
            }
            int empId = user.id;

            String valueString = jsonParam.ToString();
            string[] values = valueString.Split('.');
               int stId= Convert.ToInt16(values[0]);
            int qty= Convert.ToInt16(values[1]);

            int depId = Convert.ToInt32(user.department);
            Requisition requisition = new Requisition();
            requisition.stationery = stId;
            requisition.quantity = qty;
            requisition.user_obj = empId;
            requisition.department = depId;
            requisition.user_approved_by = null;
            RequisitionController requisitionController = new RequisitionController();
               Message msg= requisitionController.actionCreateRequisition(requisition);
               if (msg.condition)
               {
               //return msg.message;
               return "success";
               }
               else
               {
               //return msg.message;
               return "fail";
               }

              // System.Diagnostics.Debug.WriteLine(" inside MakeRequisition " + msg);
               // return "Hi this is response from MakeRequisition";
        }