public List<CustomerHirerachy> GetAllCustomerHirerachy()
 {
     IDbConnection db = new OrmliteConnection().openConn();
     var lst = db.Select<CustomerHirerachy>().Where(p => p.Status == true).ToList();
     db.Close();
     return lst;
 }
        public ActionResult CancelSalesOrder(string data)
        {
            var dbConn = new OrmliteConnection().openConn();
            if (userAsset.ContainsKey("Insert") && userAsset["Insert"])
            {
                try
                {
                    string[] separators = { "@@" };
                    var listdata = data.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var item in listdata)
                    {
                        if (dbConn.Select<SOHeader>("Select * from SOHeader where Status <> N'Mới' AND SONumber = '"+item+"'").Count() > 0)
                        {
                            return Json(new { success = false, message = "Chỉ hủy được các mẫu tin có trạng thái Mới" });
                        }

                        dbConn.Update<SOHeader>(set: "Status = N'Hủy'", where: "SONumber = '" + item + "'");
                    }
                }
                catch (Exception e)
                {
                    return Json(new { success = false, message = e.Message });
                }
                return Json(new{success = true});
            }
            else{
                return Json(new { success = false, message = "Bạn không có quyền hủy." });
            }
        }
        public ActionResult CompletePicking(string data)
        {
            var dbConn = new OrmliteConnection().openConn();
            if (userAsset.ContainsKey("Update") && userAsset["Update"])
            {
                try
                {
                    string[] separators = { "@@" };
                    var listdata = data.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var item in listdata)
                    {
                        if (dbConn.Select<DC_AD_Picking_Header>(s => s.Status == "Hoàn thành" && s.PickingNumber == item).Count() > 0)
                        {
                            return Json(new { success = false, message = item + " đã được hoàn thành trước đó." });
                        }

                        if (dbConn.Select<DC_AD_Picking_Header>(s =>s.Status != "Đang giao hàng" && s.PickingNumber==item).Count() > 0)
                        {
                            return Json(new { success = false, message = item + " vui lòng nhập kho trước khi hoàn thành." });
                        }

                        dbConn.Update<DC_AD_Picking_Header>(set: "Status = N'Hoàn thành', UpdatedBy ='" + currentUser.UserID + "', UpdatedAt= '"+DateTime.Now+"'", where: "PickingNumber = '" + item + "'");
                        foreach (var so in dbConn.Select<DC_AD_Picking_Detail>(s => s.PickingNumber == item).ToList())
                        {
                            dbConn.Update<SOHeader>(set: "Status = N'Hoàn thành'", where: "SONumber = '" + so.SONumber + "'");
                        }
                        //dbConn.Update<DC_AD_SO_Header>(set: "Status = N'Hoàn thành'", where: "SONumber = '" + item + "'");
                    }
                }
                catch (Exception e)
                {
                    return Json(new { success = false, message = e.Message });
                }
                return Json(new { success = true });
            }
            else
            {
                return Json(new { success = false, message = "Bạn không có quyền hủy." });
            }
        }
