コード例 #1
0
        public async Task<ActionResult> popUpSearch(string keywordId, string keywordSearch, int maxRows, int pageStart)
        {
            string sql = "WITH cte AS ( ";
            sql += "SELECT ROW_NUMBER() OVER(ORDER BY productId) AS rn, ";
            sql += "productID, productCode, productName, unit ";
            sql += "FROM [dbo].[Products] a WITH(NOLOCK) ";
            if (keywordId != string.Empty && keywordSearch != string.Empty)
            {
                sql += "WHERE " + keywordId + " LIKE  '%" + keywordSearch + "%' ";
            }
            sql += ") ";
            sql += "SELECT * FROM cte ";
            string sqlAll = sql;
            sql += "WHERE rn BETWEEN " + ((pageStart * maxRows) - (maxRows - 1)) + " AND " + (pageStart * maxRows);

            DataTable dataAll = con.executeReader(sqlAll);
            ViewBag.totalRows = dataAll.Rows.Count;
            ViewBag.currentPage = pageStart;

            DataTable popUp = con.executeReader(sql);
            var model = new product();
            if (popUp != null)
            {
                foreach (DataRow dr in popUp.Rows)
                {
                    var editor = new product.listProduct()
                    {
                        productID = int.Parse(dr["productId"].ToString()),
                        productCode = dr["productCode"].ToString(),
                        productName = dr["productName"].ToString(),
                        unit = dr["unit"].ToString()
                    };
                    model.productList.Add(editor);
                }
                ViewBag.ProductPopUp = model.productList.ToList();
            }

            return PartialView("_PartialPageProductSearchSub");
        }
コード例 #2
0
        protected void loadDetail(string id, int deptId)
        {
            #region default header
            lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
            var usr = db.Users.Where(x => x.userID == lvm.userID).ToList();
            if(deptId == 0)
                deptId = usr[0].deptID;

            if (lvm.isAdmin == false)
                //ViewBag.Dept = new SelectList(db.departments.Where(x=>x.deptID==deptId).Select(x => new { x.deptID, x.deptName }).ToList(), "deptID", "deptName");
                ViewBag.Dept = new SelectList(db.divisis.Where(x => x.divisiID == deptId).Select(x => new { deptID = x.divisiID, deptName = x.divisiName }).ToList(), "deptID", "deptName");
            else
                //ViewBag.Dept = new SelectList(db.departments.Select(x => new { x.deptID, x.deptName }).ToList(), "deptID", "deptName");
                ViewBag.Dept = new SelectList(db.divisis.Select(x => new { deptID = x.divisiID, deptName = x.divisiName }).ToList(), "deptID", "deptName");
            #endregion

            var popUp = db.products.ToList();
            var modelProd = new product();
            if (popUp != null)
            {
                for (int i = 0; i < popUp.Count; i++ )
                {
                    var editor = new product.listProduct()
                    {
                        productID = popUp[i].productID,
                        productCode = popUp[i].productCode,
                        productName = popUp[i].productName,
                        unit = popUp[i].unit
                    };
                    modelProd.productList.Add(editor);
                }
                ViewBag.ProductPopUp = modelProd.productList.ToList();
            }
            ViewBag.totalRows = popUp.Count;

            ViewBag.VendorPopUp = db.vendors.ToList();
            ViewBag.totalRowsVendor = db.vendors.Count();
            
            var prod = new product();
            foreach (var g in db.products.ToList() as IEnumerable<Models.product>)
            {
                var editor = new product.listProduct()
                {
                    productID = g.productID,
                    productCode = g.productCode,
                    productName = g.productName,
                    unit = g.unit,
                    createdUser = g.createdUser,
                    createdDate = g.createdDate,
                    modifiedUser = g.modifiedUser,
                    modifiedDate = g.modifiedDate
                };
                prod.productList.Add(editor);
            }

            if(id != string.Empty)
            {
                var model = new purchaseRequestHeader();
                var tempDetail = db.purchaseRequestDetails.Where(x => x.prId == id).ToList();
                foreach (var a in tempDetail)
                {
                    int t_productID = a.productId;
                    string t_description = a.description.ToString();
                    int t_qty = a.qty.ToString() != "" ? Convert.ToInt32(a.qty.ToString().Replace('.', ',')) : 0;
                    string t_unit = a.unit.ToString();
                    int? t_vendorid = a.vendorId;

                    var editor = new purchaseRequestHeader.purchaseRequestDetail()
                    {
                        productId = t_productID,
                        description = t_description,
                        qty = t_qty,
                        unit = t_unit,
                        vendorId = t_vendorid
                    };
                    model.detailPurchaseRequest.Add(editor);
                }
                ViewData["dataDetail"] = model.detailPurchaseRequest.ToList();

                var g = db.products
                    .Join(db.purchaseRequestDetails.Where(x => x.prId == id), y => y.productID, z => z.productId, (y, z) => new { y })
                    .Select(c => new { c.y.productID, c.y.productCode, c.y.productName, c.y.unit, c.y.createdUser, c.y.createdDate, c.y.modifiedUser, c.y.modifiedDate }).ToList();

                prod.productList.Clear();
                for(int i=0; i<g.Count; i++)
                {
                    var editor = new product.listProduct()
                    {                        
                        productID = g[i].productID,
                        productCode = g[i].productCode,
                        productName = g[i].productName,
                        unit = g[i].unit,
                        createdUser = g[i].createdUser,
                        createdDate = g[i].createdDate,
                        modifiedUser = g[i].modifiedUser,
                        modifiedDate = g[i].modifiedDate
                    };
                    prod.productList.Add(editor);
                }
            }
            ViewBag.product = prod.productList.ToList();
        }