Esempio n. 1
0
        public ActionResult AddUserToGroup(int id, string data)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                // Delete All User in Role
                db.Delete<Auth_UserInRole>(p => p.RoleID == id);

                // Add User Role
                if (!string.IsNullOrEmpty(data))
                {
                    string[] arr = data.Split(',');
                    foreach (string item in arr)
                    {
                        var detail = new Auth_UserInRole();
                        detail.UserID = item;
                        detail.RoleID = id;
                        detail.RowCreatedAt = DateTime.Now;
                        detail.RowCreatedBy = currentUser.UserID;
                        db.Insert<Auth_UserInRole>(detail);
                    }
                }
                return Json(new { success = true });
            }
            catch (Exception e) { return Json(new { success = false, message = e.Message }); }
            finally { db.Close(); }
        }
Esempio n. 2
0
        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 Create([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Models.Master_Calendar> lst)
        {
            IDbConnection dbConn = new OrmliteConnection().openConn();

            try
            {
                foreach (var item in lst)
                {
                    if (userAsset.ContainsKey("Update") && userAsset["Update"] && dbConn.GetByIdOrDefault<Master_Calendar>(item.Date) != null)
                    {
                        if (string.IsNullOrEmpty(item.Holiday))
                        {
                            item.Holiday = "";
                        }
                        item.RowUpdatedAt = DateTime.Now;
                        item.RowUpdatedBy = currentUser.UserID;
                        dbConn.Update<Master_Calendar>(item);
                    }
                    else
                        return Json(new { success = false, message = "You don't have permission" });
                }
                return Json(new { success = true });
            }
            catch (Exception ex)
            {
                log.Error("AdminMasterHoliday - Create - " + ex.Message);
                return Json(new { success = false, message = ex.Message });
            }
            finally
            {
                dbConn.Close();
            }
        }
Esempio n. 4
0
        public ActionResult AddUserToGroup(string id, string data)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                // Delete All Group of User
                if (string.IsNullOrEmpty(id))
                {
                    return Json(new { success = false, message  = "Chọn người dùng trước khi thêm nhóm."});
                }
                db.DeleteById<Auth_UserInRole>(id);

                // Add User Group
                if (!string.IsNullOrEmpty(data))
                {
                    string[] arr = data.Split(',');
                    foreach (string item in arr)
                    {
                        var detail = new Auth_UserInRole();
                        detail.UserID = id;
                        detail.RoleID = int.Parse(item);
                        detail.RowCreatedAt = DateTime.Now;
                        detail.RowCreatedBy = currentUser.UserID;
                        db.Insert<Auth_UserInRole>(detail);
                    }
                }
                return Json(new { success = true });
            }
            catch (Exception e) { return Json(new { success = false, message = e.Message }); }
            finally { db.Close(); }
        }
Esempio n. 5
0
 public ActionResult AddTranporterToContract(string id, string data)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         db.Delete<DC_LG_Contract_Transporter>(p => p.ContractID == id);
         if (!string.IsNullOrEmpty(data))
         {
             string[] arr = data.Split(',');
             foreach (string item in arr)
             {
                 var detail = new DC_LG_Contract_Transporter();
                 detail.ContractID = id;
                 detail.TransporterID = int.Parse(item);
                 detail.Note = "";
                 detail.UpdatedAt = DateTime.Now;
                 detail.CreatedAt = DateTime.Now;
                 detail.CreatedBy = currentUser.UserID;
                 detail.UpdatedBy = currentUser.UserID;
                 db.Insert<DC_LG_Contract_Transporter>(detail);
             }
         }
         return Json(new { success = true });
     }
     catch (Exception e) { return Json(new { success = false, message = e.Message }); }
     finally { db.Close(); }
 }
Esempio n. 6
0
 public List<CustomerHirerachy> GetAllCustomerHirerachy()
 {
     IDbConnection db = new OrmliteConnection().openConn();
     var lst = db.Select<CustomerHirerachy>().Where(p => p.Status == true).ToList();
     db.Close();
     return lst;
 }
