public SigmaResultType AddCostCodeMap(TypeCostCodeMap objCostCodeMap)
 {
     SigmaResultType result = new SigmaResultType();
     try
     {
         CostCodeMgr costCodeMgr = new CostCodeMgr();
         result = costCodeMgr.AddCostCodeMap(objCostCodeMap);
         return result;
     }
     catch (Exception ex)
     {
         // Log Exception
         ExceptionHelper.logException(ex);
         result.IsSuccessful = false;
         result.ErrorMessage = ex.Message;
         return result;
     }
 }
예제 #2
0
        public SigmaResultType ImportMeterialLib(string filePath, string exportfilepath)
        {
            MaterialMgr materialMgr = new MaterialMgr();
            CostCodeMgr costCodeMgr = new CostCodeMgr();
            SigmaCodeMgr sigmaCodeMgr = new SigmaCodeMgr();
            TaskCategoryMgr taskCategoryMgr = new TaskCategoryMgr();
            SigmaResultType sigmaResult = new SigmaResultType();
            TypeMaterial typeMaterial = new TypeMaterial();

            DataLoaderMaterialLib loader = new DataLoaderMaterialLib();

            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.GetDataLoaderMaterialLib(Exceldt);

                string codeName = "ALL";
                string codeCategoryUOM = "UOM";
                string codeCategoryDiscipline = "DISCIPLINE";

                DataSet CostCodeDS = costCodeMgr.ListCostCodeForMaterial();
                DataSet SigmaCodeDisciplineDS = sigmaCodeMgr.ListSigmaCodeByCodeCategory(codeName, codeCategoryDiscipline);
                DataSet SigmaCodeUOMDS = sigmaCodeMgr.ListSigmaCodeByCodeCategory(codeName, codeCategoryUOM);
                DataRow DisciplineCode = SigmaCodeDisciplineDS.Tables[0].Select("CodeName = '" + Exceldt.Rows[0][loader.Ord_Disicipline] + "'").FirstOrDefault();
                DataSet TaskCategoryDS = taskCategoryMgr.ListTaskCategoryByDisciplineCode(DisciplineCode[0].ToString());
                DataSet TaskTypeDS = taskCategoryMgr.ListTaskTypeByDisciplineCode(DisciplineCode[0].ToString());

                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 Discipline = null;
                    if (isValidation)
                    {
                        Discipline = SigmaCodeDisciplineDS.Tables[0].Select("CodeName = '" + row[loader.Ord_Disicipline] + "'").FirstOrDefault();
                        if (Discipline == 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_Disicipline].ToString() + "]";
                            failCount = failCount + 1;
                            isValidation = false;
                        }
                    }

                    DataRow TaskCategory = null;
                    if (isValidation)
                    {
                        TaskCategory = TaskCategoryDS.Tables[0].Select("TaskCategoryName = '" + row[loader.Ord_TaskCategory] + "'").FirstOrDefault();
                        if (TaskCategory == 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_TaskCategory].ToString() + "]";
                            failCount = failCount + 1;
                            isValidation = false;
                        }
                    }

                    DataRow TaskType = null;
                    if (isValidation)
                    {
                        TaskType = TaskTypeDS.Tables[0].Select("TaskTypeName = '" + row[loader.Ord_TaskType] + "'").FirstOrDefault();
                        if (TaskType == 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_TaskType].ToString() + "]";
                            failCount = failCount + 1;
                            isValidation = false;
                        }
                    }

                    DataRow UOM = null;
                    if (isValidation)
                    {
                        UOM = SigmaCodeUOMDS.Tables[0].Select("CodeShortName = '" + row[loader.Ord_UOM] + "' OR CodeName = '" + row[loader.Ord_UOM] + "'").FirstOrDefault();
                        if (UOM == 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_UOM].ToString() + "]";
                            failCount = failCount + 1;
                            isValidation = false;
                        }
                    }

                    DataRow CostCode = null;
                    if (isValidation && !string.IsNullOrEmpty(row[loader.Ord_CostCode].ToString()))
                    {
                        CostCode = CostCodeDS.Tables[0].Select("CostCode = '" + row[loader.Ord_CostCode] + "'").FirstOrDefault();
                        if (CostCode == 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_CostCode].ToString() + "]";
                            failCount = failCount + 1;
                            isValidation = false;
                        }
                    }

                    #endregion Reference Check

                    #region Duplication Check

                    if (isValidation)
                    {
                        string disciplineCode = Discipline["Code"].ToString().Trim();
                        string taskCategoryId = TaskCategory["TaskCategoryId"].ToString();
                        string taskTypeId = TaskType["TaskTypeId"].ToString();
                        string uomCode = UOM["Code"].ToString().Trim();
                        string description = row[loader.Ord_MaterialDescription] == null ? "" : row[loader.Ord_MaterialDescription].ToString();

                        DataSet MaterialDS = materialMgr.ListMaterialByDisciplineTaskCategory(disciplineCode, taskCategoryId, taskTypeId, description, uomCode);

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

                    #endregion Duplication Check

                    #region AddMaterial

                    if (isValidation)
                    {
                        typeMaterial.DisciplineCode = Discipline["Code"].ToString().Trim();
                        typeMaterial.TaskCategoryId = Utilities.ToInt32(TaskCategory["TaskCategoryId"].ToString().Trim());
                        typeMaterial.TaskTypeId = Utilities.ToInt32(TaskType["TaskTypeId"].ToString().Trim());
                        typeMaterial.Manhours = Utilities.ToDecimal(row[loader.Ord_ManHour].ToString().Trim());
                        typeMaterial.UomCode = UOM["Code"].ToString().Trim();
                        typeMaterial.Vendor = row[loader.Ord_Vendor].ToString();
                        typeMaterial.Description = row[loader.Ord_MaterialDescription].ToString().Trim();
                        typeMaterial.PartNumber = row[loader.Ord_PartNumber].ToString().Trim();
                        typeMaterial.CostCodeId = (CostCode == null) ? 0 : Utilities.ToInt32(CostCode["CostCodeId"].ToString().Trim());
                        typeMaterial.CreatedBy = userinfo.SigmaUserId;

                        sigmaResult = materialMgr.AddMaterial(typeMaterial);

                        if (sigmaResult.IsSuccessful)
                        {
                            // CustomField
                            for (int i = 0; i < columnCount; i++)
                            {
                                if (Exceldt.Columns[i].ToString().Substring(0, 3).ToUpper() == "UD_")
                                {
                                    string RowValue = row.ItemArray.GetValue(i).ToString();
                                    if (!string.IsNullOrEmpty(RowValue))
                                    {
                                        sigmaResult.IsSuccessful = CheckMaterialCustomField(Exceldt, Exceldt.Columns[i].ToString().Trim(), sigmaResult.ScalarValue, RowValue);
                                    }
                                }
                            }
                        }
                    }

                    #endregion AddMaterial

                }

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

                // 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;
        }
