Exemple #1
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(); }
        }
Exemple #2
0
 public string Insert(Merchant_Folder_Info item, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
         {
             try
             {
                 var checkID = db.FirstOrDefault <Merchant_Folder_Info>(s => s.ten_thu_muc == item.ten_thu_muc && s.ma_gian_hang == item.ma_gian_hang);
                 if (checkID != null)
                 {
                     return("Folder was exists");
                 }
                 else
                 {
                     item.ngay_tao = DateTime.Now;
                     db.Insert(item);
                 }
                 dbTrans.Commit();
                 return("true");
             }
             catch (Exception e)
             {
                 dbTrans.Rollback();
                 return(e.Message.ToString());
             }
         }
     }
 }
Exemple #3
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(); }
        }
Exemple #4
0
 public string UpSert(List <Product_Hierarchy_Property> lstProductHierarchyProperty, string UserName, string Type, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
         {
             try
             {
                 foreach (Product_Hierarchy_Property row in lstProductHierarchyProperty)
                 {
                     if (Type == "Insert")
                     {
                         row.ngay_tao  = row.ngay_cap_nhat = DateTime.Now;
                         row.nguoi_tao = row.nguoi_cap_nhat = UserName;
                         db.Insert(row);
                     }
                     else
                     {
                         row.ngay_cap_nhat  = DateTime.Now;
                         row.nguoi_cap_nhat = UserName;
                         db.Update(row);
                     }
                 }
                 dbTrans.Commit();
                 return("true");
             }
             catch (Exception ex)
             {
                 dbTrans.Rollback();
                 return(ex.Message);
             }
         }
     }
 }
Exemple #5
0
        //public ActionResult ReadDetail([DataSourceRequest] DataSourceRequest request, string SONumber)
        //{
        //    log4net.Config.XmlConfigurator.Configure();
        //    string whereCondition = "";
        //    if (request.Filters.Count > 0)
        //    {
        //        whereCondition = " AND " + new KendoApplyFilter().ApplyFilter(request.Filters[0]);
        //    }
        //    var data = new DC_AD_SO_Detail().GetPage(request, whereCondition, SONumber);
        //    return Json(data);
        //}
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <Products> list, string SONumber)
        {
            var dbConn = new OrmliteConnection().openConn();

            try
            {
                if (list != null && ModelState.IsValid)
                {
                    foreach (var item in list)
                    {
                        if (item.Qty > 0)
                        {
                            //string SONumber = Request["SONumber"];
                            var header = new SOHeader();
                            var detail = new SODetail();

                            if (dbConn.Select <SODetail>(s => s.SONumber == SONumber && s.ItemCode == item.Code).Count() > 0)
                            {
                                dbConn.Update <SODetail>(set: "Qty = '" + item.Qty + "', TotalAmt = '" + item.Qty * item.Price + "'", where : "SONumber = '" + SONumber + "'");
                            }
                            else
                            {
                                var data = new SODetail();
                                data.ItemName  = item.Name;
                                data.ItemCode  = item.Code;
                                data.Note      = "";
                                data.Price     = item.VATPrice;
                                data.Qty       = item.Qty;
                                data.SONumber  = SONumber;
                                data.UnitID    = item.Unit;
                                data.UnitName  = dbConn.Select <INUnit>(s => s.UnitID == item.Unit).FirstOrDefault().UnitName;
                                data.TotalAmt  = item.Qty * item.VATPrice;
                                data.Status    = "";
                                data.CreatedAt = DateTime.Now;
                                data.CreatedBy = currentUser.UserID;
                                //data.UpdatedAt = DateTime.Parse("1900-01-01");
                                data.UpdatedAt = DateTime.Now;
                                data.UpdatedBy = "";
                                dbConn.Insert <SODetail>(data);
                            }
                            dbConn.Update <SOHeader>(set: "TotalQty ='" + dbConn.Select <SODetail>(s => s.SONumber == SONumber).Sum(s => s.Qty) + "', TotalAmt = '" + +dbConn.Select <SODetail>(s => s.SONumber == SONumber).Sum(s => s.TotalAmt) + "'", where : "SONumber ='" + SONumber + "'");
                        }
                        else
                        {
                            dbConn.Delete <SOHeader>(s => s.SONumber == SONumber);
                            ModelState.AddModelError("error", "Đơn hàng được tạo khi số lượng > 0");
                            return(Json(list.ToDataSourceResult(request, ModelState)));
                        }
                    }
                }
                dbConn.Close();
            }
            catch (Exception e)
            {
                dbConn.Close();
                ModelState.AddModelError("error", e.Message);
                return(Json(list.ToDataSourceResult(request, ModelState)));
            }
            return(Json(new { sussess = true }));
        }
Exemple #6
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(); }
        }
Exemple #7
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(); }
        }
        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(); }
        }