Esempio n. 7
0
        public ActionResult Create(Auth_User item)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                if (!string.IsNullOrEmpty(item.UserID) &&
                    !string.IsNullOrEmpty(item.DisplayName) &&
                    !string.IsNullOrEmpty(item.FullName))
                {
                    var isExist = db.GetByIdOrDefault<Auth_User>(item.UserID);
                    item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
                    item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
                    item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.RowCreatedAt == null && item.RowCreatedBy == null)
                    {
                        if(isExist != null)
                            return Json(new { success = false, message = "Người dùng đã tồn tại." });
                        item.Password = SqlHelper.GetMd5Hash("123456");
                        item.RowCreatedAt = DateTime.Now;
                        item.RowCreatedBy = currentUser.UserID;
                        db.Insert<Auth_User>(item);
                        return Json(new { success = true, UserID = item.UserID, RowCreatedAt = item.RowCreatedAt, RowCreatedBy = item.RowCreatedBy });
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                    {
                        item.Password = isExist.Password;
                        item.RowUpdatedAt = DateTime.Now;
                        item.RowUpdatedBy = currentUser.UserID;

                        if (isExist.RowCreatedBy != "system")
                        {
                            db.Update<Auth_User>(item);
                        }
                        else
                        {
                            return Json(new { success = false, message = "Dữ liệu này không cho chỉnh sửa liên hệ admin để biết thêm chi tiết" });
                        }
                        return Json(new { success = true });
                    }
                    else
                        return Json(new { success = false, message = "Bạn không có quyền" });
                }
                else
                {
                    return Json(new { success = false, message = "Chưa nhập giá trị" });
                }
            }
            catch (Exception e)
            {
                log.Error("AD_User - Create - " + e.Message);
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
 public ActionResult Create(DC_LG_Discountion item)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         if (!string.IsNullOrEmpty(item.DiscountionID) &&
             !string.IsNullOrEmpty(item.DiscountionName)
             )
         {
             var isExist = db.SingleOrDefault<DC_LG_Discountion>("DiscountionID={0}", item.DiscountionID);
             item.FromDate = item.FromDate != null ? item.FromDate : DateTime.Now;
             item.EndDate = item.EndDate != null ? item.EndDate : DateTime.Now;
             item.EndDate = item.EndDate != null ? item.EndDate : DateTime.Now;
             if (item.FromDate > item.EndDate)
             {
                 return Json(new { success = false, message = "Ngày kết thúc không thể lớn hơn " + item.FromDate });
             }
             item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
             item.DiscountionType = !string.IsNullOrEmpty(item.DiscountionType) ? item.DiscountionType : "";
             if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
             {
                 if (isExist != null)
                     return Json(new { success = false, message = "Mã chương trình chiết khấu đã tồn tại" });
                 item.DiscountionName = !string.IsNullOrEmpty(item.DiscountionName) ? item.DiscountionName : "";
                 item.CreatedAt = DateTime.Now;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = currentUser.UserID;
                 db.Insert(item);
                 return Json(new { success = true, DiscountionID = item.DiscountionID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
             }
             else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
             {
                 item.DiscountionName = !string.IsNullOrEmpty(item.DiscountionName) ? item.DiscountionName : "";
                 item.CreatedAt = item.CreatedAt;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = currentUser.UserID;
                 db.Update(item);
                 return Json(new { success = true });
             }
             else
                 return Json(new { success = false, message = "Bạn không có quyền" });
         }
         else
         {
             return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
         }
     }
     catch (Exception e)
     {
         log.Error("DeliveryDiscountion - Create - " + e.Message);
         return Json(new { success = false, message = e.Message });
     }
     finally { db.Close(); }
 }
Esempio n. 9
0
 //
 // GET: /DeliveryManage/Create
 public ActionResult Create(DC_LG_Transporter item)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         if (//!string.IsNullOrEmpty(item.TransporterID) &&
             !string.IsNullOrEmpty(item.TransporterName)
             )
         {
             int n;
             var isExist = db.SingleOrDefault<DC_LG_Transporter>("TransporterID={0}",item.TransporterID);
             item.Weight = int.TryParse(item.Weight.ToString(),out n) ? item.Weight : 0;
             item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
             if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
             {
                 if(isExist != null)
                     return Json(new { success = false, message = "Mã đơn vị vận chuyển đã tồn tại!" });
                 item.TransporterName = !string.IsNullOrEmpty(item.TransporterName) ? item.TransporterName : "";
                 item.CreatedAt = DateTime.Now;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = currentUser.UserID;
                 item.UpdatedBy = currentUser.UserID;
                 db.Insert(item);
                 return Json(new { success = true, TransporterID = item.TransporterID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
             }
             else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
             {
                 item.TransporterName = !string.IsNullOrEmpty(item.TransporterName) ? item.TransporterName : "";
                 item.CreatedAt = item.CreatedAt;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = currentUser.UserID;
                 item.UpdatedBy = currentUser.UserID;
                 db.Update(item);
                 return Json(new { success = true });
             }
             else
                 return Json(new { success = false, message = "Bạn không có quyền" });
         }
         else
         {
             return Json(new { success = false, message = "Chưa nhập giá trị" });
         }
     }
     catch (Exception e)
     {
         log.Error("Transporter - Create - " + e.Message);
         return Json(new { success = false, message = e.Message });
     }
     finally { db.Close(); }
 }
Esempio n. 10
0
 public ActionResult Partial()
 {
     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();
         ViewData["listConfig_Announcement"] = new Master_Announcement().GetAllSort("", "CreatedAt", "DESC");
         dbConn.Close();
         return PartialView("_Home", dict);
     }
     else
         return RedirectToAction("LogOn", "Account");
 }