Exemple #4
0
 public List<ActiveStatus> GetActiveStatus()
 {
     IDbConnection dbConn = new OrmliteConnection().openConn();
     var list = new List<ActiveStatus>();
     try
     {
         list = dbConn.Select<ActiveStatus>("SELECT StatusValue, StatusName,IsAllMerchant,IsAllDistric FROM vw_List_Active_Status");
     }
     catch (Exception)
     {
         throw;
     }
     finally { dbConn.Close(); }
     return list;
 }
        public ActionResult ConfirmCreate()
        {
            var dbConn = new OrmliteConnection().openConn();
            if (userAsset.ContainsKey("Insert") && userAsset["Insert"])
            {
                try
                {
                    string SONumber = Request["SONumber"];
                    var header = new SOHeader();
                    var detail = new SODetail();
                    if (string.IsNullOrEmpty(SONumber))
                    {
                        string datetimeSO = DateTime.Now.ToString("yyMMdd");
                        var existSO = dbConn.SingleOrDefault<SOHeader>("SELECT id, SONumber FROM SOHeader ORDER BY Id DESC");
                        if (existSO != null)
                        {
                            var nextNo = Int32.Parse(existSO.SONumber.Substring(8, 5)) + 1;
                            SONumber = "SO" + datetimeSO + String.Format("{0:00000}", nextNo);
                        }
                        else
                        {
                            SONumber = "SO" + datetimeSO + "00001";
                        }
                    }
                    if (!string.IsNullOrEmpty(Request["SODate"]))
                    {
                        DateTime fromDateValue;
                        if (!DateTime.TryParseExact(Request["SODate"], "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDateValue))
                        {
                            return Json(new { message = "Ngày tạo không đúng." });
                        }

                    }
                    if (dbConn.Select<DC_OCM_Merchant>(p => p.MerchantID == Request["MerchantID"]).Count() <= 0)
                    {
                        return Json(new { success = false, message = "Nhà cung cấp không tồn tại." });
                    }

                    if (dbConn.Select<SODetail>(p => p.SONumber == SONumber).Count() > 0)
                    {
                        if (!string.IsNullOrEmpty(Request["ItemCode"]))
                        {
                            if (dbConn.Select<Products>(p => p.Code == Request["ItemCode"]).Count() <= 0)
                            {
                                return Json(new { success = false, message = "Ấn phẩm không tồn tại." });
                            }
                            var itemcode = dbConn.Select<Products>(s => s.Code == Request["ItemCode"]).FirstOrDefault();
                            var itemunit = dbConn.Select<Products>(s => s.UnitID == itemcode.Unit).FirstOrDefault();
                            if (dbConn.Select<SODetail>(p => p.ItemCode == Request["ItemCode"] && p.SONumber == SONumber).Count() > 0)
                            {
                                var success = dbConn.Execute(@"UPDATE SODetail Set Qty = @Qty, TotalAmt =@TotalAmt ,UpdatedAt = @UpdatedAt, UpdatedBy =  @UpdatedBy, Price = @Price
                                WHERE SONumber = '" + SONumber + "' AND ItemCode = '" + Request["ItemCode"] + "'", new
                                    {
                                        Qty = dbConn.Select<SODetail>(s => s.ItemCode == Request["ItemCode"] && s.SONumber == SONumber).Sum(s => s.Qty) + int.Parse(Request["Qty"]),
                                        TotalAmt = itemcode != null ? itemcode.VATPrice * (dbConn.Select<SODetail>(s => s.ItemCode == Request["ItemCode"] && s.SONumber == SONumber).Sum(s => s.Qty) + int.Parse(Request["Qty"])) : 0,
                                        Price = itemcode.VATPrice,
                                        UpdatedBy = currentUser.UserID,
                                        UpdatedAt = DateTime.Now,
                                    }) == 1;
                                if (!success)
                                {
                                    return Json(new { success = false, message = "Không thể lưu" });
                                }
                            }
                            else
                            {
                                detail.SONumber = SONumber;
                                detail.ItemCode = !string.IsNullOrEmpty(Request["ItemCode"]) ? Request["ItemCode"] : "";
                                detail.ItemName = !string.IsNullOrEmpty(itemcode.Name) ? itemcode.Name : "";
                                detail.Price = itemcode != null ? itemcode.VATPrice : 0;
                                detail.Qty = int.Parse(Request["Qty"]);
                                detail.TotalAmt = itemcode.VATPrice * int.Parse(Request["Qty"]);
                                detail.UnitID = !string.IsNullOrEmpty(itemunit.UnitID) ? itemunit.UnitID : "";
                                detail.UnitName = !string.IsNullOrEmpty(itemunit.UnitName) ? itemunit.UnitName : "";
                                detail.Note = "";
                                detail.Status = "";
                                detail.CreatedBy = currentUser.UserID;
                                detail.CreatedAt = DateTime.Now;
                                detail.UpdatedBy = "";
                                detail.UpdatedAt = DateTime.Parse("1900-01-01");
                                dbConn.Insert<SODetail>(detail);
                            }
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(Request["ItemCode"]) || dbConn.Select<Products>(p => p.Code == Request["ItemCode"]).Count() <= 0)
                        {
                            return Json(new { success = false, message = "Ấn phẩm không tồn tại." });
                        }
                        var itemcode = dbConn.Select<Products>(s => s.Code == Request["ItemCode"]).FirstOrDefault();
                        var itemunit = dbConn.Select<Products>(s => s.UnitID == itemcode.Unit).FirstOrDefault();
                        detail.SONumber = SONumber;
                        detail.ItemCode = !string.IsNullOrEmpty(Request["ItemCode"]) ? Request["ItemCode"] : "";
                        detail.ItemName = !string.IsNullOrEmpty(itemcode.Name) ? itemcode.Name : "";
                        detail.Price = itemcode != null ? itemcode.VATPrice :0 ;
                        detail.Qty = int.Parse(Request["Qty"]);
                        detail.TotalAmt = itemcode.VATPrice * int.Parse(Request["Qty"]);
                        detail.UnitID = !string.IsNullOrEmpty(itemunit.UnitID) ? itemunit.UnitID : "";
                        detail.UnitName = !string.IsNullOrEmpty(itemunit.UnitName) ? itemunit.UnitName : "";
                        detail.Note = "";
                        detail.Status = "";
                        detail.CreatedBy = currentUser.UserID;
                        detail.CreatedAt = DateTime.Now;
                        detail.UpdatedBy = "";
                        detail.UpdatedAt = DateTime.Parse("1900-01-01");
                        dbConn.Insert<SODetail>(detail);

                    }
                    if (dbConn.Select<SOHeader>(p => p.SONumber == SONumber).Count() > 0)
                    {
                        var success = dbConn.Execute(@"UPDATE SOHeader Set TotalQty = @TotalQty, TotalAmt =@TotalAmt ,UpdatedAt = @UpdatedAt, UpdatedBy =  @UpdatedBy,
                        MerchantID = @MerchantID, SODate = @SODate , WHLID =@WHLID, WHID =@WHID WHERE SONumber = '" + SONumber + "'", new
                                {
                                    TotalQty = dbConn.Select<SODetail>(s =>s.SONumber == SONumber).Sum(s => s.Qty),
                                    TotalAmt = dbConn.Select<SODetail>(s => s.SONumber == SONumber).Sum(s => s.TotalAmt),
                                    SODate = !string.IsNullOrEmpty(Request["SODate"]) ? DateTime.Parse(DateTime.ParseExact(Request["SODate"], "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")) : DateTime.Now,
                                    WHID = !string.IsNullOrEmpty(Request["WHID"]) ? Request["WHID"] : "",
                                    WHLID = !string.IsNullOrEmpty(Request["WHLID"]) ? Request["WHLID"] : "",
                                    MerchantID = !string.IsNullOrEmpty(Request["MerchantID"]) ? Request["MerchantID"] : "",
                                    UpdatedBy = currentUser.UserID,
                                    UpdatedAt = DateTime.Now,
                                }) == 1;
                        if (!success)
                        {
                            return Json(new { success = false, message = "Không thể lưu" });
                        }
                    }
                    else
                    {
                        header.SONumber = SONumber;
                        header.SODate = !string.IsNullOrEmpty(Request["SODate"]) ? DateTime.Parse(DateTime.ParseExact(Request["SODate"], "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")) : DateTime.Now;
                        header.VendorID = !string.IsNullOrEmpty(Request["MerchantID"]) ? Request["MerchantID"] : "";
                        header.Note = !string.IsNullOrEmpty(Request["Note"]) ? Request["Note"] : "";
                        header.TotalQty = dbConn.Select<SODetail>(s =>s.SONumber == SONumber).Sum(s => s.Qty);
                        header.WHID = Request["WHID"];
                        header.Status = "Mới";
                        header.WHLID = !string.IsNullOrEmpty(Request["WHLID"]) ? Request["WHLID"] : "";
                        header.TotalAmt = dbConn.Select<SODetail>(s => s.SONumber == SONumber).Sum(s => s.TotalAmt);
                        header.CreatedBy = currentUser.UserID;
                        header.CreatedAt = DateTime.Now;
                        header.UpdatedBy = "";
                        header.UpdatedAt = DateTime.Parse("1900-01-01");
                        dbConn.Insert<SOHeader>(header);
                    }

                    return Json(new { success = true, SONumber = SONumber });
                }
                catch (Exception e)
                {
                    return Json(new { success = false, message = e.Message });
                }
            }

            else
            {
                return Json(new { success = false, message = "Không có quyền tạo." });
            }
        }
 public ActionResult ReadHeader([DataSourceRequest] DataSourceRequest request)
 {
     var dbConn = new OrmliteConnection().openConn();
     var data = new List<SOHeader>();
     if(request.Filters.Any())
     {
         var where = new KendoApplyFilter().ApplyFilter(request.Filters[0]);
         data = dbConn.Select<SOHeader>(where);
     }
     else{
         data = dbConn.Select<SOHeader>();
     }
     return Json(data.ToDataSourceResult(request));
 }
 public ActionResult ReadDetail([DataSourceRequest] DataSourceRequest request, string text)
 {
     var dbConn = new OrmliteConnection().openConn();
     var data = dbConn.Select<SODetail>("SELECT * FROM SODetail WHERE SONumber ='" + text + "'");
     return Json(data.ToDataSourceResult(request));
 }
 public ActionResult PartialCustomer()
 {
     if (userAsset.ContainsKey("View") && userAsset["View"])
     {
         IDbConnection dbConn = new OrmliteConnection().openConn();
         var dict = new Dictionary<string, object>();
         dict["asset"] = userAsset;
         dict["activestatus"] = new CommonLib().GetActiveStatus();
         dict["listprovince"] = dbConn.Select<Master_Territory>("Select TerritoryID,TerritoryName From Master_Territory where Level ='Province'");
         dict["listdistrict"] = dbConn.Select<Master_Territory>("Select TerritoryID,TerritoryName From Master_Territory where Level ='District'");
         dbConn.Close();
         return PartialView("_Customer", dict);
     }
     else
         return RedirectToAction("NoAccess", "Error");
 }
        public ActionResult PartialRole()
        {
            if (userAsset.ContainsKey("View") && userAsset["View"])
            {
                IDbConnection dbConn = new OrmliteConnection().openConn();
                var dict = new Dictionary<string, object>();
                dict["asset"] = userAsset;
                dict["activestatus"] = new CommonLib().GetActiveStatus();
                dict["user"] = dbConn.Select<Auth_User>(p => p.IsActive == true);
                dict["listWH"] = dbConn.Select<WareHouse>(p => p.Status == true);
                dict["listWHL"] = dbConn.Select<WareHouseLocation>(p => p.Status == true);
                dict["listUnit"] = dbConn.Select<DC_AD_Unit>(p => p.Status == true);
                dbConn.Close();

                return PartialView("_ListPublication", dict);
            }
            else
                return RedirectToAction("NoAccess", "Error");
        }
Exemple #10
0
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);
            if (this.User.Identity.IsAuthenticated)
            {
                IDbConnection dbConn = new OrmliteConnection().openConn();
                lstAssetDefault = InitAssetDefault();
                currentUser     = dbConn.GetByIdOrDefault <Auth_User>(User.Identity.Name);
                currentUserRole = dbConn.SqlList <Auth_Role>("EXEC p_Auth_UserInRole_Select_By_UserID @UserID", new { UserID = User.Identity.Name });
                string controllerName = this.GetType().Name;
                controllerName = controllerName.Substring(0, controllerName.IndexOf("Controller"));
                var lstAsset = new List <Auth_Action>();

                // Get MenuID from controller name
                string menuID = dbConn.SingleOrDefault <Auth_Menu>("ControllerName = {0}", controllerName).MenuID;
                foreach (var g in currentUserRole)
                {
                    // Get List Asset
                    var temp = dbConn.Select <Auth_Action>(p => p.RoleID == g.RoleID && p.MenuID == menuID);
                    if (temp.Count > 0)
                    {
                        lstAsset.AddRange(temp);
                    }
                }
                if (lstAsset.Count == 0)
                {
                    var item = new Auth_Action();
                    item.MenuID       = menuID;
                    item.Note         = "";
                    item.RowCreatedAt = DateTime.Now;
                    item.RowCreatedBy = "System";
                    if (currentUser.UserID == ConfigurationManager.AppSettings["superadmin"])
                    {
                        item.RoleID    = 1;
                        item.IsAllowed = true;
                        foreach (var asset in lstAssetDefault)
                        {
                            item.Action = asset;
                            dbConn.Insert <Auth_Action>(item);
                        }
                    }
                    else
                    {
                        item.RoleID    = currentUserRole.FirstOrDefault().RoleID;
                        item.IsAllowed = false;
                        foreach (var asset in lstAssetDefault)
                        {
                            item.Action = asset;
                            dbConn.Insert <Auth_Action>(item);
                        }
                    }
                }
                else
                {
                    foreach (var g in currentUserRole)
                    {
                        // Asset
                        var lst = lstAsset.Where(p => p.RoleID == g.RoleID).ToList();
                        foreach (var item in lst)
                        {
                            if (!userAsset.ContainsKey(item.Action))
                            {
                                userAsset.Add(item.Action, item.IsAllowed);
                            }
                            else if (item.IsAllowed)
                            {
                                userAsset.Remove(item.Action);
                                userAsset.Add(item.Action, item.IsAllowed);
                            }
                        }
                    }
                }
                // Get Asset View Menu
                foreach (var g in currentUserRole)
                {
                    var lstView = dbConn.Select <Auth_Action>(p => p.RoleID == g.RoleID && p.Action == "View");
                    //var lstView = new Auth_Menu().GetMenuByRoleID(g.RoleID);
                    foreach (var i in lstView)
                    {
                        if (!dictView.ContainsKey("menu_" + i.MenuID))
                        {
                            if (i.IsAllowed)
                            {
                                dictView.Add("menu_" + i.MenuID, true);
                            }
                        }
                    }
                }
                ViewData["menuView"] = dictView;
                dbConn.Close();
            }
        }
 public ActionResult GetTransByID(string id)
 {
     IDbConnection dbConn = new OrmliteConnection().openConn();
     try
     {
         var listStran = dbConn.Select<DC_LG_Contract_Transporter>("ContractID={0}",id);
         return Json(new { success = true, listtran = listStran });
     }
     catch (Exception e)
     {
         return Json(new { success = false, message = e.Message });
     }
     finally { dbConn.Close(); }
 }
 public ActionResult Read([DataSourceRequest]DataSourceRequest request)
 {
     var dbConn = new OrmliteConnection().openConn();
     string whereCondition = "";
     if (request.Filters.Count > 0)
     {
         whereCondition = new KendoApplyFilter().ApplyFilter(request.Filters[0]);
     }
     var data = dbConn.Select<DC_RuleCheck>(whereCondition);
     return Json(data.ToDataSourceResult(request));
 }
        public ActionResult CreatePO(string data, string printer, string delivery)
        {
            var dbConn = new OrmliteConnection().openConn();
            if (userAsset.ContainsKey("Insert") && userAsset["Insert"])
            {
                try
                {
                    string[] separators = { "@@" };
                    var listdata = data.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    string PONumber = "";
                    string datetimeSO = DateTime.Now.ToString("yyMMdd");
                    var existSO = dbConn.SingleOrDefault<DC_AD_PO_Header>("SELECT id, PONumber FROM DC_AD_PO_Header ORDER BY Id DESC");
                    if (existSO != null)
                    {
                        var nextNo = Int32.Parse(existSO.PONumber.Substring(8, 5)) + 1;
                        PONumber = "PO" + datetimeSO + String.Format("{0:00000}", nextNo);
                    }
                    else
                    {
                        PONumber = "PO" + datetimeSO + "00001";
                    }
                    if (!string.IsNullOrEmpty(delivery))
                    {
                        DateTime fromDateValue;
                        if (!DateTime.TryParseExact(delivery, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDateValue))
                        {
                            return Json(new { message = "Ngày tạo không đúng." });
                        }
                    }
                    var detail = new DC_AD_PO_Detail();
                    foreach (var item in listdata)
                    {
                        if (dbConn.Select<SOHeader>(s => s.Status != "Mới" && s.SONumber == item).Count() > 0)
                        {
                            return Json(new { success = false, message = "Không thể đặt hàng." });
                        }
                        foreach (var dtSO in dbConn.Select<SODetail>(s => s.SONumber == item).ToList())
                        {
                            if (dbConn.Select<DC_AD_PO_Detail>(s => s.PONumber == PONumber && s.ItemCode == dtSO.ItemCode).Count() > 0)
                            {
                                var success = dbConn.Execute(@"UPDATE DC_AD_PO_Detail Set Qty = @Qty, TotalAmt =@TotalAmt ,UpdatedAt = @UpdatedAt, UpdatedBy =  @UpdatedBy, Price = @Price
                                    WHERE PONumber = '" + PONumber + "' AND ItemCode = '" + dtSO.ItemCode + "'", new
                                    {
                                        Qty = dbConn.Select<DC_AD_PO_Detail>(s => s.PONumber == PONumber && s.ItemCode == dtSO.ItemCode).Sum(s => s.Qty) + dtSO.Qty,
                                        TotalAmt = dbConn.Select<DC_AD_PO_Detail>(s => s.PONumber == PONumber && s.ItemCode == dtSO.ItemCode).Sum(s => s.TotalAmt)+dtSO.TotalAmt,
                                        Price = dtSO.Price,
                                        UpdatedBy = currentUser.UserID,
                                        UpdatedAt = DateTime.Now,
                                    }) == 1;
                                if (!success)
                                {
                                    return Json(new { success = false, message = "Không thể lưu" });
                                }
                            }
                            else
                            {
                                detail.PONumber = PONumber;
                                detail.ItemCode = !string.IsNullOrEmpty(dtSO.ItemCode) ? dtSO.ItemCode : "";
                                detail.ItemName = !string.IsNullOrEmpty(dtSO.ItemName) ? dtSO.ItemName : "";
                                detail.Price = dtSO.Price;
                                detail.Qty = dtSO.Qty;
                                detail.TotalAmt = dtSO.TotalAmt;
                                detail.UnitID = !string.IsNullOrEmpty(dtSO.UnitID) ? dtSO.UnitID : "";
                                detail.UnitName = !string.IsNullOrEmpty(dtSO.UnitName) ? dtSO.UnitName : "";
                                detail.Note = "";
                                detail.Status = "Mới";
                                detail.CreatedBy = currentUser.UserID;
                                detail.CreatedAt = DateTime.Now;
                                detail.UpdatedBy = "";
                                detail.UpdatedAt = DateTime.Parse("1900-01-01");
                                dbConn.Insert<DC_AD_PO_Detail>(detail);
                            }
                        }
                        dbConn.Update<SOHeader>(set: "Status = N'Đã đặt hàng'", where: "SONumber = '" + item + "'");
                    }
                    var header = new DC_AD_PO_Header();
                    header.PONumber = PONumber;
                    header.PODate = DateTime.Now;
                    header.DeliveryDate = !string.IsNullOrEmpty(delivery) ? DateTime.Parse(DateTime.ParseExact(delivery, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")) : DateTime.Now;
                    header.PrinterID = printer;
                    header.PrinterName = dbConn.Select<DC_AD_Printer>(s => s.PrinterID == printer).FirstOrDefault().PrinterName;
                    header.TotalQty = dbConn.Select<DC_AD_PO_Detail>(s => s.PONumber == PONumber).Sum(s => s.Qty);
                    header.TotalAmt = dbConn.Select<DC_AD_PO_Detail>(s => s.PONumber == PONumber).Sum(s => s.TotalAmt);
                    header.Note = "";
                    header.Status = "Nhà in đang xử lý";
                    header.CreatedBy = currentUser.UserID;
                    header.CreatedAt = DateTime.Now;
                    header.UpdatedBy = "";
                    header.UpdatedAt = DateTime.Parse("1900-01-01");
                    dbConn.Insert<DC_AD_PO_Header>(header);

                }
                catch (Exception ex)
                {
                    return Json(new { success = false, message = ex.Message });
                }
                return Json(new { success = true });
            }
            else
            {
                return Json(new { success = false, message = "Không có quyền tạo." });
            }
        }
Exemple #14
0
 //========================================== Tab Phân quyền chức năng =================================
 public ActionResult ReadAction([DataSourceRequest]DataSourceRequest request, int roleid, string menuid)
 {
     var data = new List<Auth_Action>();
     if (roleid > 0 && !string.IsNullOrEmpty(menuid))
     {
         IDbConnection db = new OrmliteConnection().openConn();
         data = db.Select<Auth_Action>(p => p.RoleID == roleid && p.MenuID == menuid &&
                                             p.Action != "View" &&
                                             p.Action != "Insert" &&
                                             p.Action != "Update" &&
                                             p.Action != "Delete" &&
                                             p.Action != "Export" &&
                                             p.Action != "Import");
         db.Close();
     }
     return Json(data.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
 }
Exemple #15
0
        //public JsonResult GetMenu([DataSourceRequest] DataSourceRequest request)
        //{
        //    IDbConnection db = new OrmliteConnection().openConn();
        //    try
        //    {
        //        var listMenu = db.Select<Auth_Menu>(p => p.IsVisible == true).OrderBy(p => p.MenuIndex).ToList();
        //        DataSourceResult dsr = new DataSourceResult();
        //        dsr.Data = listMenu;
        //        return Json(dsr, JsonRequestBehavior.AllowGet);
        //    }
        //    catch (Exception e)
        //    {
        //        return Json(new { success = false, message = e.Message });
        //    }
        //    finally { db.Close(); }
        //}
        //[HttpPost]
        public JsonResult GetMenu(string action, int roleID)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                //select list menu cha
                List<Auth_Menu> lstFirstMenu = db.Select<Auth_Menu>("IsVisible = 1 AND ParentMenuID ='' AND MenuID <> 'Home'").OrderBy(p => p.MenuIndex).ToList();
                List<Auth_Menu> allAuthMenu = db.Select<Auth_Menu>("IsVisible = 1  AND MenuID <> 'Home'").OrderBy(p => p.MenuIndex).ToList();

                var listAction = new List<Auth_Menu>();
                if (!string.IsNullOrEmpty(action))
                {
                    listAction = db.SqlList<Auth_Menu>("p_Auth_Menu_Select_By_Action '" + action + "', " + roleID);
                }

                List<AuthMenuViewModel> lstMenuView = new List<AuthMenuViewModel>();
                foreach (Auth_Menu der in lstFirstMenu)
                {
                    AuthMenuViewModel node = new AuthMenuViewModel();
                    node.id = der.MenuID;
                    node.text = der.MenuName;
                    node.items = new List<AuthMenuViewModel>();
                    AddChidrenNode(ref node, allAuthMenu,listAction);
                    lstMenuView.Add(node);
                }
                return Json(new { success = true, Data = lstMenuView });
            }
            catch (Exception e)
            {
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
Exemple #16
0
 public ActionResult GetByID(int id)
 {
     IDbConnection dbConn = new OrmliteConnection().openConn();
     try
     {
         var data = dbConn.GetByIdOrDefault<Auth_Role>(id);
         var listUserRole = dbConn.Select<Auth_UserInRole>(p => p.RoleID == id);
         return Json(new { success = true, data = data, listuser = listUserRole });
     }
     catch (Exception e)
     {
         return Json(new { success = false, message = e.Message });
     }
     finally { dbConn.Close(); }
 }
 public ActionResult GetCompanyByID(string id)
 {
     IDbConnection dbConn = new OrmliteConnection().openConn();
     try
     {
         var listCompany = dbConn.Select<Company>("CompanyID={0}", id);
         return Json(new { success = true, listcompany = listCompany });
     }
     catch (Exception e)
     {
         return Json(new { success = false, message = e.Message });
     }
     finally { dbConn.Close(); }
 }
Exemple #18
0
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);
            if (this.User.Identity.IsAuthenticated)
            {
                IDbConnection dbConn = new OrmliteConnection().openConn();
                lstAssetDefault = InitAssetDefault();
                currentUser = dbConn.GetByIdOrDefault<Auth_User>(User.Identity.Name);
                currentUserRole = dbConn.SqlList<Auth_Role>("EXEC p_Auth_UserInRole_Select_By_UserID @UserID", new { UserID = User.Identity.Name });
                string controllerName = this.GetType().Name;
                controllerName = controllerName.Substring(0, controllerName.IndexOf("Controller"));
                var lstAsset = new List<Auth_Action>();

                // Get MenuID from controller name
                string menuID = dbConn.SingleOrDefault<Auth_Menu>("ControllerName = {0}", controllerName).MenuID;
                foreach (var g in currentUserRole)
                {
                    // Get List Asset
                    var temp = dbConn.Select<Auth_Action>(p => p.RoleID == g.RoleID && p.MenuID == menuID);
                    if (temp.Count > 0)
                        lstAsset.AddRange(temp);
                }
                if(lstAsset.Count == 0)
                {
                    var item = new Auth_Action();
                    item.MenuID = menuID;
                    item.Note = "";
                    item.RowCreatedAt = DateTime.Now;
                    item.RowCreatedBy = "System";
                    if (currentUser.UserID == ConfigurationManager.AppSettings["superadmin"])
                    {
                        item.RoleID = 1;
                        item.IsAllowed = true;
                        foreach(var asset in lstAssetDefault)
                        {
                            item.Action = asset;
                            dbConn.Insert<Auth_Action>(item);
                        }
                    }
                    else
                    {
                        item.RoleID = currentUserRole.FirstOrDefault().RoleID;
                        item.IsAllowed = false;
                        foreach (var asset in lstAssetDefault)
                        {
                            item.Action = asset;
                            dbConn.Insert<Auth_Action>(item);
                        }
                    }
                }
                else
                {
                    foreach (var g in currentUserRole)
                    {
                        // Asset
                        var lst = lstAsset.Where(p => p.RoleID == g.RoleID).ToList();
                        foreach(var item in lst)
                        {
                            if (!userAsset.ContainsKey(item.Action))
                                userAsset.Add(item.Action, item.IsAllowed);
                            else if(item.IsAllowed)
                            {
                                userAsset.Remove(item.Action);
                                userAsset.Add(item.Action, item.IsAllowed);
                            }
                        }
                    }
                }
                // Get Asset View Menu
                foreach (var g in currentUserRole)
                {
                    var lstView = dbConn.Select<Auth_Action>(p => p.RoleID == g.RoleID && p.Action == "View");
                    //var lstView = new Auth_Menu().GetMenuByRoleID(g.RoleID);
                    foreach (var i in lstView)
                    {
                        if (!dictView.ContainsKey("menu_" + i.MenuID))
                        {
                            if(i.IsAllowed)
                            {
                                dictView.Add("menu_" + i.MenuID, true);
                            }
                        }
                    }
                }
                ViewData["menuView"] = dictView;
                dbConn.Close();
            }
        }
Exemple #19
0
 public List<Auth_Menu> GetAllMenu()
 {
     IDbConnection db = new OrmliteConnection().openConn();
     var lst = db.Select<Auth_Menu>().Where(p => p.IsVisible == true).ToList();
     db.Close();
     return lst;
 }
 //
 // GET: /SalesPerson/
 public ActionResult PartialSalesPerson()
 {
     if (userAsset.ContainsKey("View") && userAsset["View"])
     {
         IDbConnection dbConn = new OrmliteConnection().openConn();
         var dict = new Dictionary<string, object>();
         dict["asset"] = userAsset;
         dict["activestatus"] = new CommonLib().GetActiveStatus();
         //dict["listSalesPerson"] = dbConn.Select<SalesPerson>(p => p.Status == true);
         dict["listCompany"] = dbConn.Select<Company>(p => p.Status == true);
         dbConn.Close();
         return PartialView("_SalesPerson", dict);
     }
     else
         return RedirectToAction("NoAccess", "Error");
 }
        //
        // GET: /DeliveryManage/Details/5
        public ActionResult Read([DataSourceRequest]DataSourceRequest request)
        {
            var dbConn = new OrmliteConnection().openConn();
            string whereCondition = "";
            if (request.Filters.Count > 0)
            {
                whereCondition =  new KendoApplyFilter().ApplyFilter(request.Filters[0]);
            }
            var data = dbConn.Select<DC_LG_Transporter>(whereCondition).OrderBy(p=>p.Weight);

            return Json(data.ToDataSourceResult(request));
        }
 public ActionResult PartialContract()
 {
     if (userAsset.ContainsKey("View") && userAsset["View"])
     {
         IDbConnection dbConn = new OrmliteConnection().openConn();
         var dict = new Dictionary<string, object>();
         dict["asset"] = userAsset;
         dict["activestatus"] = new CommonLib().GetActiveStatus();
         dict["listTranporter"] = dbConn.Select<DC_LG_Transporter>(p => p.Status == true);
         //dict["listContractTransporter"] = new DC_LG_Contract().GetList(" AND 1=1");
         dbConn.Close();
         return PartialView("_Contract", dict);
     }
     else
         return RedirectToAction("NoAccess", "Error");
 }
        public ActionResult Export([DataSourceRequest]DataSourceRequest request)
        {
            if (userAsset["Export"])
            {
                using (var dbConn = new OrmliteConnection().openConn())
                {
                    //using (ExcelPackage excelPkg = new ExcelPackage())
                    FileInfo fileInfo = new FileInfo(Server.MapPath(@"~\ExportTemplate\DanhMucAnPham.xlsx"));
                    var excelPkg = new ExcelPackage(fileInfo);

                    string fileName = "ThongTinKho_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx";
                    string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

                    var data = new List<Products>();
                    if (request.Filters.Any())
                    {
                        var where = new KendoApplyFilter().ApplyFilter(request.Filters[0], "data.");
                        //data = dbConn.Select<Products>(where);
                        data = dbConn.Query<Products>("p_SelectDC_AD_Item_Export", new { WhereCondition = where}, commandType:System.Data.CommandType.StoredProcedure).ToList();
                    }
                    else
                    {
                        //data = dbConn.Select<Products>();
                        data = dbConn.Query<Products>("p_SelectDC_AD_Item_Export", new { WhereCondition = "1=1" }, commandType: System.Data.CommandType.StoredProcedure).ToList();
                    }

                    ExcelWorksheet expenseSheet = excelPkg.Workbook.Worksheets["Data"];

                    int rowData = 1;

                    foreach (var item in data)
                    {
                        int i = 1;
                        rowData++;
                        expenseSheet.Cells[rowData, i++].Value = item.Code;
                        expenseSheet.Cells[rowData, i++].Value = item.Name;
                        expenseSheet.Cells[rowData, i++].Value = item.Size;
                        expenseSheet.Cells[rowData, i++].Value = item.VATPrice;
                        expenseSheet.Cells[rowData, i++].Value = item.Type;
                        expenseSheet.Cells[rowData, i++].Value = item.UnitName+"/"+item.UnitID;
                        expenseSheet.Cells[rowData, i++].Value = item.WHName +"/"+item.WHID;
                        expenseSheet.Cells[rowData, i++].Value = item.WHLName + "/" +item.WHLID;
                        expenseSheet.Cells[rowData, i++].Value = item.ShapeTemplate;
                        if (item.Status == true)
                        {
                            expenseSheet.Cells[rowData, i++].Value = "Đang hoạt động";
                        }
                        else
                        {
                            expenseSheet.Cells[rowData, i++].Value = "Ngưng hoạt động";
                        }
                        expenseSheet.Cells[rowData, i++].Value = item.CreatedBy;
                        expenseSheet.Cells[rowData, i++].Value = item.CreatedAt;
                        expenseSheet.Cells[rowData, i++].Value = item.UpdatedBy;
                        if (item.UpdatedAt != DateTime.Parse("1900-01-01"))
                        {
                            expenseSheet.Cells[rowData, i++].Value = item.UpdatedAt;
                        }
                        else
                        {
                            expenseSheet.Cells[rowData, i++].Value = "";
                        }
                        //expenseSheet.Cells[rowData, i++].Value = item.RowLastUpdatedTime;
                    }
                    expenseSheet = excelPkg.Workbook.Worksheets["Warehouse"];
                    var listWH = dbConn.Select<WareHouse>("SELECT * FROM WareHouse WHERE Status = 1");
                    rowData = 1;
                    foreach (var item in listWH)
                    {
                        int i = 1;
                        rowData++;
                        expenseSheet.Cells[rowData, i++].Value = item.WHName + "/" + item.WHID;
                    }
                    expenseSheet = excelPkg.Workbook.Worksheets["Location"];
                    var listWHL = dbConn.Select<WareHouseLocation>("SELECT * FROM WareHouseL WHERE Status = 1");
                    rowData = 1;
                    foreach (var item in listWHL)
                    {
                        int i = 1;
                        rowData++;
                        expenseSheet.Cells[rowData, i++].Value = item.WHLName + "/" + item.WHLID;
                    }
                    expenseSheet = excelPkg.Workbook.Worksheets["Unit"];
                    var listUnit = dbConn.Select<DC_AD_Unit>("SELECT * FROM DC_AD_Unit WHERE Status = 1");
                    rowData = 1;
                    foreach (var item in listUnit)
                    {
                        int i = 1;
                        rowData++;
                        expenseSheet.Cells[rowData, i++].Value = item.UnitName + "/" + item.UnitID;
                    }

                    MemoryStream output = new MemoryStream();
                    excelPkg.SaveAs(output);
                    output.Position = 0;
                    return File(output.ToArray(), contentType, fileName);
                }
            }
            else
            {
                return Json(new { success = false });
            }
        }
        public ActionResult ExportWH([DataSourceRequest]DataSourceRequest request)
        {
            if (userAsset["Export"])
            {
                using (var dbConn = new OrmliteConnection().openConn())
                {
                    //using (ExcelPackage excelPkg = new ExcelPackage())
                    FileInfo fileInfo = new FileInfo(Server.MapPath(@"~\ExportTemplate\ThongTinKho.xlsx"));
                    var excelPkg = new ExcelPackage(fileInfo);

                    string fileName = "ThongTinKho_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx";
                    string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

                    var data = new List<WareHouse>();
                    if (request.Filters.Any())
                    {
                        var where = new KendoApplyFilter().ApplyFilter(request.Filters[0]);
                        data = dbConn.Select<WareHouse>(where);
                    }
                    else
                    {
                        data = dbConn.Select<WareHouse>();
                    }

                    ExcelWorksheet expenseSheet = excelPkg.Workbook.Worksheets["Data"];

                    int rowData = 1;

                    foreach (var item in data)
                    {
                        int i = 1;
                        rowData++;
                        expenseSheet.Cells[rowData, i++].Value = item.WHID;
                        expenseSheet.Cells[rowData, i++].Value = item.WHName;
                        expenseSheet.Cells[rowData, i++].Value = item.Address;
                        expenseSheet.Cells[rowData, i++].Value = item.WHKeeper;
                        expenseSheet.Cells[rowData, i++].Value = item.Note;
                        if (item.Status == true)
                        {
                            expenseSheet.Cells[rowData, i++].Value = "Đang hoạt động";
                        }
                        else
                        {
                            expenseSheet.Cells[rowData, i++].Value = "Ngưng hoạt động";
                        }
                        expenseSheet.Cells[rowData, i++].Value = item.CreatedBy;
                        expenseSheet.Cells[rowData, i++].Value = item.CreatedAt;
                        expenseSheet.Cells[rowData, i++].Value = item.UpdatedBy;
                        if (item.UpdatedAt != DateTime.Parse("1900-01-01"))
                        {
                            expenseSheet.Cells[rowData, i++].Value = item.UpdatedAt;
                        }
                        else
                        {
                            expenseSheet.Cells[rowData, i++].Value = "";
                        }
                        //expenseSheet.Cells[rowData, i++].Value = item.RowLastUpdatedTime;
                    }

                    MemoryStream output = new MemoryStream();
                    excelPkg.SaveAs(output);
                    output.Position = 0;
                    return File(output.ToArray(), contentType, fileName);
                }
            }
            else
            {
                return Json(new { success = false });
            }
        }
        public ActionResult GetBySONumber(string id)
        {
            try
            {
                var dbConn = new OrmliteConnection().openConn();
                var data = dbConn.Select<SOHeader>("SELECT * FROM SOHeader WHERE SONumber ='" + id + "'").FirstOrDefault();
                return Json(data, JsonRequestBehavior.AllowGet);

            }
            catch (Exception e)
            {
                return Json(new { success = false, message = e.Message });
            }
        }
 public FileResult Export([DataSourceRequest]DataSourceRequest request)
 {
     ExcelPackage pck = new ExcelPackage(new FileInfo(Server.MapPath("~/ExportTemplate/DeliveryUOM.xlsx")));
     ExcelWorksheet ws = pck.Workbook.Worksheets["Data"];
     if (userAsset["Export"])
     {
         string whereCondition = "";
         if (request.Filters.Count > 0)
         {
             whereCondition =  new KendoApplyFilter().ApplyFilter(request.Filters[0]);
         }
         IDbConnection db = new OrmliteConnection().openConn();
         var lstResult = db.Select<DC_LG_Transporter>(whereCondition);
         int rowNum = 2;
         foreach (var item in lstResult)
         {
             ws.Cells["A" + rowNum].Value = item.TransporterID;
             ws.Cells["B" + rowNum].Value = item.TransporterName;
             ws.Cells["C" + rowNum].Value = item.Weight;
             ws.Cells["D" + rowNum].Value = item.Note;
             ws.Cells["E" + rowNum].Value = item.CreatedBy;
             ws.Cells["F" + rowNum].Value = Convert.ToDateTime(item.CreatedAt).ToString("dd/MM/yyyy");
             ws.Cells["G" + rowNum].Value = item.Status ? "Đang hoạt động" : "Ngưng hoạt động";
             rowNum++;
         }
         db.Close();
     }
     else
     {
         ws.Cells["A2:E2"].Merge = true;
         ws.Cells["A2"].Value = "You don't have permission to export data.";
     }
     MemoryStream output = new MemoryStream();
     pck.SaveAs(output);
     return File(output.ToArray(), //The binary data of the XLS file
                 "application/vnd.ms-excel", //MIME type of Excel files
                 "DanhSachDonViVanChuyen" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx");     //Suggested file name in the "Save as" dialog which will be displayed to the end user
 }
 public ActionResult GetLocationhByWareHouseID(string WHID)
 {
     var dbConn = new OrmliteConnection().openConn();
     try
     {
         var data = dbConn.Select<WareHouseLocation>(s => s.WHID == WHID);
         return Json(data, JsonRequestBehavior.AllowGet);
     }
     catch (Exception e)
     {
         return Json(new { success = false, message = e.Message });
     }
 }
 public ActionResult GetWH()
 {
     IDbConnection dbConn = new OrmliteConnection().openConn();
     try
     {
         var data = dbConn.Select<WareHouse>("Select * from WareHouse");
         return Json(new { success = true, data = data});
     }
     catch (Exception e)
     {
         return Json(new { success = false, message = e.Message });
     }
     finally { dbConn.Close(); }
 }
 public ActionResult PartialDetail(string id)
 {
     if (userAsset.ContainsKey("View") && userAsset["View"])
     {
         IDbConnection dbConn = new OrmliteConnection().openConn();
         var dict = new Dictionary<string, object>();
         dict["asset"] = userAsset;
         dict["listWH"] = dbConn.Select<WareHouse>(p => p.Status == true);
         dict["listWHL"] = dbConn.Select<WareHouseLocation>(p => p.Status == true);
         dict["listMerchant"] = dbConn.Select<DC_OCM_Merchant>("SELECT MerchantID, MerchantName FROM DC_OCM_Merchant");
         dict["listWH"] = dbConn.Select<WareHouse>(p => p.Status == true);
         dict["listWHL"] = dbConn.Select<WareHouseLocation>(p => p.Status == true);
         dict["listUnit"] = dbConn.Select<Products>(p => p.Status == true);
         dict["SONumber"] = id;
         return PartialView("AD_Order_Detail", dict);
     }
     else
     {
         return Json(new { succsess = false, message = "Không có quyền tạo." });
     }
 }
 public ActionResult Read([DataSourceRequest]DataSourceRequest request)
 {
     var dbConn = new OrmliteConnection().openConn();
     log4net.Config.XmlConfigurator.Configure();
     string whereCondition = "";
     if (request.Filters.Count > 0)
     {
         whereCondition = new KendoApplyFilter().ApplyFilter(request.Filters[0]);
     }
     var data = dbConn.Select<Products>(whereCondition).ToList();
     return Json(data.ToDataSourceResult(request));
 }
 public ActionResult PartialRole()
 {
     if (userAsset.ContainsKey("View") && userAsset["View"])
     {
         IDbConnection dbConn = new OrmliteConnection().openConn();
         var dict = new Dictionary<string, object>();
         dict["asset"] = userAsset;
         dict["activestatus"] = new CommonLib().GetActiveStatus();
         //dict["user"] = dbConn.Select<Auth_User>(p => p.IsActive == true);
         dict["listWH"] = dbConn.Select<WareHouse>(p => p.Status == true);
         dict["listWHL"] = dbConn.Select<WareHouseLocation>(p => p.Status == true);
         dict["listUnit"] = dbConn.Select<Products>(p => p.Status == true);
         dict["listMerchant"] = dbConn.Select<DC_OCM_Merchant>();
         dict["ListPrinter"] = dbConn.Select<DC_AD_Printer>(p => p.Status == true);
         dict["ListStatus"] = dbConn.Select<DC_Parameter>(s => s.Type == "SOStatus");
         dbConn.Close();
         return PartialView("AD_Order_Header", dict);
     }
     else
         return RedirectToAction("NoAccess", "Error");
 }