コード例 #1
0
ファイル: ImportMgr.cs プロジェクト: paraneye/WebService
        public SigmaResultType ImportDrawingTypeLib(string filePath, string exportfilepath)
        {
            SigmaCodeMgr sigmaCodeMgr = new SigmaCodeMgr();
            CommonCodeMgr commonCodeMgr = new CommonCodeMgr();
            SigmaResultType sigmaResult = new SigmaResultType();
            TypeSigmaCode typeSigmaCode = new TypeSigmaCode();

            DataLoaderDrawingType loader = new DataLoaderDrawingType();

            DataTable Exceldt = Element.Shared.Common.ImportHelper.ImportWorkSheet(filePath, true);
            DataTable ErrDataTable = SetErrTable(Exceldt);

            int failCount = 0;
            int rowCount = Exceldt.Rows.Count;
            int columnCount = Exceldt.Columns.Count;

            if (rowCount > 0)
            {
                loader = MTOImportHelper.GetDataLoaderDrawingType(Exceldt);

                string codeCategory = "DRAWING_TYPE";

                foreach (DataRow row in Exceldt.Rows)
                {
                    bool isValidation = true;

                    #region Mandatory Check (*)

                    for (int i = 0; i < columnCount; i++)
                    {
                        if (Exceldt.Columns[i].ToString().Substring(0, 1).ToUpper() == "*" && string.IsNullOrEmpty(row.ItemArray.GetValue(i).ToString()))
                        {
                            ErrDataTable.Rows.Add(row.ItemArray);
                            ErrDataTable.Rows[ErrDataTable.Rows.Count - 1]["Fail Reason"] = "The value of [" + Exceldt.Columns[i].ToString() + "] is required.";
                            failCount = failCount + 1;
                            isValidation = false;
                            break;
                        }
                    }

                    #endregion Mandatory Check

                    #region Reference Check (SigmaCode Table)

                    //DataRow DrawingType = null;
                    //if (isValidation)
                    //{
                    //    DrawingType = SigmaCodeDT.Select("CodeName = '" + row[loader.Ord_DrawingType] + "'").FirstOrDefault();
                    //    if (DrawingType == null)
                    //    {
                    //        ErrDataTable.Rows.Add(row.ItemArray);
                    //        ErrDataTable.Rows[ErrDataTable.Rows.Count - 1]["Fail Reason"] = "There is no item in the library to match up with the value of [" + row[loader.Ord_DrawingType].ToString() + "]";
                    //        failCount = failCount + 1;
                    //        isValidation = false;
                    //    }
                    //}

                    #endregion Reference Check

                    #region Duplication Check

                    if (isValidation)
                    {
                        string codeName = row[loader.Ord_DrawingType].ToString();

                        DataSet SigmaCodeDS = sigmaCodeMgr.ListSigmaCodeByCodeCategory(codeName, codeCategory);

                        if (SigmaCodeDS.Tables[0].Rows.Count > 0)
                        {
                            ErrDataTable.Rows.Add(row.ItemArray);
                            ErrDataTable.Rows[ErrDataTable.Rows.Count - 1]["Fail Reason"] = "This data[Drawing Type] is duplicated.";
                            failCount = failCount + 1;
                            isValidation = false;
                        }
                    }

                    #endregion Duplication Check

                    #region AddSigmaCode

                    if (isValidation)
                    {
                        typeSigmaCode.Code = "";
                        typeSigmaCode.CodeCategory = codeCategory;
                        typeSigmaCode.CodeName = row[loader.Ord_DrawingType].ToString().Trim();
                        typeSigmaCode.CodeShortName = row[loader.Ord_DrawingType].ToString().Trim();
                        typeSigmaCode.RefChar = "";
                        typeSigmaCode.RefNo = "";
                        typeSigmaCode.Description = row[loader.Ord_Description].ToString();
                        typeSigmaCode.IsActive = "Y";
                        typeSigmaCode.SortOrder = "";
                        typeSigmaCode.SigmaOperation = "C";
                        typeSigmaCode.CreatedBy = userinfo.SigmaUserId;

                        sigmaResult = sigmaCodeMgr.AddSigmaCode(typeSigmaCode);
                    }

                    #endregion AddSigmaCode

                }

                // Set ImportHistory(SuccessCount/FailCount)
                sigmaResult = AddImportHistory(Exceldt.Rows.Count, failCount, Path.GetFileName(filePath).ToString(), "DrawingType");

                // ConvertExcel file && CSV file
                Export2Excel.ConvertExcelfromData(ErrDataTable, sigmaResult.ScalarValue.ToString() + ".xlsx", exportfilepath);
                Export2Excel.ConvertCSVFile(ErrDataTable, sigmaResult.ScalarValue.ToString() + ".csv", exportfilepath);

                sigmaResult.IsSuccessful = true;
            }
            else
            {
                sigmaResult.IsSuccessful = false;
                sigmaResult.ErrorMessage = "no record from file.";
            }

            return sigmaResult;
        }
コード例 #2
0
        /// <summary>
        /// Import Drawing Type Data(Excel)
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DataLoaderDrawingType GetDataLoaderDrawingType(DataTable dt)
        {
            DataLoaderDrawingType loader = new DataLoaderDrawingType();

            foreach (DataColumn column in dt.Columns)
            {
                string mycol = column.ColumnName.Trim().ToUpper().Replace("*", "").Replace(" ", "").Replace("-", "").Replace("_", "");

                switch (mycol)
                {
                    case "DRAWINGTYPE":
                        loader.Ord_DrawingType = column.Ordinal;
                        break;
                    case "DRAWINGDESCRIPTION":
                        loader.Ord_Description = column.Ordinal;
                        break;
                }
            }

            return loader;
        }