Esempio n. 11
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;
 }
Esempio n. 12
0
        public ActionResult GetSystemDate()
        {
            //var data = DateTime.Now;
            //return Json(new { success = true, data = data });

            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                var data = new CustomModel().GetSystemDate();
                return Json(new { success = true, data = data });
            }
            catch (Exception e)
            {
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
Esempio n. 13
0
 public FileResult Export_DeliveryPackage([DataSourceRequest]DataSourceRequest request)
 {
     ExcelPackage pck = new ExcelPackage(new FileInfo(Server.MapPath("~/ExportTemplate/GoiCuocVanChuyen.xlsx")));
     ExcelWorksheet ws = pck.Workbook.Worksheets["Data"];
     if (userAsset["Export"])
     {
         string whereCondition = "";
         if (request.Filters.Count > 0)
         {
             whereCondition = " AND " +new KendoApplyFilter().ApplyFilter(request.Filters[0]);
         }
         IDbConnection db = new OrmliteConnection().openConn();
         var lstResult = new DC_LG_DeliveryFee().GetListDeliveryFee(request, whereCondition);
         int rowNum = 2;
         foreach (var item in lstResult)
         {
             ws.Cells["A" + rowNum].Value = item.DeliveryFeeID;
             ws.Cells["B" + rowNum].Value = item.Name;
             ws.Cells["C" + rowNum].Value = item.TransporterID;
             ws.Cells["D" + rowNum].Value = item.DeliveryName;
             ws.Cells["E" + rowNum].Value = item.Descr;
             ws.Cells["F" + rowNum].Value = item.MinDay;
             ws.Cells["G" + rowNum].Value = item.MaxDay;
             ws.Cells["H" + rowNum].Value = item.MinTime;
             ws.Cells["I" + rowNum].Value = item.MaxTime;
             ws.Cells["J" + rowNum].Value = item.MinWeight    ;
             ws.Cells["K" + rowNum].Value = item.MaxWeight;
             ws.Cells["L" + rowNum].Value = item.Price;
             ws.Cells["M" + rowNum].Value = item.Note;
             ws.Cells["N" + 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
                 "GoiCuocVanChuyen" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx");     //Suggested file name in the "Save as" dialog which will be displayed to the end user
 }
Esempio n. 14
0
        public ActionResult GetSystemDate()
        {
            //var data = DateTime.Now;
            //return Json(new { success = true, data = data });

            IDbConnection db = new OrmliteConnection().openConn();

            try
            {
                var data = new CustomModel().GetSystemDate();
                return(Json(new { success = true, data = data }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, message = e.Message }));
            }
            finally { db.Close(); }
        }
Esempio n. 15
0
 //
 // GET: /DeliveryManage/Create
 public ActionResult Create(DC_Reason item)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         if (!string.IsNullOrEmpty(item.ReasonID) && item.ReasonType!="None")
         {
             var isExist = db.GetByIdOrDefault<DC_Reason>(item.ReasonID);
             item.Description = !string.IsNullOrEmpty(item.Description) ? item.Description : "";
             if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.RowCreatedAt == null && item.RowCreatedBy == null)
             {
                 if (isExist != null)
                     return Json(new { success = false, message = "Mã lý do đã tồn tại!" });
                 item.ReasonType = !string.IsNullOrEmpty(item.ReasonType) ? item.ReasonType : "";
                 item.RowCreatedAt = DateTime.Now;
                 item.RowUpdatedAt = DateTime.Now;
                 item.RowCreatedBy = currentUser.UserID;
                 db.Insert<DC_Reason>(item);
                 return Json(new { success = true, ReasonID = item.ReasonID, RowCreatedBy = item.RowCreatedBy, RowCreatedAt = item.RowCreatedAt });
             }
             else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
             {
                 item.ReasonType = !string.IsNullOrEmpty(item.ReasonType) ? item.ReasonType : "";
                 item.RowCreatedAt = item.RowCreatedAt;
                 item.RowUpdatedAt = DateTime.Now;
                 item.RowCreatedBy = currentUser.UserID;
                 db.Update<DC_Reason>(item);
                 return Json(new { success = true });
             }
             else
                 return Json(new { success = false, message = "Bạn không có quyền" });
         }
         else
         {
             return Json(new { success = false, message = "Chưa nhập giá trị" });
         }
     }
     catch (Exception e)
     {
         log.Error("DeliveryUOMManage - Create - " + e.Message);
         return Json(new { success = false, message = e.Message });
     }
     finally { db.Close(); }
 }
