コード例 #1
0
ファイル: IdxIndexDAO.cs プロジェクト: pvthang810/PsMModel
        private void SaveMoney(IdxIndexModels index, SysUserModels userSession)
        {
            // Check exist index

            IDictionary<string, object> param = new Dictionary<string, object>();
            string timeFormat = Resource.DateFormat;
            string displayTimeFormat = Resource.DateFormat;
            Int32 precision = Int32.Parse(Resource.Precision);

            MstIndexTypeDAO indexTypeDAO = new MstIndexTypeDAO(this.mapper);

            MstIndexTypeModels indexTypeModel = indexTypeDAO.GetIndexType(index.indexTypeCode);
            if (indexTypeModel != null)
            {
                displayTimeFormat = indexTypeModel.displayTimeFormat;
                timeFormat = indexTypeModel.typeTimeFormat;
                precision = indexTypeModel.precisionField;

                // Check exist index
                param.Add("indexCode", index.indexCode);
                param.Add("term", index.term);
                param.Add("indexTypeCode", index.indexTypeCode);
                param.Add("seqNo", index.seqNo);
                param.Add("indexTime", index.indexTime);
                param.Add("displayTimeFormat", Int32.Parse(displayTimeFormat));

                Hashtable obj = (Hashtable)mapper.QueryForObject("Idx.selectIndex", param);
                index.updatedBy = userSession.userCode;
                index.createdBy = userSession.userCode;
                index.indexStatus = Constants.Status.Active;
                // If not exist -> Insert
                if (obj == null)
                {
                    mapper.Insert("Idx.insertIndex", index);
                }
                else // If exist -> Update
                {
                    param.Add("indexMoney", index.indexMoney);
                    param.Add("updatedBy", index.updatedBy);
                    mapper.Update("Idx.updateIndex", param);
                }
            }
            else
            {
                mapper.Insert("Idx.insertIndex", index);
            }
        }
コード例 #2
0
        public IList<IdxIndexModels> GetIndexFromExcel(DataTable dtIndex, ISqlMapper mapper, out string errorMsg)
        {
            string term = null;
            IList<IdxIndexModels> indexList = new List<IdxIndexModels>();
            errorMsg = "";
            // Check file type
            if (!StringUtils.IsEmpty(dtIndex.Columns[0].ColumnName) && dtIndex.Columns[0].ColumnName.Equals(Constants.FileType.ShortIndex))
            {
                term = Constants.Term.ShortTerm;
            }
            else if (!StringUtils.IsEmpty(dtIndex.Columns[0].ColumnName) && dtIndex.Columns[0].ColumnName.Equals(Constants.FileType.MiddleIndex))
            {
                term = Constants.Term.MidTerm;
            }
            else if (!StringUtils.IsEmpty(dtIndex.Columns[0].ColumnName) && dtIndex.Columns[0].ColumnName.Equals(Constants.FileType.LongIndex))
            {
                term = Constants.Term.LongTerm;
            }
            else
            {
                errorMsg = string.Format(Resource.MsgErrWrongSelection, Resource.IndexFile);
                return null;
            }

            // Get Index TypeCode
            string indexTypeCode = "";

            // Exact indexCode
            MstIndexDAO mstIndexDAO = new MstIndexDAO(mapper);
            int seqNo = 0;
            string previousItemCode = "";
            List<IdxIndexModels> indexCodeList = new List<IdxIndexModels>();
            int i = 0;
            foreach (DataRow row in dtIndex.Rows)
            {
                i++;
                IdxIndexModels index = new IdxIndexModels();
                string indexName = row[0].ToString();
                if (indexName.Equals(Resource.ExcelEndChar)
                    || StringUtils.IsEmpty(indexName)
                    ) break;

                if (StringUtils.IsEmpty(indexName))
                {
                    index.indexCode = previousItemCode;
                    seqNo++;
                    index.seqNo = seqNo;
                }
                else
                {
                    MstIndexModels indexModels = mstIndexDAO.GetIndexCode(indexName.Trim(), "", term);
                    if (indexModels == null)
                    {
                        errorMsg = string.Format(Resource.MsgErrIndexNotExist, indexName.Trim());
                        return null;
                    }
                    indexTypeCode = indexModels.indexTypeCode;
                    String indexCode = indexModels.indexCode;
                    if (indexCode == null)
                    {
                        errorMsg = string.Format(Resource.MsgErrNotExistIndexNameUploadExcelFile, new String[] { i.ToString(), "1", indexName });
                        return null;
                    }
                    previousItemCode = indexCode; // = ws.Cell(i, 1).Value;
                    index.indexCode = previousItemCode;
                    index.seqNo = 0;
                    seqNo = 0;
                }
                index.indexTypeCode = indexTypeCode;

                indexCodeList.Add(index);
            }

            // Get Index TypeCode
            MstIndexTypeDAO indexTypeDAO = new MstIndexTypeDAO(mapper);

            MstIndexTypeModels indexTypeModel = indexTypeDAO.GetIndexType(indexTypeCode);
            if (indexTypeModel == null)
            {
                errorMsg = string.Format(Resource.MsgErrIndexTypeNotExist, indexTypeCode);
                return null;
            }
            string timeFormat = indexTypeModel.typeTimeFormat;

            // Exact time
            IList<DateTime> timeList = new List<DateTime>();
            for (i=1; i<dtIndex.Columns.Count; i++)
            {
                string time = dtIndex.Columns[i].ToString();
                if (time.Equals(Resource.ExcelEndChar)
                    || StringUtils.IsEmpty(time)
                    || time.Contains("Column")
                    ) break;

                try
                {
                    timeList.Add(DateTime.ParseExact(time, timeFormat, null));
                }
                catch (Exception e)
                {
                    errorMsg = string.Format(Resource.MsgErrDateFormatUploadExcelFile, new String[] { "1", i.ToString(), time });
                    return null;
                }
            }

            // Exact index
            for (int currentRowIndex = 0; currentRowIndex < indexCodeList.Count; currentRowIndex++)
            {
                IdxIndexModels indexCode = indexCodeList[currentRowIndex];
                for (int currentColumnIndex = 0; currentColumnIndex < timeList.Count; currentColumnIndex++)
                {
                    IdxIndexModels index = new IdxIndexModels();
                    index.indexTypeCode = indexCode.indexTypeCode.Trim();
                    index.indexCode = indexCode.indexCode.Trim();
                    index.seqNo = indexCode.seqNo;
                    index.indexTime = timeList[currentColumnIndex];
                    try
                    {
                        index.indexField = double.Parse(dtIndex.Rows[currentRowIndex][currentColumnIndex+1].ToString());
                    }
                    catch (Exception e)
                    {
                        errorMsg = string.Format(Resource.MsgErrNumberFormatUploadExcelFile
                            , new String[] { (currentRowIndex+2).ToString(), (currentColumnIndex+2).ToString(), dtIndex.Rows[currentRowIndex][currentColumnIndex+1].ToString() });
                        return null;
                    }
                    index.term = term;
                    indexList.Add(index);
                }
            }

            return indexList;
        }