예제 #1
0
 public void Update(Budget_FileVersionBudget instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException();
     }
     this._repository.Update(instance);
 }
예제 #2
0
 public string Create(Budget_FileVersionBudget instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException();
     }
     return(this._repository.Create(instance));
 }
        /// <summary>
        /// you need to approve the row data that the user can duplicate upload
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool UpdateFileVersionBudgetApprove(int Id)
        {
            bool _Success = false;
            Budget_FileVersionBudget _Budget_FileVersionBudget = this._budget_FileVersionBudgetService.GetByID(Id);

            _Budget_FileVersionBudget.Approve = true;
            this._budget_FileVersionBudgetService.Update(_Budget_FileVersionBudget);
            _Success = true;
            return(_Success);
        }
        /// <summary>
        /// insert Budget_FileVersionBudget data
        /// </summary>
        /// <param name="_Budget_FileVersionBudget"></param>
        /// <param name="account">altw id</param>
        /// <param name="itemId_BudgetName">budget item id</param>
        /// <param name="departmentId">department id</param>
        /// <param name="factory">LT/KS</param>
        /// <param name="uploadLogId"></param>
        /// <param name="itemId_CostCommon"></param>
        /// <returns></returns>
        private Budget_FileVersionBudget setBudget_FileVersionBudget(Budget_FileVersionBudget _Budget_FileVersionBudget, string account, string itemId_BudgetName, string departmentId, string factory, int uploadLogId, string itemId_CostCommon)
        {
            string _Version = _Budget_FileVersionBudget != null?Convert.ToString(Convert.ToInt32(_Budget_FileVersionBudget.Version) + 1).PadLeft(4, '0') : "0001";

            if (_Budget_FileVersionBudget == null)
            {
                _Budget_FileVersionBudget = new Budget_FileVersionBudget();
            }
            _Budget_FileVersionBudget.Date              = (DateTime.Now.Year + 1).ToString();
            _Budget_FileVersionBudget.Version           = _Version;
            _Budget_FileVersionBudget.Approve           = false;
            _Budget_FileVersionBudget.Account           = account;
            _Budget_FileVersionBudget.ItemId_BudgetName = itemId_CostCommon != "" ? itemId_CostCommon : itemId_BudgetName;
            _Budget_FileVersionBudget.DepartmentId      = departmentId;
            _Budget_FileVersionBudget.Factory           = factory;
            _Budget_FileVersionBudget.UploadLogId       = uploadLogId;
            return(_Budget_FileVersionBudget);
        }
        /// <summary>
        /// 1. upload file (excel)
        /// 2. get file version data to judge you got approved
        /// 3. parse excel column value
        /// 4. batch insert  data
        /// 5. copy file to success directory
        /// 6. insert uploadlog
        /// 7. insert update FileVersionBudget
        /// </summary>
        /// <returns></returns>
        public List <string> UploadFile()
        {
            string _ItemId            = HttpContext.Current.Request["ItemId"].ToString();
            string _ItemId_CostCommon = "";
            //  string _ItemId = "00000000";
            string                   _DepartmentId             = HttpContext.Current.Request["DepartmentId"].ToString();
            string                   _Factory                  = HttpContext.Current.Request["Factory"].ToString();
            string                   _Account                  = HttpContext.Current.Request["Account"].ToString();
            List <string>            _ListError                = new List <string>();
            string                   _FilePath                 = this._commonFileService.Upload();
            int                      _LoginID                  = HttpContext.Current.Request["LoginID"].ToString() != "" ? Convert.ToInt32(HttpContext.Current.Request["LoginID"].ToString()) : 0;
            string                   _TableName                = "";
            Budget_FileVersionBudget _Budget_FileVersionBudget = new Budget_FileVersionBudget();

            if (this._itemCatalogService.GetByItemIdInClassName(_ItemId, "CostCommon") != null)
            {
                _Budget_FileVersionBudget = this._budget_FileVersionBudgetService.GetLastVersion(_ItemId, (DateTime.Now.Year + 1).ToString(), _Factory);
                _ItemId_CostCommon        = _ItemId;
                _ItemId = "CostCommon";
            }
            else if (_ItemId == "PartTime")
            {
                _Budget_FileVersionBudget = this._budget_FileVersionBudgetService.GetLastVersion(_ItemId, (DateTime.Now.Year + 1).ToString(), _Factory);
            }
            else
            {
                _Budget_FileVersionBudget = this._budget_FileVersionBudgetService.GetLastVersion(_ItemId, _DepartmentId, _Factory, (DateTime.Now.Year + 1).ToString());
            }
            if ((_Budget_FileVersionBudget != null) && (!Convert.ToBoolean(_Budget_FileVersionBudget.Approve)))
            {
                throw new Exception("please inform Iris(#6802) to approve you duplicate upload ");
            }
            string _Version = _Budget_FileVersionBudget != null?Convert.ToString(Convert.ToInt32(_Budget_FileVersionBudget.Version) + 1).PadLeft(4, '0') : "0001";

            Budget _Budget = parse(_FilePath, _ItemId, _DepartmentId, _Factory, _Version, _ItemId_CostCommon);

            _ListError = miltiCreate(_ItemId, _Budget, out _TableName);
            bool      _Success        = _ListError.Count > 1 ? false : true;
            string    _ServerFileName = this._commonFileService.SaveToSuccess(_LoginID, _FilePath, _TableName);
            string    _UploadLogError = this._commonFileService.InsertUploadLog(_LoginID, _FilePath, _TableName, _Success, _ServerFileName);
            UploadLog _UploadLog      = this._uploadLogService.GetAll().Where(x => x.FK_LoginId == _LoginID).OrderByDescending(x => x.Id).First();
            Budget_FileVersionBudget _SetBudget_FileVersionBudget = setBudget_FileVersionBudget(_Budget_FileVersionBudget, _Account, _ItemId, _DepartmentId, _Factory, _UploadLog.Id, _ItemId_CostCommon);

            if (_Budget_FileVersionBudget != null)
            {
                this._budget_FileVersionBudgetService.Update(_SetBudget_FileVersionBudget);
            }
            else
            {
                this._budget_FileVersionBudgetService.Create(_SetBudget_FileVersionBudget);
            }
            if (_UploadLogError != "")
            {
                _ListError.Add(_UploadLogError);
            }
            if (_ListError.Count > 0)
            {
                _ListError[0] = _ListError[0] + "ms";
            }
            return(_ListError);
        }