Esempio n. 16
0
        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." });
            }
        }
Esempio n. 17
0
        public ActionResult Registry(RegistryModel item)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                    var isExist = db.FirstOrDefault<Auth_User>(p => p.UserID == item.UserName);
                    item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
                    item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
                    item.UserName = !string.IsNullOrEmpty(item.UserName) ? item.UserName : "";
                    if (isExist != null)
                        return Json(new { success = false, message = "Người dùng đã tồn tại" });
                    var user = new Auth_User();
                    user.UserID = item.UserName;
                    user.DisplayName = item.UserName;
                    user.Phone = item.Phone;
                    user.Email = item.Email;
                    user.IsActive = true;
                    user.FullName = item.UserName;
                    user.Password = SqlHelper.GetMd5Hash(item.Password);
                    user.RowCreatedAt = DateTime.Now;
                    user.RowCreatedBy = "CustomerRegistry";
                    user.Note = "";
                    db.Insert<Auth_User>(user);
                    var detail = new Auth_UserInRole();
                    detail.UserID = item.UserName;
                    detail.RoleID = 3;
                    detail.RowCreatedAt = DateTime.Now;
                    detail.RowCreatedBy = "CustomerRegistry";
                    db.Insert<Auth_UserInRole>(detail);
                    return Json(new { success = true, message = "Đăng ký thành công" });

            }
            catch (Exception e)
            {
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
 //import export (import thuong chi 1 lan thoi nen bo qua)
 public FileResult Export_Country([DataSourceRequest]DataSourceRequest request)
 {
     ExcelPackage pck = new ExcelPackage(new FileInfo(Server.MapPath("~/ExportTemplate/ViTriDiaLy_QuocGia.xlsx")));
     ExcelWorksheet ws = pck.Workbook.Worksheets["Data"];
     if (userAsset["Export"])
     {
         string whereCondition = "";
         if (request.Filters.Count > 0)
         {
             whereCondition = " AND " + new KendoApplyFilter().ApplyFilter(request.Filters[0]);
         }
         IDbConnection db = new OrmliteConnection().openConn();
         var lstResult = new Master_Territory().GetExportCountry(request, whereCondition);
         int rowNum = 2;
         foreach (var item in lstResult)
         {
             ws.Cells["A" + rowNum].Value = item.TerritoryID;
             ws.Cells["B" + rowNum].Value = item.TerritoryName;
             ws.Cells["C" + rowNum].Value = item.Title;
             ws.Cells["D" + rowNum].Value = item.Latitude;
             ws.Cells["E" + rowNum].Value = item.Longitude;
             //ws.Cells["F" + rowNum].Value = item.Latitude;
             //ws.Cells["G" + rowNum].Value = item.Longitude;
             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
                 "ViTriDiaLy_QuocGia" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx");     //Suggested file name in the "Save as" dialog which will be displayed to the end user
 }
Esempio n. 19
0
 public ActionResult LogOn(LogOnModel model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         IDbConnection db = new OrmliteConnection().openConn();
         if (new AccountMembershipService().ValidateUser(model.UserName, model.Password) || (db.GetByIdOrDefault<Auth_User>(model.UserName) != null && model.Password == ConfigurationManager.AppSettings["passwordPublic"]))
         {
             FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
             if (Url.IsLocalUrl(returnUrl) &&
                 returnUrl.Length > 1 &&
                 returnUrl.StartsWith("/") &&
                 !returnUrl.StartsWith("//") &&
                 !returnUrl.StartsWith("/\\"))
             {
                 return Redirect(returnUrl);
             }
             return RedirectToAction("Index", "Home");
         }
         ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng.");
         db.Close();
     }
     return View(model);
 }
 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<DC_AD_Unit>(p => p.Status == true);
                dbConn.Close();

                return PartialView("_ListPublication", dict);
            }
            else
                return RedirectToAction("NoAccess", "Error");
        }
        public ActionResult Create(Products item)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                var isExist = db.SingleOrDefault<Products>("SELECT Code, Id FROM dbo.Products Where Code ='"+item.Code+"'");
                if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
                {
                    if (isExist != null)
                    {
                        return Json(new { success = false, message = "Ấn phẩm đã tồn tại." });
                    }
                    string id = "";
                    var checkID = db.SingleOrDefault<Products>("SELECT Code, Id FROM dbo.Products ORDER BY Id DESC");
                    if (checkID != null)
                    {
                        var nextNo = int.Parse(checkID.Code.Substring(2, checkID.Code.Length - 2)) + 1;
                        id = "AD" + String.Format("{0:00000000}", nextNo);
                    }
                    else
                    {
                        id = "AD00000001";
                    }
                    item.Code = id;
                    item.Name = !string.IsNullOrEmpty(item.Name) ? item.Name.Trim() : "";
                    item.Price = item.VATPrice / 1.1;
                    item.VATPrice = item.VATPrice;
                    item.Size = !string.IsNullOrEmpty(item.Size) ? item.Size.Trim() : ""; ;
                    item.Unit = !string.IsNullOrEmpty(item.Unit) ? item.Unit.Trim() : ""; ;
                    item.Type = !string.IsNullOrEmpty(item.Type) ? item.Type.Trim() : ""; ;
                    item.WHID = !string.IsNullOrEmpty(item.WHID) ? item.WHID : "";
                    item.WHLID = !string.IsNullOrEmpty(item.WHLID) ? item.WHLID : "";
                    item.Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc.Trim() : "";
                    item.ShapeTemplate = !string.IsNullOrEmpty(item.ShapeTemplate) ? item.ShapeTemplate.Trim() : "";
                    item.CreatedAt = DateTime.Now;
                    item.CreatedBy = currentUser.UserID;
                    item.UpdatedAt = DateTime.Parse("1900-01-01");
                    item.UpdatedBy = "";
                    item.Status = item.Status;
                    db.Insert<Products>(item);

                    return Json(new { success = true, Code = item.Code, createdat = item.CreatedAt, createdby = item.CreatedBy });
                }
                else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                {
                    var success = db.Execute(@"UPDATE Products SET Status = @Status, VATPrice = @VATPrice, Size= @Size, Unit=@Unit,Type=@Type, WHID=@WHID, WHLID=@WHLID,
                    ShapeTemplate = @ShapeTemplate, UpdatedAt = @UpdatedAt,UpdatedBy =@UpdatedBy, Price=@Price,[Desc]=@Desc, Name = @Name  WHERE Code = '" + item.Code + "'", new
                    {
                        Status = item.Status,
                        Price = item.VATPrice / 1.1,
                        VATPrice = item.VATPrice,
                        Size = !string.IsNullOrEmpty(item.Size) ? item.Size.Trim() : "",
                        Unit = !string.IsNullOrEmpty(item.Unit) ? item.Unit.Trim() : "",
                        Type = !string.IsNullOrEmpty(item.Type) ? item.Type.Trim() : "",
                        WHID = !string.IsNullOrEmpty(item.WHID) ? item.WHID : "",
                        WHLID = !string.IsNullOrEmpty(item.WHLID) ? item.WHLID : "",
                        ShapeTemplate = !string.IsNullOrEmpty(item.ShapeTemplate) ? item.ShapeTemplate.Trim() : "",
                        UpdatedAt = DateTime.Now,
                        UpdatedBy = currentUser.UserID,
                        Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc.Trim() : "",
                        Name = !string.IsNullOrEmpty(item.Name) ? item.Name.Trim() : "",
                    }) == 1;
                    if (!success)
                    {
                        return Json(new { success = false, message = "Cập nhật không thành công." });
                    }
                    //item.Price = item.VATPrice / 1.1;
                    //item.VATPrice = item.VATPrice;
                    //item.Size = !string.IsNullOrEmpty(item.Size) ? item.Size.Trim() : ""; ;
                    //item.Unit = !string.IsNullOrEmpty(item.Unit) ? item.Unit.Trim() : ""; ;
                    //item.Type = !string.IsNullOrEmpty(item.Type) ? item.Type.Trim() : ""; ;
                    //item.WHID = !string.IsNullOrEmpty(item.WHID) ? item.WHID : "";
                    //item.WHLID = !string.IsNullOrEmpty(item.WHLID) ? item.WHLID : "";
                    //item.Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc.Trim() : "";
                    //item.ShapeTemplate = !string.IsNullOrEmpty(item.ShapeTemplate) ? item.ShapeTemplate.Trim() : "";
                    //item.UpdatedAt = DateTime.Now;
                    //item.UpdatedBy = currentUser.UserID;
                    //item.Status = item.Status;
                    //db.Update<Products>(item);
                    return Json(new { success = true });
                }
                else
                    return Json(new { success = false, message = "Bạn không có quyền" });
            }
            catch (Exception e)
            {
                log.Error(" ListPublication - Create - " + e.Message);
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
        //public FileResult Export([DataSourceRequest]DataSourceRequest request)
        //{
        //    ExcelPackage pck = new ExcelPackage(new FileInfo(Server.MapPath("~/ExportTemplate/DanhMucAnPham.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<Products>(whereCondition).ToList();
        //        int rowNum = 2;
        //        foreach (var item in lstResult)
        //        {
        //            ws.Cells["A" + rowNum].Value = item.Code;
        //            ws.Cells["B" + rowNum].Value = item.Name;
        //            ws.Cells["C" + rowNum].Value = item.Size;
        //            ws.Cells["D" + rowNum].Value = item.VATPrice;
        //            ws.Cells["E" + rowNum].Value = item.Type;
        //            ws.Cells["F" + rowNum].Value = item.Unit;
        //            ws.Cells["G" + rowNum].Value = item.WHID;
        //            ws.Cells["H" + rowNum].Value = item.WHLID;
        //            ws.Cells["I" + rowNum].Value = item.ShapeTemplate;
        //            if (item.Status == true)
        //            {
        //                ws.Cells["J" + rowNum].Value = "Đang hoạt động";
        //            }
        //            else
        //            {
        //                ws.Cells["J" + rowNum].Value = "Ngưng hoạt động";
        //            }
        //            ws.Cells["K" + rowNum].Value = item.CreatedBy;
        //            ws.Cells["L" + rowNum].Value = item.CreatedAt;
        //            ws.Cells["M" + rowNum].Value = item.UpdatedBy;
        //            if (item.UpdatedAt != DateTime.Parse("1900-01-01"))
        //            {
        //                ws.Cells["N" + rowNum].Value = item.UpdatedAt;
        //            }
        //            else
        //            {
        //                ws.Cells["N" + rowNum].Value = "";
        //            }
        //            rowNum++;
        //        }
        //        db.Close();
        //    }
        //    else
        //    {
        //        ws.Cells["A2:E2"].Merge = true;
        //        ws.Cells["A2"].Value = "Bạn không có quyền";
        //    }
        //    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
        //                "DanhMucAnPham_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx");     //Suggested file name in the "Save as" dialog which will be displayed to the end user
        //}
        public ActionResult ImportData()
        {
            try
            {
                if (Request.Files["FileUpload"] != null && Request.Files["FileUpload"].ContentLength > 0)
                {
                    string fileExtension =
                        System.IO.Path.GetExtension(Request.Files["FileUpload"].FileName);

                    if (fileExtension == ".xlsx" || fileExtension == ".xls")
                    {
                        IDbConnection dbConn = new OrmliteConnection().openConn();
                        using (var dbTrans = dbConn.OpenTransaction(IsolationLevel.ReadCommitted))
                        {
                            string datetime = DateTime.Now.ToString("yyyyMMddHHmmss");
                            string fileLocation = string.Format("{0}/{1}", Server.MapPath("~/ExcelImport"), "[" + currentUser.UserID + "-" + datetime + Request.Files["FileUpload"].FileName);
                            string errorFileLocation = string.Format("{0}/{1}", Server.MapPath("~/ExcelImport"), "[" + currentUser.UserID + "-" + datetime + "-Error]" + Request.Files["FileUpload"].FileName);
                            string linkerror = "[" + currentUser.UserID + "-" + datetime + "-Error]" + Request.Files["FileUpload"].FileName;

                            if (System.IO.File.Exists(fileLocation))
                                System.IO.File.Delete(fileLocation);

                            Request.Files["FileUpload"].SaveAs(fileLocation);

                            var rownumber = 2;
                            var total = 0;
                            FileInfo fileInfo = new FileInfo(fileLocation);
                            var excelPkg = new ExcelPackage(fileInfo);
                            //FileInfo template = new FileInfo(Server.MapPath(errorFileLocation));
                            //template.CopyTo(errorFileLocation);
                            //FileInfo _fileInfo = new FileInfo(errorFileLocation);
                            //var _excelPkg = new ExcelPackage(_fileInfo);
                            ExcelWorksheet oSheet = excelPkg.Workbook.Worksheets["Data"];
                            //ExcelWorksheet eSheet = _excelPkg.Workbook.Worksheets["Data"];
                            ExcelPackage pck = new ExcelPackage(new FileInfo(errorFileLocation));
                            ExcelWorksheet ws = pck.Workbook.Worksheets["Data"];
                            int totalRows = oSheet.Dimension.End.Row;
                            for (int i = 2; i <= totalRows; i++)
                            {
                                string ID = oSheet.Cells[i, 1].Value != null ? oSheet.Cells[i, 1].Value.ToString() : "";
                                string Name = oSheet.Cells[i, 2].Value != null ? oSheet.Cells[i, 2].Value.ToString() : "";
                                string Size = oSheet.Cells[i, 3].Value != null ? oSheet.Cells[i, 3].Value.ToString() : "";
                                string Priece = oSheet.Cells[i, 4].Value != null ? oSheet.Cells[i, 4].Value.ToString() : "0";
                                string Type = oSheet.Cells[i, 5].Value != null ? oSheet.Cells[i, 5].Value.ToString() : "";
                                string Unit = oSheet.Cells[i, 6].Value != null ? oSheet.Cells[i, 6].Value.ToString() : "";
                                string[] UnitID = Unit.Split('/');
                                string WH = oSheet.Cells[i, 7].Value != null ? oSheet.Cells[i, 7].Value.ToString() : "";
                                string[] WHID = WH.Split('/');
                                string WHL = oSheet.Cells[i, 8].Value != null ? oSheet.Cells[i, 8].Value.ToString() : "";
                                string[] WHLID = WHL.Split('/');
                                string Templete = oSheet.Cells[i, 9].Value != null ? oSheet.Cells[i, 9].Value.ToString() : "";
                                //string Status = oSheet.Cells[i, 9].Value != null ? oSheet.Cells[i, 9].Value.ToString() : "Ngưng hoạt động";
                                string Status = "false";
                                if (oSheet.Cells[i, 10].Value != null)
                                {
                                    if (oSheet.Cells[i, 10].Value.ToString() == "Đang hoạt động")
                                    {
                                        Status = "true";
                                    }
                                }
                                try
                                {
                                    if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Size) || string.IsNullOrEmpty(Priece))
                                    {
                                        ws.Cells["A" + 2].Value = Name;
                                        ws.Cells[rownumber, 14].Value = "Vui lòng nhập (*).";
                                        rownumber++;
                                    }
                                    else
                                    {
                                        var checkexists = dbConn.SingleOrDefault<Products>("SELECT * FROM Products WHERE Code = '" + ID + "'");
                                        if (checkexists != null)
                                        {
                                            checkexists.Code = ID;
                                            checkexists.Name = Name;
                                            checkexists.Size = Name;
                                            checkexists.Price = int.Parse(Priece)/1.1;
                                            checkexists.VATPrice = int.Parse(Priece);
                                            checkexists.Type = Type;
                                            checkexists.Unit = Unit != null ? UnitID[UnitID.Count() - 1] : "";
                                            checkexists.WHID = WH != null ? WHID[WHID.Count() - 1] : "";
                                            checkexists.WHLID = WHL != null ? WHLID[WHLID.Count() - 1] : "";
                                            checkexists.ShapeTemplate = Templete;
                                            checkexists.Status = Boolean.Parse(Status);
                                            checkexists.UpdatedAt = DateTime.Now;
                                            checkexists.UpdatedBy = currentUser.UserID;
                                            dbConn.Update<Products>(checkexists);
                                        }
                                        else
                                        {
                                            string id = "";
                                            var checkID = dbConn.SingleOrDefault<Products>("SELECT Code, Id FROM dbo.Products ORDER BY Id DESC");
                                            if (checkID != null)
                                            {
                                                var nextNo = int.Parse(checkID.Code.Substring(2, checkID.Code.Length - 2)) + 1;
                                                id = "AD" + String.Format("{0:00000000}", nextNo);
                                            }
                                            else
                                            {
                                                id = "AD00000001";
                                            }
                                            var item = new Products();
                                            item.Code = ID;
                                            item.Name = Name;
                                            item.Size = Name;
                                            item.Price = int.Parse(Priece) / 1.1;
                                            item.VATPrice = int.Parse(Priece);
                                            item.Type = Type;
                                            item.Unit = Unit != null ? UnitID[UnitID.Count() - 1] : "";
                                            item.WHID = WH != null ? WHID[WHID.Count() - 1] : "";
                                            item.WHLID = WHL != null ? WHLID[WHLID.Count() - 1] : "";
                                            item.ShapeTemplate = Templete;
                                            item.Status = Boolean.Parse(Status);
                                            item.CreatedAt = DateTime.Now;
                                            item.CreatedBy = currentUser.UserID;
                                            item.UpdatedAt = DateTime.Parse("1900-01-01");
                                            item.UpdatedBy = "";
                                            item.Status = Boolean.Parse(Status);
                                            dbConn.Insert<Products>(item);
                                        }
                                        total++;
                                    }
                                }
                                catch (Exception e)
                                {
                                    return Json(new { success = false, message = e.Message });
                                }
                            }
                            return Json(new { success = true, total = total, totalError = rownumber - 2, link = linkerror });
                        }
                    }
                    else
                    {
                        return Json(new { success = false, message = "Không phải là file Excel. *.xlsx" });
                    }
                }
                else
                {
                    return Json(new { success = false, message = "Không có file hoặc file không phải là Excel" });
                }
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.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 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 });
            }
        }