예제 #3
0
        public SigmaResultType ImportFile()
        {
            SigmaResultType result = new SigmaResultType();
            try
            {
                var queryStr = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters;
                string fileType = queryStr["filetype"];
                string filePath = queryStr["filepath"];

                //string rootPath = System.Web.Configuration.WebConfigurationManager.AppSettings["DocumentUpload"];
                //string targetPath = System.Web.Configuration.WebConfigurationManager.AppSettings["DocumentFolderRoot"];

                string rootPath = ConfigMgr.GetImportFilePath();

                filePath = rootPath + filePath;

                //fileType = "DrawingImage";

                // ImportFile
                switch (fileType)
                {
                    case "Drawing":
                        //importDrawing importDrawing = new ImportDrawing();
                        ImportDrawingMgr importDrawing = new ImportDrawingMgr();
                        result = importDrawing.AddDrawing(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    case "DrawingImage":
                        //ImportDrawing importDrawingImage = new ImportDrawing();
                        ImportDrawingMgr importDrawingImage = new ImportDrawingMgr();
                        //result = importDrawingImage.AddDrawingImage(filePath, targetPath);
                        result = importDrawingImage.AddDrawingImage(filePath, ConfigMgr.GetTargetPath());
                        break;
                    case "MTO":
                        ImportMgr importMgr = new ImportMgr();
                        result = importMgr.ImportMTOFromExcel(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    case "CostCode":
                        CostCodeMgr costcodeMgr = new CostCodeMgr();
                        result = costcodeMgr.ImportCostCodeFromExcel(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    case "ProjectCostCode":
                        CostCodeMgr projectcostcodeMgr = new CostCodeMgr();
                        result = projectcostcodeMgr.ImportProjectCostCodeFromExcel(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    case "ClientCostCode":
                        CostCodeMgr clientcostcodeMgr = new CostCodeMgr();
                        result = clientcostcodeMgr.ImportClientCostCodeFromExcel(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    case "HR":
                        PersonnelMgr personnelMgr = new PersonnelMgr();
                        result = personnelMgr.ImportPersonnelFromExcel(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    case "User":
                        SigmaUserMgr sigmauserMgr = new SigmaUserMgr();
                        result = sigmauserMgr.ImportSigmaUserFromExcel(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    case "MeterialLibrary":
                        ImportMgr importMeterial = new ImportMgr();
                        result = importMeterial.ImportMeterialLib(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    case "EquipmentLibrary":
                        ImportMgr importEquipment = new ImportMgr();
                        result = importEquipment.ImportEquipmentLib(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    case "ConsumableLibrary":
                        ImportMgr importConsumable = new ImportMgr();
                        result = importConsumable.ImportConsumableLib(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    case "DrawingType":
                        ImportMgr importDrawingType = new ImportMgr();
                        result = importDrawingType.ImportDrawingTypeLib(filePath, ConfigMgr.GetExportFilePath());
                        break;
                    default:
                        break;
                }
                return result;

            }
            catch (Exception ex)
            {
                // Log Exception
                ExceptionHelper.logException(ex);
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
        public SigmaResultType MultiProjectCostCode(List<TypeProjectCostCode> listObj)
        {
            SigmaResultType result = new SigmaResultType();

            try
            {
                CostCodeMgr costCodeMgr = new CostCodeMgr();
                result = costCodeMgr.MultiProjectCostCode(listObj);
                return result;
            }
            catch (Exception ex)
            {
                // Log Exception
                ExceptionHelper.logException(ex);
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
        public SigmaResultType ListProjectCostCodeForMap()
        {
            SigmaResultType result = new SigmaResultType();
            try
            {
                var queryStr = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters;
                string max = queryStr["max"];
                string offset = queryStr["offset"];
                string s_option = queryStr["s_option"];
                string s_key = queryStr["s_key"];
                string o_option = queryStr["o_option"];
                string o_desc = queryStr["o_desc"];

                CostCodeMgr costCodeMgr = new CostCodeMgr();
                result = costCodeMgr.ListProjectCostCodeForMap(offset, max, s_option, s_key, o_option, o_desc);
                return result;
            }
            catch (Exception ex)
            {
                // Log Exception
                ExceptionHelper.logException(ex);
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
 public SigmaResultType GetProjectCostCode(string CostCode)
 {
     SigmaResultType result = new SigmaResultType();
     try
     {
         CostCodeMgr costCodeMgr = new CostCodeMgr();
         result = costCodeMgr.GetProjectCostCode(CostCode);
         return result;
     }
     catch (Exception ex)
     {
         // Log Exception
         ExceptionHelper.logException(ex);
         result.IsSuccessful = false;
         result.ErrorMessage = ex.Message;
         return result;
     }
 }
        public SigmaResultType UpdateClientCostCode(TypeClientCostCode objClientCostCode)
        {
            SigmaResultType result = new SigmaResultType();

            try
            {
                CostCodeMgr costCodeMgr = new CostCodeMgr();
                result = costCodeMgr.UpdateClientCostCode(objClientCostCode);
                return result;
            }
            catch (Exception ex)
            {
                // Log Exception
                ExceptionHelper.logException(ex);
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
        public SigmaResultType ListCostCode()
        {
            SigmaResultType result = new SigmaResultType();
            try
            {
                var queryStr = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters;
                string max = queryStr["max"];
                string offset = queryStr["offset"];

                List<string> s_option = new List<string>();
                List<string> s_key = new List<string>();
                s_option.Add("@CostCode");
                s_option.Add("@Description");
                s_key.Add(queryStr["CostCode"]);
                s_key.Add(queryStr["Description"]);

                string o_option = queryStr["o_option"];
                string o_desc = queryStr["o_desc"];

                CostCodeMgr costCodeMgr = new CostCodeMgr();

                //generate template
                costCodeMgr.SetProjectCostCodeTemplate(ConfigMgr.GetDynamicTemplateFilePath("costcode"));

                result = costCodeMgr.ListCostCode(offset, max, s_option, s_key, o_option, o_desc);

                return result;
            }
            catch (Exception ex)
            {
                // Log Exception
                ExceptionHelper.logException(ex);
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }