Esempio n. 1
0
        public ReturnObject UpdateAsset(ModelViews.ViewAsset entity)
        {
            ReturnObject obj = new ReturnObject();

            obj.status = -1;
            using (var transaction = tWG_ACHECKContext.Database.BeginTransaction())
            {
                try
                {
                    DaoAsset daoAsset = new DaoAsset(tWG_ACHECKContext);
                    var      result   = daoAsset.UpdateAsset(entity.asset, entity.assign);
                    if (result > 0)
                    {
                        obj.status = 1;
                    }
                    obj.value = result;
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    obj.status  = -1;
                    obj.message = ex.StackTrace;
                }
            }
            return(obj);
        }
Esempio n. 2
0
        public ReturnObject AssetFilter(string AssetID, string AssetName, string keyWord)
        {
            ReturnObject obj = new ReturnObject();

            obj.status = -1;
            try
            {
                DaoAsset daoAsset = new DaoAsset(tWG_ACHECKContext);
                if (!string.IsNullOrEmpty(keyWord))
                {
                    object result = new object();
                    result    = daoAsset.AssetFilter(keyWord);
                    obj.value = result;
                }
                else
                {
                    List <Asset> result = new List <Asset>();
                    result    = daoAsset.AssetFilter(AssetID, AssetName);
                    obj.value = result;
                }
                obj.status = 1;
            }
            catch (Exception ex)
            {
                obj.status  = -1;
                obj.message = ex.StackTrace;
            }
            return(obj);
        }
Esempio n. 3
0
        public async Task <ReturnObject> Update()
        {
            IFormFileCollection formFiles = Request.Form.Files;

            ModelViews.ViewAsset entity = JsonConvert.DeserializeObject <ModelViews.ViewAsset>(Request.Form["entity"].ToString());
            ReturnObject         obj    = new ReturnObject();

            obj.status = -1;
            using (var transaction = tWG_ACHECKContext.Database.BeginTransaction())
            {
                try
                {
                    DaoAsset daoAsset = new DaoAsset(tWG_ACHECKContext);
                    int      result   = await daoAsset.Update(entity, formFiles);

                    if (result > 0)
                    {
                        obj.status = 1;
                    }
                    obj.value = result;
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    obj.status  = -1;
                    obj.message = ex.StackTrace;
                }
            }
            return(obj);
        }
Esempio n. 4
0
        public ReturnObject GetAssetByDepartmentID(string DepartmentID)
        {
            ReturnObject obj = new ReturnObject();

            obj.status = -1;
            try
            {
                DaoAsset daoAsset = new DaoAsset(tWG_ACHECKContext);
                var      result   = daoAsset.GetAssetByDepartmentID(DepartmentID);
                obj.status = 1;
                obj.value  = result;
            }
            catch (Exception ex)
            {
                obj.status  = -1;
                obj.message = ex.StackTrace;
            }
            return(obj);
        }
Esempio n. 5
0
        public ReturnObject GetAsset(int page, int pageSize)
        {
            ReturnObject obj = new ReturnObject();

            obj.status = -1;
            try
            {
                DaoAsset daoAsset = new DaoAsset(tWG_ACHECKContext);
                var      result   = daoAsset.GetAll(page, pageSize);
                obj.status = 1;
                obj.value  = result;
            }
            catch (Exception ex)
            {
                obj.status  = -1;
                obj.message = ex.StackTrace;
            }
            return(obj);
        }
Esempio n. 6
0
        public ReturnObject GetAssetByID(string AssetID)
        {
            TWG_HR_API.APIRequest res = new TWG_HR_API.APIRequest(null, null);
            ReturnObject          obj = new ReturnObject();

            obj.status = -1;
            try
            {
                DaoAsset daoAsset = new DaoAsset(tWG_ACHECKContext);
                var      result   = daoAsset.GetAssetByAssetID(AssetID);
                obj.status = 1;
                obj.value  = result;
            }
            catch (Exception ex)
            {
                obj.status  = -1;
                obj.message = ex.StackTrace;
            }
            return(obj);
        }
Esempio n. 7
0
        public async Task <ReturnObject> DeleteAsset(string AssetId)
        {
            ReturnObject obj = new ReturnObject();

            obj.status = -1;
            try
            {
                DaoAsset daoAsset = new DaoAsset(tWG_ACHECKContext);
                var      result   = await daoAsset.DeleteAsset(AssetId);

                if (result > 0)
                {
                    obj.status = 1;
                }
                obj.value = result;
            }
            catch (Exception ex)
            {
                obj.status  = -1;
                obj.message = ex.StackTrace;
            }
            return(obj);
        }