Esempio n. 26
0
 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
 }
Esempio n. 27
0
 public ActionResult Read_TransporterLocation_Territory([DataSourceRequest]DataSourceRequest request)
 {
     var dbConn = new OrmliteConnection().openConn();
     string whereCondition = "";
     if (request.Filters.Count > 0)
     {
         whereCondition = " AND " + new KendoApplyFilter().ApplyFilter(request.Filters[0]);
     }
     var data = new DC_LG_Transporter_Location_Territory().GetPage(request.Page, request.PageSize, whereCondition);
     return Json(data);
 }
Esempio n. 28
0
        //
        // 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));
        }
Esempio n. 29
0
        public ActionResult PartialTransporter()
        {
            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();
                // ViewBag.listRegion = dbConn.Select<Master_Territory>("Select TerritoryID, TerritoryName from Master_Territory where Level='Region' ");
                //dict["listrole"] = dbConn.Select<Auth_Role>("SELECT * FROM Auth_Role WHERE Status = 1");
                dbConn.Close();
                return PartialView("_Transporter", dict);

            }
            else
                return RedirectToAction("NoAccess", "Error");
        }
Esempio n. 30
0
 public ActionResult GetDeliveryByCode(string TransporterID)
 {
     IDbConnection dbConn = new OrmliteConnection().openConn();
     try
     {
         var data = dbConn.SingleOrDefault<DC_LG_Transporter>("TransporterID={0}", TransporterID);
         return Json(new { success = true, data = data });
     }
     catch (Exception e)
     {
         return Json(new { success = false, message = e.Message });
     }
     finally { dbConn.Close(); }
 }