Exemple #9
0
        public string CreateUpdate(Footer footer, string UserName, string connectionString)
        {
            using (var db = new OrmliteConnection().openConn(connectionString))
            {
                try
                {
                    var checkID = db.SingleOrDefault <Footer>("ma_footer={0}", footer.ma_footer);
                    if (checkID != null)
                    {
                        footer.id             = checkID.id;
                        footer.nguoi_tao      = checkID.nguoi_tao;
                        footer.ngay_tao       = checkID.ngay_tao;
                        footer.nguoi_cap_nhat = UserName;
                        footer.ngay_cap_nhat  = DateTime.Now;
                        db.Update(footer);
                    }
                    else
                    {
                        var lastId = db.FirstOrDefault <Footer>("SELECT TOP 1 * FROM Footer ORDER BY id DESC");
                        if (lastId != null)
                        {
                            if (lastId.ma_footer.Contains("FOO"))
                            {
                                var nextNo = Int32.Parse(lastId.ma_footer.Substring(3, 10)) + 1;
                                footer.ma_footer = "FOO" + String.Format("{0:0000000000}", nextNo);
                            }
                        }
                        else
                        {
                            footer.ma_footer = "FOO" + "0000000001";
                        }
                        footer.ten_footer     = !string.IsNullOrEmpty(footer.ten_footer) ? footer.ten_footer : "";
                        footer.url_link       = !string.IsNullOrEmpty(footer.url_link) ? footer.url_link : "";
                        footer.image_link     = !string.IsNullOrEmpty(footer.image_link) ? footer.image_link : "";
                        footer.noi_dung       = !string.IsNullOrEmpty(footer.noi_dung) ? footer.noi_dung : "";
                        footer.levels         = footer.levels != 0 ? footer.levels : 0;
                        footer.orders         = footer.orders != 0 ? footer.orders : 0;
                        footer.hinh_anh       = footer.hinh_anh;
                        footer.loai           = !string.IsNullOrEmpty(footer.loai) ? footer.loai : "";
                        footer.nguoi_tao      = UserName;
                        footer.ngay_tao       = DateTime.Now;
                        footer.nguoi_cap_nhat = UserName;
                        footer.ngay_cap_nhat  = DateTime.Parse("01/01/1900");

                        db.Insert(footer);
                    }
                    //SyncToMySQL
                    List <SqlParameter> lstParameter = new List <SqlParameter>();
                    lstParameter.Clear();
                    lstParameter.Add(new SqlParameter("@ma_footer", footer.ma_footer));
                    new SqlHelper(connectionString).ExecuteNoneQuery("p_Footer_SyncToMySQL", lstParameter);
                    return("true@@" + footer.ma_footer);
                }
                catch (Exception e)
                {
                    return("false@@" + e.Message);
                }
            }
        }
Exemple #10
0
 public string CreateUpdate(BrandManagement brand, string UserName, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         try
         {
             var checkID = db.SingleOrDefault <BrandManagement>("ma_thuong_hieu={0}", brand.ma_thuong_hieu);
             if (checkID != null)
             {
                 checkID.logo            = (!string.IsNullOrEmpty(brand.logo) && checkID.logo != brand.logo) ? brand.logo : checkID.logo;
                 checkID.ten_thuong_hieu = !string.IsNullOrEmpty(brand.ten_thuong_hieu) ? brand.ten_thuong_hieu : checkID.ten_thuong_hieu;
                 checkID.trang_thai      = !string.IsNullOrEmpty(brand.trang_thai) ? brand.trang_thai : checkID.trang_thai;
                 checkID.mo_ta           = !string.IsNullOrEmpty(brand.mo_ta) ? brand.mo_ta : checkID.mo_ta;
                 checkID.slug            = StringHelper.convertToUnSign3(brand.ten_thuong_hieu);
                 checkID.nguoi_cap_nhat  = UserName;
                 checkID.ngay_cap_nhat   = DateTime.Now;
                 db.Update(checkID);
             }
             else
             {
                 var lastId = db.FirstOrDefault <BrandManagement>("SELECT TOP 1 * FROM BrandManagement ORDER BY id DESC");
                 if (lastId != null)
                 {
                     if (lastId.ma_thuong_hieu.Contains("BRA"))
                     {
                         var nextNo = Int32.Parse(lastId.ma_thuong_hieu.Substring(3, 10)) + 1;
                         brand.ma_thuong_hieu = "BRA" + String.Format("{0:0000000000}", nextNo);
                     }
                 }
                 else
                 {
                     brand.ma_thuong_hieu = "BRA" + "0000000001";
                 }
                 brand.logo            = !string.IsNullOrEmpty(brand.logo) ? brand.logo : "";
                 brand.ten_thuong_hieu = !string.IsNullOrEmpty(brand.ten_thuong_hieu) ? brand.ten_thuong_hieu : "";
                 brand.trang_thai      = !string.IsNullOrEmpty(brand.trang_thai) ? brand.trang_thai : AllConstant.trang_thai.DANG_SU_DUNG;
                 brand.mo_ta           = !string.IsNullOrEmpty(brand.mo_ta) ? brand.mo_ta : "";
                 brand.slug            = StringHelper.convertToUnSign3(brand.ten_thuong_hieu);
                 brand.nguoi_tao       = UserName;
                 brand.ngay_tao        = DateTime.Now;
                 brand.nguoi_cap_nhat  = UserName;
                 brand.ngay_cap_nhat   = DateTime.Now;
                 db.Insert(brand);
             }
             //SyncToMySQL
             List <SqlParameter> lstParameter = new List <SqlParameter>();
             lstParameter.Clear();
             lstParameter.Add(new SqlParameter("@ma_thuong_hieu", brand.ma_thuong_hieu));
             new SqlHelper(connectionString).ExecuteNoneQuery("p_Brand_SyncToMySQL", lstParameter);
             return("true@@" + brand.ma_thuong_hieu);
         }
         catch (Exception e)
         {
             return("false@@" + e.Message);
         }
     }
 }
