Exemplo n.º 1
0
        /// <summary>
        /// //Giai ma
        /// </summary>
        ///  /// phongtv
        /// <param name="ModuleParent"></param>
        /// <param name="AttributeCode"></param>
        /// <param name="keyString"></param>
        /// <returns></returns>
        public int DecryptAtt(string ModuleParent, string AttributeCode, string keyString)
        {
            int result = 0;

            try
            {
                List <TblCimsattributeValue> CimsChk = db.TblCimsattributeValue.Where(a => a.IsDelete == false && a.Module == ModuleParent && a.AttributeCode == AttributeCode).ToList();

                for (int i = 0; i < CimsChk.Count(); i++)
                {
                    TblVocattributes AttChk = db.TblVocattributes.Where(a => a.IsDelete == false && a.ModuleParent == ModuleParent && a.AttributeCode == AttributeCode).FirstOrDefault();
                    AttChk.Encyption       = false;
                    db.Entry(AttChk).State = EntityState.Modified;
                    db.SaveChanges();

                    string text = CimsChk[i].AttributeValue;
                    CimsChk[i].AttributeValue  = cimsCommon.DecryptStringAES(text, keyString);
                    db.Entry(CimsChk[i]).State = EntityState.Modified;
                    db.SaveChanges();
                    result = 2;
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(result);

                throw ex;
            }
        }
Exemplo n.º 2
0
        public object Import(string fileName, string rootFolder)
        {
            //string fileName = @"ImportCustomers.xlsx";
            FileInfo file = new FileInfo(Path.Combine(rootFolder, fileName));

            using (ExcelPackage package = new ExcelPackage(file))
            {
                ExcelWorksheet workSheet = package.Workbook.Worksheets["Customer"];
                int            totalRows = workSheet.Dimension.Rows;

                List <TblCategory> customerList = new List <TblCategory>();

                for (int i = 2; i <= totalRows; i++)
                {
                    customerList.Add(new TblCategory
                    {
                        CategoryCode        = workSheet.Cells[i, 1].Value.ToString(),
                        CategoryName        = workSheet.Cells[i, 2].Value.ToString(),
                        CategoryTypeCode    = workSheet.Cells[i, 3].Value.ToString(),
                        CategoryDescription = workSheet.Cells[i, 4].Value.ToString(),
                    });
                }
                db.TblCategory.AddRange(customerList);
                db.SaveChanges();

                return(customerList);
            }
        }
Exemplo n.º 3
0
 public ResponseDTO UpdateEncrpytion(AttributeModel model, string orgCode)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         try
         {
             foreach (var item in model.tblVocattributes)
             {
                 var result = db.TblEncryption.Where(x => x.AttributeCode == item.AttributeCode && x.ParentCode == item.ParentCode).FirstOrDefault();
                 if (result != null)
                 {
                     // Kiểm tra xem trường dữ liệu đã được mã hóa lần nào chưa
                     if (result.IsFirst == true)
                     {
                         db.TblEncryption.Remove(result);
                     }
                     else
                     {
                         if (result.EncryptionStatus == result.FinalizationStatus)
                         {
                             // Kiểm tra trạng thái mã hóa của trường dữ liệu
                             if (result.EncryptionStatus == true)
                             {
                                 result.EncryptionStatus = false;
                                 result.UpdatedBy        = model.UserName;
                                 //result.IsDone = true;
                                 result.IsDone          = false;
                                 db.Entry(result).State = EntityState.Modified;
                             }
                             else
                             {
                                 result.EncryptionStatus = true;
                                 result.UpdatedBy        = model.UserName;
                                 //result.IsDone = true;
                                 result.IsDone          = false;
                                 db.Entry(result).State = EntityState.Modified;
                             }
                         }
                         else
                         {
                             result.IsDone           = true;
                             result.EncryptionStatus = result.FinalizationStatus;
                         }
                     }
                 }
                 else
                 {
                     // Thêm mới trường dữ liệu cần mã hóa
                     if (item.ParentCode == EncryptionConstant.ADMIN_USER)
                     {
                         var attributeEncryption = new TblEncryption();
                         attributeEncryption.AttributeCode = item.AttributeCode;
                         if (item.AttributeLabel == EncryptionConstant.HoTen)
                         {
                             attributeEncryption.AttributeLabel = item.AttributeLabel;
                             attributeEncryption.Field          = EncryptionConstant.FullName;
                         }
                         if (item.AttributeLabel == EncryptionConstant.DiaChi)
                         {
                             attributeEncryption.AttributeLabel = item.AttributeLabel;
                             attributeEncryption.Field          = EncryptionConstant.Address;
                         }
                         attributeEncryption.CreatedBy        = model.UserName;
                         attributeEncryption.CreateDate       = DateTime.Now;
                         attributeEncryption.ParentCode       = item.ParentCode;
                         attributeEncryption.ModuleName       = item.ModuleName;
                         attributeEncryption.EncryptionStatus = true;
                         attributeEncryption.OrgCode          = orgCode;
                         attributeEncryption.IsFirst          = true;
                         attributeEncryption.IsDone           = false;
                         db.TblEncryption.Add(attributeEncryption);
                     }
                     else
                     {
                         var attributeEncryption = new TblEncryption();
                         attributeEncryption.AttributeCode    = item.AttributeCode;
                         attributeEncryption.AttributeLabel   = item.AttributeLabel;
                         attributeEncryption.CreatedBy        = model.UserName;
                         attributeEncryption.CreateDate       = DateTime.Now;
                         attributeEncryption.ParentCode       = item.ParentCode;
                         attributeEncryption.ModuleName       = item.ModuleName;
                         attributeEncryption.EncryptionStatus = true;
                         attributeEncryption.OrgCode          = orgCode;
                         attributeEncryption.IsFirst          = true;
                         attributeEncryption.IsDone           = false;
                         db.TblEncryption.Add(attributeEncryption);
                     }
                 }
             }
             db.SaveChanges();
             scope.Complete();
             return(new ResponseDTO()
             {
                 StatusCode = 200, Response = EncryptionConstant.MS0013
             });
         }
         catch (Exception ex)
         {
             return(new ResponseDTO()
             {
                 StatusCode = 500, Response = ex.Message
             });
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Tạo mới danh mục
        /// CreatedBy: Cuongpv1
        /// CreatedDate: 23/05/2019
        /// </summary>
        /// <param name="tblCategory">object</param>
        /// <returns></returns>
        public object AddCategory(CategoryChildren tblCategory)
        {
            int    code        = 0;
            object objCategory = new object();

            try
            {
                string           cateCode       = LocDau(tblCategory.CategoryName).ToUpper();
                string           cateCode1      = (cateCode != "") ? Regex1(cateCode, CategoryConstant.regex, CategoryConstant.Space) : "";
                TblCategoryGroup addCateGroup   = new TblCategoryGroup();
                TblCategory      addCategory    = new TblCategory();
                TblCategory      checkCateCode  = db.TblCategory.Where(v => v.CategoryCode == cateCode1 && v.IsDelete == false).FirstOrDefault();
                TblCategoryGroup checkCateGroup = db.TblCategoryGroup.Where(v => v.CategoryCode == cateCode1 && v.IsDelete == false).FirstOrDefault();

                if (tblCategory.CategoryTypeCode != "")
                {
                    if (checkCateCode == null)
                    {
                        if (checkCateGroup == null)
                        {
                            using (var ts = new TransactionScope())
                            {
                                addCateGroup.CategoryCode        = cateCode1;
                                addCateGroup.CategoryTypeCode    = tblCategory.CategoryTypeCode;
                                addCateGroup.CategoryGroupName   = tblCategory.CategoryName;
                                addCateGroup.CategoryDescription = tblCategory.CategoryDescription;
                                addCateGroup.CreateBy            = tblCategory.CreateBy;
                                addCateGroup.CreateDate          = DateTime.Now;
                                addCateGroup.IsDelete            = false;
                                db.TblCategoryGroup.Add(addCateGroup);
                                code = db.SaveChanges();
                                if (tblCategory.children.Count > 0)
                                {
                                    AddCategoryChild(addCateGroup.CategoryCode, tblCategory.children);
                                }
                                objCategory = new { code = code, CategoryCode = addCateGroup.CategoryCode };
                                ts.Complete();
                            }
                        }
                        else
                        {
                            objCategory = new { code = code, CategoryCode = "" };
                        }
                    }
                    else
                    {
                        objCategory = new { code = code, CategoryCode = "" };
                    }
                }
                else
                {
                    if (checkCateGroup == null)
                    {
                        if (checkCateCode == null)
                        {
                            using (var ts = new TransactionScope())
                            {
                                addCategory.CategoryCode        = cateCode1;
                                addCategory.CategoryTypeCode    = tblCategory.CategoryTypeCode;
                                addCategory.CategoryName        = tblCategory.CategoryName;
                                addCategory.CategoryDescription = tblCategory.CategoryDescription;
                                addCategory.IsDelete            = false;
                                addCategory.CreateBy            = tblCategory.CreateBy;
                                addCategory.CreateDate          = DateTime.Now;
                                db.TblCategory.Add(addCategory);
                                code = db.SaveChanges();
                                if (tblCategory.children.Count > 0)
                                {
                                    AddCategoryChild(addCategory.CategoryCode, tblCategory.children);
                                }
                                objCategory = new { code = code, CategoryCode = addCategory.CategoryCode };
                                ts.Complete();
                            }
                        }
                        else
                        {
                            objCategory = new { code = code, CategoryCode = "" };
                        }
                    }
                    else
                    {
                        objCategory = new { code = code, CategoryCode = "" };
                    }
                }
                return(objCategory);
            }
            catch (Exception ex)
            {
                return(new { code = 500, messsage = ex.Message });
            }
        }