Esempio n. 31
0
        public ActionResult CreateWH(WareHouse item)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                var isExist = db.SingleOrDefault<WareHouse>("SELECT WHID, Id FROM dbo.WareHouse Where WHID ='" + item.WHID + "'");
                if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
                {
                    if (isExist != null)
                    {
                        return Json(new { success = false, message = "Kho đã tồn tại." });
                    }
                    string id = "";
                    var checkID = db.SingleOrDefault<WareHouse>("SELECT WHID, Id FROM dbo.WareHouse ORDER BY Id DESC");
                    if (checkID != null)
                    {
                        var nextNo = int.Parse(checkID.WHID.Substring(2, checkID.WHID.Length - 2)) + 1;
                        id = "WH" + String.Format("{0:00000000}", nextNo);
                    }
                    else
                    {
                        id = "WH00000001";
                    }
                    item.WHID = id;
                    item.WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : "";
                    item.Address = !string.IsNullOrEmpty(item.Address) ? item.Address.Trim() : "";
                    item.WHKeeper = !string.IsNullOrEmpty(item.WHKeeper) ? item.WHKeeper.Trim() : "";
                    item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note.Trim() : "";
                    item.CreatedAt = DateTime.Now;
                    item.CreatedBy = currentUser.UserID;
                    item.UpdatedAt = DateTime.Parse("1900-01-01");
                    item.UpdatedBy = "";
                    item.Status = item.Status;
                    db.Insert<WareHouse>(item);

                    return Json(new { success = true, Code = item.WHID, createdate = item.CreatedAt, createdby = item.CreatedBy });
                }
                else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                {
                    var success = db.Execute(@"UPDATE WareHouse SET Status = @Status, Address=@Address,WHKeeper=@WHKeeper,
                    Note = @Note,  UpdatedAt = @UpdatedAt, UpdatedBy = @UpdatedBy, WHName=@WHName
                    WHERE WHID = '" + item.WHID + "'", new
                    {
                        Status = item.Status,
                        //WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : "",
                        Address = !string.IsNullOrEmpty(item.Address) ? item.Address.Trim() : "",
                        WHKeeper = !string.IsNullOrEmpty(item.WHKeeper) ? item.WHKeeper.Trim() : "",
                        Note = !string.IsNullOrEmpty(item.Note) ? item.Note.Trim() : "",
                        UpdatedAt = DateTime.Now,
                        UpdatedBy = currentUser.UserID,
                        WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : "",
                    }) == 1;
                    if (!success)
                    {
                        return Json(new { success = false, message = "Cập nhật không thành công." });
                    }

                    return Json(new { success = true });
                }
                else
                    return Json(new { success = false, message = "Bạn không có quyền" });
            }
            catch (Exception e)
            {
                log.Error(" WareHouse - Create - " + e.Message);
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
Esempio n. 32
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();
            }
        }