Exemple #11
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(); }
        }
 public string Upsert(List <Merchant_Product_Promotion> list, string UserName, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
         {
             try
             {
                 foreach (Merchant_Product_Promotion item in list)
                 {
                     var checkID = db.SingleOrDefault <Merchant_Product_Promotion>("id={0}", item.id);
                     if (checkID != null)
                     {
                         checkID.nguoi_cap_nhat      = UserName;
                         checkID.ngay_cap_nhat       = DateTime.Now;
                         checkID.ten_chuong_trinh_km = item.ten_chuong_trinh_km;
                         checkID.loai    = item.loai;
                         checkID.gia_tri = item.gia_tri;
                         db.Update(checkID);
                     }
                     else
                     {
                         string PromotionID = String.Empty;
                         var    lastId      = db.FirstOrDefault <Merchant_Product_Promotion>("SELECT TOP 1 * FROM Merchant_Product_Promotion ORDER BY id DESC");
                         if (lastId != null)
                         {
                             if (lastId.ma_chuong_trinh_km.Contains("KM"))
                             {
                                 var nextNo = Int32.Parse(lastId.ma_chuong_trinh_km.Substring(2, 7)) + 1;
                                 PromotionID = "KM" + String.Format("{0:0000000}", nextNo);
                             }
                         }
                         else
                         {
                             PromotionID = "KM" + "0000001";
                         }
                         item.trang_thai         = AllConstant.trang_thai.DANG_SU_DUNG;
                         item.ma_chuong_trinh_km = PromotionID;
                         item.ngay_tao           = DateTime.Now;
                         item.nguoi_tao          = UserName;
                         item.ngay_cap_nhat      = DateTime.Parse("1900-1-1");
                         db.Insert(item);
                     }
                 }
                 dbTrans.Commit();
                 return("true");
             }
             catch (Exception e)
             {
                 dbTrans.Rollback();
                 return(e.Message.ToString());
             }
         }
     }
 }
Exemple #13
0
        public string CreateMerchant(Merchant_Info row, string UserName, string connectionString)
        {
            using (var db = new OrmliteConnection().openConn(connectionString))
            {
                //using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
                {
                    try
                    {
                        var checkID = db.SingleOrDefault <Merchant_Info>("id={0}", row.id);
                        if (checkID == null)
                        {
                            string ma_gian_hang = String.Empty;

                            var lastId = db.FirstOrDefault <Merchant_Info>("SELECT TOP 1 * FROM Merchant_Info ORDER BY id DESC");
                            if (lastId != null)
                            {
                                if (lastId.ma_gian_hang.Contains("GH"))
                                {
                                    var nextNo = Int32.Parse(lastId.ma_gian_hang.Substring(7, 2)) + 1;
                                    ma_gian_hang = "GH" + String.Format("{0:0000000}", nextNo);
                                }
                            }
                            else
                            {
                                ma_gian_hang = "GH0000001";
                            }
                            row.ma_gian_hang        = ma_gian_hang;
                            row.slug                = StringHelper.convertToUnSign3(row.ten_gian_hang);
                            row.ngay_tao            = DateTime.Now;
                            row.nguoi_tao           = UserName;
                            row.ngay_tiep_xuc       = !string.IsNullOrEmpty(row.ngay_tiep_xuc.ToString()) ? row.ngay_tiep_xuc : DateTime.Parse("1900-01-01");
                            row.ngay_ky_hop_dong    = !string.IsNullOrEmpty(row.ngay_tiep_xuc.ToString()) ? row.ngay_tiep_xuc : DateTime.Parse("1900-01-01");
                            row.ngay_duyet          = !string.IsNullOrEmpty(row.ngay_duyet.ToString()) ? row.ngay_duyet : DateTime.Parse("1900-01-01");
                            row.ngay_hoat_dong      = !string.IsNullOrEmpty(row.ngay_hoat_dong.ToString()) ? row.ngay_hoat_dong : DateTime.Parse("1900-01-01");
                            row.trang_thai_duyet    = AllConstant.trang_thai_duyet.CHUA_DUYET;
                            row.trang_thai_xuat_ban = AllConstant.trang_thai_xuat_ban.CHUA_XUAT_BAN;
                            row.trang_thai_xac_thuc = AllConstant.trang_thai_xac_thuc.CHUA_XAC_THUC;
                            row.ngay_tao            = DateTime.Now;
                            row.nguoi_tao           = "System";
                            row.ngay_cap_nhat       = DateTime.Now;
                            row.nguoi_cap_nhat      = "System";
                            db.Insert(row);
                            new SqlHelper().ExecuteNoneQuery("update tw_User set ma_gian_hang='" + ma_gian_hang + "' where name='" + UserName + "'", new List <SqlParameter>(), CommandType.Text);
                        }
                        //dbTrans.Commit();
                        return("true");
                    }
                    catch (Exception e)
                    {
                        //dbTrans.Rollback();
                        return(e.Message.ToString());
                    }
                }
            }
        }