Esempio n. 8
0
        public ReturnObject ImportAsset()
        {
            ReturnObject obj = new ReturnObject();

            obj.status = -1;
            obj.value  = 0;
            ViewImportData entity    = new ViewImportData();
            IFormFile      formFiles = Request.Form.Files.First();

            entity.FileImport = formFiles;
            listWarning       = new List <string>();
            listError         = new List <string>();
            if (entity.FileImport != null)
            {
                IFormFile file = entity.FileImport;
                if (file.Length > 0)
                {
                    entity.fileName = file.FileName;
                    string sFileExtension = Path.GetExtension(file.FileName).ToLower();
                    ISheet sheet;
                    using (var stream = new FileStream(file.FileName, FileMode.Create))
                    {
                        int countUpdate = 0;
                        int countInsert = 0;
                        int countError  = 0;
                        file.CopyTo(stream);
                        stream.Position = 0;
                        XSSFWorkbook hssfwb      = new XSSFWorkbook(stream);
                        XSSFWorkbook hssfwbCheck = hssfwb;
                        if (hssfwb.NumberOfSheets > 0)
                        {
                            sheet = hssfwb.GetSheetAt(0);
                            var header = sheet.GetRow(5);
                            dict.Clear();
                            if (header != null)
                            {
                                Dictionary <string, int> dictHeaders = new Dictionary <string, int>();
                                var lstLines = new List <string>();
                                for (int j = 0; j < header.Cells.Count; j++)
                                {
                                    string key = header.Cells[j].StringCellValue.Trim().ToUpper();
                                    if (dictMap.ContainsKey(key))
                                    {
                                        dict.Add(dictMap[key], j);
                                    }
                                }
                            }
                            //Lấy dữ liệu từ dòng thứ 1
                            for (int rowIndex = 6; rowIndex < sheet.PhysicalNumberOfRows; rowIndex++)
                            {
                                // Lấy row hiện tại
                                var nowRow = sheet.GetRow(rowIndex);
                                if (nowRow.GetCell(1) != null && (nowRow.GetCell(1).CellType.ToString() != "Blank"))
                                {
                                    countInsert++;
                                    //Kiểm tra lỗi
                                    KiemTraLoi(ref nowRow);
                                    countError = listError.Count;
                                    //Nếu không có lỗi mới thực hiện tiếp
                                    if (countError <= 0)
                                    {
                                        var   now   = DateTime.Now.ToString("dd-MMM-yyyy");
                                        Asset asset = new Asset();
                                        asset.AssetCode   = GetString(nowRow, "AssetCode").TrimEnd();
                                        asset.AssetName   = GetString(nowRow, "AssetName").TrimEnd();
                                        asset.Description = GetString(nowRow, "Description").TrimEnd();
                                        asset.Unit        = GetString(nowRow, "Unit").TrimEnd();
                                        asset.Price       = GetInt(nowRow, "Price");
                                        asset.Quantity    = GetInt(nowRow, "Quantity");
                                        asset.LocationID  = GetString(nowRow, "LocationID").TrimEnd();
                                        asset.CategoryID  = GetString(nowRow, "CategoryID").TrimEnd();

                                        entity.lsAsset.Add(asset);
                                    }
                                }
                                else
                                {
                                    listError.Add("File không có dữ liệu hoặc dữ liệu không đúng định dạng");
                                    break;
                                }
                            }
                            if (listError.Count == 0)
                            {
                                DaoAsset daoAsset = new DaoAsset(tWG_ACHECKContext);
                                int      count    = daoAsset.ImportData(entity.lsAsset);
                                if (count > 0)
                                {
                                    obj.value  = count;
                                    obj.status = 1;
                                }
                            }
                        }
                        System.IO.File.Delete(stream.Name);
                        entity.countError  = countError;
                        entity.countUpdate = countUpdate;
                        entity.countInsert = countInsert;
                        entity.listError   = listError;
                        entity.listWarning = listWarning;
                        obj.message        = JsonConvert.SerializeObject(listError).ToString();
                    }
                }
            }
            return(obj);
        }
Esempio n. 9
0
        public void KiemTraLoi(ref IRow row)
        {
            DaoAsset daoAsset = new DaoAsset(tWG_ACHECKContext);
            var      sheet    = row.Sheet;

            try
            {
                var AssetCode   = GetString(row, "AssetCode");
                var AssetName   = GetString(row, "AssetName");
                var Description = GetString(row, "Description");
                var Unit        = GetString(row, "Unit");
                var Price       = GetString(row, "Price");
                var Model       = GetString(row, "Model");
                var Origin      = GetString(row, "Origin");
                var Quantity    = GetString(row, "Quantity");
                var CategoryID  = GetString(row, "CategoryID");
                var LocationID  = GetString(row, "LocationID");

                if (AssetCode != "" && AssetCode.Length > 150)
                {
                    listError.Add("Hàng thứ " + (row.RowNum + 1) + " - Asset Code '" + AssetCode + " có độ dài vượt quá độ dài cho phép.");
                }
                //if (AssetCode == "")
                //{
                //    listError.Add("Hàng thứ " + (row.RowNum + 1) + " - Asset Code không được để trống.");
                //}
                if (!string.IsNullOrEmpty(AssetCode))
                {
                    bool check = daoAsset.CheckUniqueAssetCode(AssetCode, "");
                    if (!check)
                    {
                        listError.Add("Hàng thứ " + (row.RowNum + 1) + " - Asset Code '" + AssetCode + " đã tồn tại.");
                    }
                }
                if (AssetName.Length > 200)
                {
                    listError.Add("Hàng thứ " + (row.RowNum + 1) + " - Tên tài sản '" + AssetCode + " có độ dài vượt quá độ dài cho phép.");
                }
                if (AssetName == "")
                {
                    listError.Add("Hàng thứ " + (row.RowNum + 1) + " - Tên tài sản không được để trống.");
                }
                if (CategoryID.Length > 200)
                {
                    listError.Add("Hàng thứ " + (row.RowNum + 1) + " - Loại tài sản '" + AssetCode + " có độ dài vượt quá độ dài cho phép.");
                }
                if (CategoryID == "")
                {
                    listError.Add("Hàng thứ " + (row.RowNum + 1) + " - Loại tài sản không được để trống.");
                }
                if (LocationID.Length > 200)
                {
                    listError.Add("Hàng thứ " + (row.RowNum + 1) + " - Vị trí tài sản '" + AssetCode + " có độ dài vượt quá độ dài cho phép.");
                }
                if (LocationID == "")
                {
                    listError.Add("Hàng thứ " + (row.RowNum + 1) + " - Vị trí tài sản không được để trống.");
                }
            }
            catch (Exception ex)
            {
                listError.Add(ex.Message.ToString());
            }
        }