Exemple #14
0
 public string UpSert(List <Image_Info> list, string UserName, string Type, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
         {
             try
             {
                 foreach (Image_Info row in list)
                 {
                     var checkID = db.SingleOrDefault <Image_Info>("id={0}", row.id);
                     if (checkID != null)
                     {
                         row.ngay_cap_nhat  = DateTime.Now;
                         row.nguoi_cap_nhat = UserName;
                         row.nguoi_tao      = checkID.nguoi_tao;
                         row.ngay_tao       = checkID.ngay_tao;
                         db.Update(row);
                     }
                     else
                     {
                         string ma_tu_tang = String.Empty;
                         var    lastId     = db.FirstOrDefault <Image_Info>("SELECT TOP 1 * FROM Image_Info ORDER BY id DESC");
                         if (lastId != null)
                         {
                             if (lastId.ma_thong_tin_anh.Contains("IM"))
                             {
                                 var nextNo = Int32.Parse(lastId.ma_thong_tin_anh.Substring(2, 13)) + 1;
                                 ma_tu_tang = "IM" + String.Format("{0:0000000000000}", nextNo);
                             }
                         }
                         else
                         {
                             ma_tu_tang = "IM0000000000001";
                         }
                         row.ma_thong_tin_anh = ma_tu_tang;
                         row.ngay_tao         = DateTime.Now;
                         row.ngay_duyet       = row.ngay_cap_nhat = DateTime.Parse("1900-01-01");
                         row.nguoi_tao        = UserName;
                         row.nguoi_cap_nhat   = row.nguoi_duyet = "";
                         db.Insert(row);
                     }
                 }
                 dbTrans.Commit();
                 return("true");
             }
             catch (Exception e)
             {
                 dbTrans.Rollback();
                 return(e.Message.ToString());
             }
         }
     }
 }
Exemple #15
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(); }
        }
Exemple #16
0
 public string UpSert(List <Merchant_Image> lstProdInfo, string UserName, string Type, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
         {
             try
             {
                 foreach (Merchant_Image row in lstProdInfo)
                 {
                     var checkID = db.SingleOrDefault <Merchant_Image>("id={0}", row.id);
                     if (checkID != null)
                     {
                         if (String.IsNullOrEmpty(row.ten_anh))
                         {
                             row.ten_anh = checkID.ten_anh;
                         }
                         else
                         {
                             if (!String.IsNullOrEmpty(checkID.ten_anh))
                             {
                                 var path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Images/Merchant_Info/"), checkID.ten_anh);
                                 if (!String.IsNullOrEmpty(path))
                                 {
                                     System.IO.File.Delete(path);
                                 }
                             }
                         }
                         row.ngay_cap_nhat  = DateTime.Now;
                         row.nguoi_cap_nhat = UserName;
                         db.Update(EmptyIfNull(row));
                     }
                     else
                     {
                         //row.ngay_duyet = row.ngay_xuat_ban = DateTime.Now;//chua biet
                         row.ngay_tao = row.ngay_cap_nhat = DateTime.Now;
                         //row.nguoi_duyet = row.nguoi_tao = UserName;
                         row.nguoi_tao = UserName;
                         db.Insert(EmptyIfNull(row));
                     }
                 }
                 dbTrans.Commit();
                 return("true");
             }
             catch (Exception e)
             {
                 dbTrans.Rollback();
                 return(e.Message.ToString());
             }
         }
     }
 }
Exemple #17
0
 public string UpSert(List <Property_Detail> lstProperty, string UserName, string Type, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
         {
             try
             {
                 foreach (Property_Detail row in lstProperty)
                 {
                     if (Type == "Insert")
                     {
                         string ma_thuoc_tinh = String.Empty;
                         var    lastId        = db.FirstOrDefault <Property_Detail>("SELECT TOP 1 * FROM Property_Detail ORDER BY ma_thuoc_tinh DESC");
                         if (lastId != null)
                         {
                             if (lastId.ma_thuoc_tinh.Contains("MTT"))
                             {
                                 var nextNo = Int32.Parse(lastId.ma_thuoc_tinh.Substring(3, 5)) + 1;
                                 ma_thuoc_tinh = "MTT" + String.Format("{0:00000}", nextNo);
                             }
                         }
                         else
                         {
                             ma_thuoc_tinh = "MTT" + "00001";
                         }
                         row.ma_thong_so   = row.ma_thong_so;
                         row.ma_thuoc_tinh = ma_thuoc_tinh;
                         row.ngay_tao      = row.ngay_cap_nhat = DateTime.Now;
                         row.nguoi_tao     = row.nguoi_cap_nhat = UserName;
                         db.Insert(row);
                     }
                     else
                     {
                         row.ngay_cap_nhat  = DateTime.Now;
                         row.nguoi_cap_nhat = UserName;
                         db.Update(row);
                     }
                 }
                 dbTrans.Commit();
                 return("true");
             }
             catch (Exception ex)
             {
                 dbTrans.Rollback();
                 return(ex.Message);
             }
         }
     }
 }
Exemple #18
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(); }
        }
Exemple #19
0
        public int AddOrUpdate(int curruserid)
        {
            IDbConnection dbConn = new OrmliteConnection().openConn();

            try
            {
                //var isexist = dbConn.GetByIdOrDefault<AuthUser>(10);
                var isexist = dbConn.FirstOrDefault <AuthUser>("entryid={0}", this.entryid);
                if (isexist == null)
                {
                    this.isactive  = true;
                    this.createdat = DateTime.Now;
                    this.createdby = curruserid;
                    this.updatedat = DateTime.Now;
                    this.updatedby = curruserid;
                    this.lastlogin = DateTime.Now;
                    dbConn.Insert <AuthUser>(this);
                    long lastInsertId = dbConn.GetLastInsertId();
                    dbConn.Close();
                    this.entryid = Convert.ToInt32(lastInsertId);
                    return(this.entryid);
                }
                else if (isexist != null)
                {
                    this.isactive      = isexist.isactive;
                    this.loginprovider = isexist.loginprovider;
                    this.logintype     = isexist.logintype;
                    this.createdat     = isexist.createdat;
                    this.createdby     = isexist.createdby;
                    this.updatedat     = DateTime.Now;
                    this.updatedby     = curruserid;
                    this.lastlogin     = DateTime.Now;
                    dbConn.Update <AuthUser>(this);
                    dbConn.Close();
                    return(this.entryid);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
Exemple #20
0
 public ActionResult CreateAction([DataSourceRequest] DataSourceRequest request, int roleid, string menuid, [Bind(Prefix = "models")] IEnumerable <Auth_Action> lst)
 {
     if (userAsset.ContainsKey("Insert") && userAsset["Insert"])
     {
         IDbConnection db = new OrmliteConnection().openConn();
         foreach (var item in lst)
         {
             if (item != null)
             {
                 if (string.IsNullOrEmpty(item.Action))
                 {
                     ModelState.AddModelError("er", "Xin nhập quyền");
                     return(Json(lst.ToDataSourceResult(request, ModelState)));
                 }
                 var isExist = db.SingleOrDefault <Auth_Action>("RoleID = {0} AND MenuID = {1} AND Action = {2}", roleid, menuid, item.Action);
                 if (isExist != null)
                 {
                     ModelState.AddModelError("er", "Quyền đã tồn tại");
                     return(Json(lst.ToDataSourceResult(request, ModelState)));
                 }
                 try
                 {
                     item.RoleID       = roleid;
                     item.MenuID       = menuid;
                     item.Note         = "";
                     item.RowCreatedAt = DateTime.Now;
                     item.RowCreatedBy = currentUser.UserID;
                     db.Insert <Auth_Action>(item);
                 }
                 catch (Exception ex)
                 {
                     ModelState.AddModelError("er", ex.Message);
                     return(Json(lst.ToDataSourceResult(request, ModelState)));
                 }
             }
         }
         db.Close();
         return(Json(lst.ToDataSourceResult(request)));
     }
     else
     {
         ModelState.AddModelError("er", "Bạn không có quyền tạo mới");
         return(Json(lst.ToDataSourceResult(request, ModelState)));
     }
 }
Exemple #21
0
        public string UpSert(List <Banner> lstBanners, string UserName, string connectionString)
        {
            using (var db = new OrmliteConnection().openConn(connectionString))
            {
                try
                {
                    foreach (Banner row in lstBanners)
                    {
                        var checkID = db.SingleOrDefault <Banner>("id={0}", row.id);
                        if (checkID != null)
                        {
                            checkID.url_link = !string.IsNullOrEmpty(row.url_link.ToString()) ? row.url_link : "";

                            checkID.image          = !string.IsNullOrEmpty(row.image) ? row.image : "";
                            checkID.ma_chuyen_muc  = !string.IsNullOrEmpty(row.ma_chuyen_muc) ? row.ma_chuyen_muc : "";
                            checkID.vi_tri         = !string.IsNullOrEmpty(row.vi_tri) ? row.vi_tri : "";
                            checkID.alt            = !string.IsNullOrEmpty(row.alt) ? row.alt : "";
                            checkID.trang_thai     = !string.IsNullOrEmpty(row.trang_thai) ? row.trang_thai : AllConstant.trang_thai.DANG_SU_DUNG;
                            checkID.nguoi_cap_nhat = UserName;
                            checkID.ngay_cap_nhat  = DateTime.Now;
                            db.Update(checkID);
                        }
                        else
                        {
                            row.url_link       = !string.IsNullOrEmpty(row.url_link.ToString()) ? row.url_link : "";
                            row.image          = !string.IsNullOrEmpty(row.image) ? row.image : "";
                            row.ma_chuyen_muc  = !string.IsNullOrEmpty(row.ma_chuyen_muc) ? row.ma_chuyen_muc : "";
                            row.vi_tri         = !string.IsNullOrEmpty(row.vi_tri) ? row.vi_tri : "";
                            row.trang_thai     = !string.IsNullOrEmpty(row.trang_thai) ? row.trang_thai : AllConstant.trang_thai.DANG_SU_DUNG;
                            row.alt            = !string.IsNullOrEmpty(row.alt) ? row.alt : "";
                            row.nguoi_tao      = UserName;
                            row.ngay_tao       = DateTime.Now;
                            row.nguoi_cap_nhat = UserName;
                            row.ngay_cap_nhat  = DateTime.Now;
                            db.Insert(row);
                        }
                    }
                    return("true");
                }
                catch (Exception e)
                {
                    return(e.Message.ToString());
                }
            }
        }
Exemple #22
0
 public string UpSert(Merchant_Catalog catalog, string UserName, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         try
         {
             var checkID = db.SingleOrDefault <Merchant_Catalog>("id={0}", catalog.id);
             if (checkID != null)
             {
                 catalog.ngay_cap_nhat  = DateTime.Now;
                 catalog.nguoi_cap_nhat = UserName;
                 catalog.nguoi_tao      = checkID.nguoi_tao;
                 catalog.ngay_tao       = checkID.ngay_tao;
                 db.Update(catalog);
             }
             else
             {
                 catalog.nguoi_tao      = UserName;
                 catalog.nguoi_cap_nhat = UserName;
                 catalog.ngay_tao       = DateTime.Now;
                 catalog.ngay_cap_nhat  = DateTime.Now;
                 var lastId = db.FirstOrDefault <Merchant_Catalog>("SELECT TOP 1 * FROM Merchant_Catalog ORDER BY id DESC");
                 if (lastId != null)
                 {
                     if (lastId.ma_catalog.Contains("CAT"))
                     {
                         var nextNo = Int32.Parse(lastId.ma_catalog.Substring(3, 10)) + 1;
                         catalog.ma_catalog = "CAT" + String.Format("{0:0000000000}", nextNo);
                     }
                 }
                 else
                 {
                     catalog.ma_catalog = "CAT" + "0000000001";
                 }
                 db.Insert(catalog);
             }
             return("true");
         }
         catch (Exception e)
         {
             return(e.Message.ToString());
         }
     }
 }
Exemple #23
0
 public string UpSert(List <SEO_MerchantProduct> lstData, string UserName, string connectionString)
 {
     using (var dbConn = new OrmliteConnection().openConn(connectionString))
     {
         try
         {
             foreach (SEO_MerchantProduct item in lstData)
             {
                 if (item.id > 0)
                 {
                     var exist = dbConn.FirstOrDefault <SEO_MerchantProduct>(s => s.ma_san_pham == item.ma_san_pham);
                     exist.og_description = !string.IsNullOrEmpty(item.og_description) ? item.og_description : "";
                     exist.og_title       = !string.IsNullOrEmpty(item.og_title) ? item.og_title : "";
                     exist.og_image       = !string.IsNullOrEmpty(item.og_image) ? item.og_image : "";
                     exist.og_keyword     = !string.IsNullOrEmpty(item.og_keyword) ? item.og_keyword : "";
                     exist.robot          = !string.IsNullOrEmpty(item.robot) ? item.robot : "";
                     exist.nguoi_cap_nhat = UserName;
                     exist.ngay_cap_nhat  = DateTime.Now;
                     dbConn.Update(exist);
                 }
                 else
                 {
                     item.og_description = !string.IsNullOrEmpty(item.og_description) ? item.og_description : "";
                     item.og_title       = !string.IsNullOrEmpty(item.og_title) ? item.og_title : "";
                     item.og_image       = !string.IsNullOrEmpty(item.og_image) ? item.og_image : "";
                     item.og_keyword     = !string.IsNullOrEmpty(item.og_keyword) ? item.og_keyword : "";
                     item.robot          = !string.IsNullOrEmpty(item.robot) ? item.robot : "";
                     item.nguoi_tao      = UserName;
                     item.ngay_tao       = DateTime.Now;
                     item.nguoi_cap_nhat = UserName;
                     item.ngay_cap_nhat  = DateTime.Now;
                     dbConn.Insert(item);
                 }
             }
             return("true");
         }
         catch (Exception e)
         {
             return(e.Message.ToString());
         }
     }
 }
Exemple #24
0
 public string UpSert(List <Entities.Merchant_Product_Related> list, string ma_san_pham_de_nghi, string UserName, string Type, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
         {
             try
             {
                 foreach (Entities.Merchant_Product_Related row in list)
                 {
                     var checkID = db.SingleOrDefault <Entities.Merchant_Product_Related>("ma_san_pham={0}", row.ma_san_pham_de_nghi);
                     if (checkID == null)
                     {
                         string ma_tu_tang = String.Empty;
                         var    lastId     = db.FirstOrDefault <Hierarchy>("SELECT TOP 1 * FROM Hierarchy ORDER BY id DESC");
                         if (lastId != null)
                         {
                             if (lastId.ma_phan_cap.Contains("CAP"))
                             {
                                 var nextNo = Int32.Parse(lastId.ma_phan_cap.Substring(3, 3)) + 1;
                                 ma_tu_tang = "CAP" + String.Format("{0:000}", nextNo);
                             }
                         }
                         else
                         {
                             ma_tu_tang = "CAP001";
                         }
                         row.ma_san_pham_de_nghi = ma_tu_tang;
                         db.Insert(row);
                     }
                 }
                 dbTrans.Commit();
                 return("true");
             }
             catch (Exception e)
             {
                 dbTrans.Rollback();
                 return(e.Message.ToString());
             }
         }
     }
 }
Exemple #25
0
 public string UpSert(List <Merchant_Product_Hierarchy> list, string UserName, string ma_gian_hang, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
         {
             try
             {
                 foreach (Merchant_Product_Hierarchy row in list)
                 {
                     var exit = db.FirstOrDefault <Merchant_Product_Hierarchy>(s => s.id == row.id);
                     if (exit != null)
                     {
                         row.ngay_tao       = exit.ngay_tao;
                         row.nguoi_tao      = exit.nguoi_tao;
                         row.ngay_cap_nhat  = DateTime.Now;
                         row.nguoi_cap_nhat = UserName;
                         db.Update(EmptyIfNull(row));
                     }
                     else
                     {
                         row.trang_thai     = AllConstant.trang_thai.DANG_SU_DUNG;
                         row.ngay_tao       = DateTime.Now;
                         row.ngay_cap_nhat  = DateTime.Parse("1900-01-01");
                         row.nguoi_tao      = UserName;
                         row.nguoi_cap_nhat = "";
                         row.ma_gian_hang   = ma_gian_hang;
                         db.Insert(EmptyIfNull(row));
                     }
                 }
                 dbTrans.Commit();
                 return("true");
             }
             catch (Exception e)
             {
                 dbTrans.Rollback();
                 return(e.Message.ToString());
             }
         }
     }
 }
 public string UpSert(List <Merchant_Contact> list, string UserName, string Type, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
         {
             try
             {
                 foreach (Merchant_Contact row in list)
                 {
                     var checkID = db.SingleOrDefault <Merchant_Contact>("id={0}", row.id);
                     if (checkID != null)
                     {
                         row.ngay_cap_nhat  = DateTime.Now;
                         row.nguoi_cap_nhat = UserName;
                         row.ngay_tao       = checkID.ngay_tao;
                         row.nguoi_cap_nhat = checkID.nguoi_tao;
                         db.Update(EmptyIfNull(row));
                     }
                     else
                     {
                         row.ngay_tao  = row.ngay_cap_nhat = DateTime.Now;
                         row.nguoi_tao = row.nguoi_cap_nhat = UserName;
                         db.Insert(EmptyIfNull(row));
                     }
                 }
                 dbTrans.Commit();
                 return("true");
             }
             catch (Exception e)
             {
                 dbTrans.Rollback();
                 return(e.Message.ToString());
             }
         }
     }
 }
        public string UpsertFull(Merchant_Voucher voucher, List <Merchant_Voucher_Detail> products, string UserName, string connectionString)
        {
            using (var db = new OrmliteConnection().openConn(connectionString))
            {
                Merchant_Voucher checkID;
                checkID = db.SingleOrDefault <Merchant_Voucher>("id={0} and ma_gian_hang = {1}", voucher.id, voucher.ma_gian_hang);
                //Transaction for voucher
                using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
                {
                    try
                    {
                        if (checkID != null)
                        {
                            voucher.ma_khuyen_mai   = checkID.ma_khuyen_mai;
                            checkID.ten_khuyen_mai  = voucher.ten_khuyen_mai;
                            checkID.gia_tri         = voucher.gia_tri;
                            checkID.loai_khuyen_mai = voucher.loai_khuyen_mai;
                            checkID.dieu_kien       = voucher.dieu_kien;
                            checkID.mieu_ta         = voucher.mieu_ta;
                            checkID.gia_ban         = voucher.gia_ban;
                            checkID.ngay_bat_dau    = voucher.ngay_bat_dau;
                            checkID.ngay_ket_thuc   = voucher.ngay_ket_thuc;
                            checkID.so_luong        = voucher.so_luong;
                            checkID.su_dung         = voucher.su_dung;
                            checkID.url             = voucher.url;
                            checkID.ma_anh_goc      = voucher.ma_anh_goc;
                            checkID.ngay_tao        = voucher.ngay_tao;
                            checkID.nguoi_tao       = voucher.nguoi_tao;
                            checkID.ngay_cap_nhat   = DateTime.Now;
                            checkID.nguoi_cap_nhat  = UserName;
                            checkID.trang_thai      = voucher.trang_thai;
                            db.Update(checkID);
                        }
                        else
                        {
                            var lastId = db.FirstOrDefault <Merchant_Voucher>("SELECT TOP 1 * FROM Merchant_Voucher ORDER BY id DESC");
                            if (lastId != null)
                            {
                                if (lastId.ma_khuyen_mai.Contains("VC"))
                                {
                                    var nextNo = Int32.Parse(lastId.ma_khuyen_mai.Substring(2, 7)) + 1;
                                    voucher.ma_khuyen_mai = "VC" + String.Format("{0:0000000}", nextNo);
                                }
                            }
                            else
                            {
                                voucher.ma_khuyen_mai = "VC" + "0000001";
                            }
                            voucher.trang_thai    = AllConstant.trang_thai.DANG_SU_DUNG;
                            voucher.ngay_tao      = DateTime.Now;
                            voucher.nguoi_tao     = UserName;
                            voucher.ngay_cap_nhat = DateTime.Parse("1900-1-1");
                            db.Insert(voucher);
                        }
                        dbTrans.Commit();
                    }
                    catch (Exception e)
                    {
                        dbTrans.Rollback();
                        return(e.Message.ToString());
                    }
                }
                //Transaction for voucher Details
                //using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
                //{
                //    try
                //    {
                //        if (products != null)
                //        {
                //            var checkData = db.Select<Merchant_Product_Promotion_Detail>("ma_khuyen_mai = {0} and ma_gian_hang = {1}", voucher.ma_khuyen_mai, voucher.ma_gian_hang);
                //            if (checkData == null)
                //            {
                //                foreach (string ma_san_pham in products)
                //                {
                //                    Merchant_Product_Promotion_Detail item = new Merchant_Product_Promotion_Detail();
                //                    item.id = 0;
                //                    item.ma_san_pham = ma_san_pham;
                //                    item.ma_gian_hang = voucher.ma_gian_hang;
                //                    item.ma_chuong_trinh_km = voucher.ma_khuyen_mai;
                //                    item.nguoi_tao = UserName;
                //                    item.ngay_tao = DateTime.Now;
                //                    db.Insert(item);
                //                }
                //            }
                //            else
                //            {

                //                foreach (string ma_san_pham in products)
                //                {
                //                    var checkProDetail = checkData.FirstOrDefault(s => s.ma_san_pham == ma_san_pham);
                //                    if (checkProDetail == null)
                //                    {
                //                        Merchant_Product_Promotion_Detail item = new Merchant_Product_Promotion_Detail();
                //                        item.id = 0;
                //                        item.ma_san_pham = ma_san_pham;
                //                        item.ma_gian_hang = voucher.ma_gian_hang;
                //                        item.ma_chuong_trinh_km = voucher.ma_khuyen_mai;
                //                        item.nguoi_tao = UserName;
                //                        item.ngay_tao = DateTime.Now;
                //                        db.Insert(item);
                //                    }
                //                    else
                //                    {
                //                        checkData.Remove(checkProDetail);
                //                    }
                //                }
                //                if (checkData != null)
                //                {
                //                    foreach (Merchant_Product_Promotion_Detail item in checkData)
                //                        db.Delete<Merchant_Product_Promotion_Detail>("ma_khuyen_mai = {0} and ma_gian_hang = {1} and ma_san_pham = {2}", item.ma_chuong_trinh_km, item.ma_gian_hang, item.ma_san_pham);
                //                }
                //            }
                //        }
                //        else
                //        {
                //            db.Delete<Merchant_Product_Promotion_Detail>("ma_khuyen_mai = {0} and ma_gian_hang = {1}", voucher.ma_khuyen_mai, voucher.ma_gian_hang);
                //        }
                //        dbTrans.Commit();
                //    }
                //    catch (Exception e)
                //    {
                //        dbTrans.Rollback();
                //        return e.Message.ToString();
                //    }
                //}
            }
            return("true" + voucher.ma_khuyen_mai);
        }
        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 = "Sả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 = "PR" + String.Format("{0:00000000}", nextNo);
                    }
                    else
                    {
                        id = "PR00000001";
                    }
                    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." }));
                    }
                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false, message = "Bạn không có quyền" }));
                }
            }
            catch (Exception e)
            {
                log.Error(" ListProducts - Create - " + e.Message);
                return(Json(new { success = false, message = e.Message }));
            }
            finally { db.Close(); }
        }
        public ActionResult Create(Company item)
        {
            IDbConnection db = new OrmliteConnection().openConn();

            try
            {
                if (!string.IsNullOrEmpty(item.CompanyID) &&
                    !string.IsNullOrEmpty(item.CompanyName)
                    )
                {
                    var isExist = db.SingleOrDefault <Company>("CompanyID={0}", item.CompanyID);

                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
                    {
                        if (isExist != null)
                        {
                            return(Json(new { success = false, message = "Mã công ty đã tồn tại" }));
                        }
                        item.CompanyName   = !string.IsNullOrEmpty(item.CompanyName) ? item.CompanyName : "";
                        item.ShortName     = !string.IsNullOrEmpty(item.ShortName) ? item.ShortName : "";
                        item.EnglishName   = !string.IsNullOrEmpty(item.EnglishName) ? item.EnglishName : "";
                        item.SubDomain     = !string.IsNullOrEmpty(item.SubDomain) ? item.SubDomain : "";
                        item.Phone         = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
                        item.MobilePhone   = !string.IsNullOrEmpty(item.MobilePhone) ? item.MobilePhone : "";
                        item.Fax           = !string.IsNullOrEmpty(item.Fax) ? item.Fax : "";
                        item.Email         = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
                        item.PersonalEmail = !string.IsNullOrEmpty(item.PersonalEmail) ? item.PersonalEmail : "";
                        item.Address       = !string.IsNullOrEmpty(item.Address) ? item.Address : "";
                        item.Website       = !string.IsNullOrEmpty(item.Website) ? item.Website : "";
                        item.Descr         = !string.IsNullOrEmpty(item.Descr) ? item.Descr : "";
                        item.CreatedAt     = DateTime.Now;
                        item.UpdatedAt     = DateTime.Now;
                        item.CreatedBy     = currentUser.UserID;
                        item.UpdatedBy     = currentUser.UserID;
                        db.Insert <Company>(item);

                        return(Json(new { success = true, CompanyID = item.CompanyID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt, }));
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                    {
                        item.CompanyName   = !string.IsNullOrEmpty(item.CompanyName) ? item.CompanyName : "";
                        item.ShortName     = !string.IsNullOrEmpty(item.ShortName) ? item.ShortName : "";
                        item.EnglishName   = !string.IsNullOrEmpty(item.EnglishName) ? item.EnglishName : "";
                        item.SubDomain     = !string.IsNullOrEmpty(item.SubDomain) ? item.SubDomain : "";
                        item.Phone         = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
                        item.MobilePhone   = !string.IsNullOrEmpty(item.MobilePhone) ? item.MobilePhone : "";
                        item.Fax           = !string.IsNullOrEmpty(item.Fax) ? item.Fax : "";
                        item.Email         = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
                        item.PersonalEmail = !string.IsNullOrEmpty(item.PersonalEmail) ? item.PersonalEmail : "";
                        item.Address       = !string.IsNullOrEmpty(item.Address) ? item.Address : "";
                        item.Website       = !string.IsNullOrEmpty(item.Website) ? item.Website : "";
                        item.Descr         = !string.IsNullOrEmpty(item.Descr) ? item.Descr : "";
                        item.CreatedBy     = isExist.CreatedBy;
                        item.CreatedAt     = isExist.CreatedAt;
                        item.UpdatedAt     = DateTime.Now;
                        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("Company - Create - " + e.Message);
                return(Json(new { success = false, message = e.Message }));
            }
            finally { db.Close(); }
        }
        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 = "PR" + String.Format("{0:00000000}", nextNo);
                                            }
                                            else
                                            {
                                                id = "PR00000001";
                                            }
                                            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 }));
            }
        }