コード例 #1
0
ファイル: ImportMgr.cs プロジェクト: paraneye/WebService
        public SigmaResultType ImportEquipmentLib(string filePath, string exportfilepath)
        {
            EquipmentMgr equipmentMgr = new EquipmentMgr();
            SigmaCodeMgr sigmaCodeMgr = new SigmaCodeMgr();
            SigmaResultType sigmaResult = new SigmaResultType();
            TypeEquipment typeEquipment = new TypeEquipment();
            DataLoaderEquipmentLib loader = new DataLoaderEquipmentLib();

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

                string parentCodeCategory = "EQUIP%";
                string categoryName = "ALL";
                string codeCategory = "EQUIP_%";

                DataSet SigmaCodeCategoryDS = sigmaCodeMgr.ListSigmaCodeCategoryByParentCodeCategory(parentCodeCategory, categoryName);
                DataSet SigmaCodeDS = sigmaCodeMgr.ListSigmaCodeForEquipment(codeCategory);

                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 (SigmaCodeCategory Table)

                    DataRow EquipmentCodeMain = null;
                    DataRow EquipmentCodeSub = null;
                    DataRow ThirdLevel = null;
                    if (isValidation)
                    {
                        EquipmentCodeMain = SigmaCodeCategoryDS.Tables[0].Select("CategoryName = '" + row[loader.Ord_EquipCodeMain] + "'").FirstOrDefault();
                        if (EquipmentCodeMain == 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_EquipCodeMain].ToString() + "]";
                            failCount = failCount + 1;
                            isValidation = false;
                        }
                    }
                    if (isValidation)
                    {
                        EquipmentCodeSub = SigmaCodeCategoryDS.Tables[0].Select("ParentCodeCategory = '" + EquipmentCodeMain["CodeCategory"] + "' AND CategoryName = '" + row[loader.Ord_EquipCodeSub] + "'").FirstOrDefault();
                        if (EquipmentCodeSub == 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_EquipCodeSub].ToString() + "]";
                            failCount = failCount + 1;
                            isValidation = false;
                        }
                    }
                    if (isValidation && !string.IsNullOrEmpty(row[loader.Ord_ThirdLevel].ToString()))
                    {
                        ThirdLevel = SigmaCodeDS.Tables[0].Select("CodeCategory = '" + EquipmentCodeSub["CodeCategory"] + "' AND CodeName = '" + row[loader.Ord_ThirdLevel] + "'").FirstOrDefault();
                        if (ThirdLevel == 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_ThirdLevel].ToString() + "]";
                            failCount = failCount + 1;
                            isValidation = false;
                        }
                    }

                    #endregion Reference Check

                    #region Duplication Check

                    if (isValidation)
                    {
                        string equipmentCodeMain = row[loader.Ord_EquipCodeMain].ToString();
                        string equipmentCodeSub = row[loader.Ord_EquipCodeSub].ToString();
                        string thirdLevel = row[loader.Ord_ThirdLevel].ToString();
                        string spec = row[loader.Ord_Spec].ToString().Replace("'", "’");
                        string equipmentType = row[loader.Ord_EquipmentType].ToString();

                        DataSet EquipmentDS = equipmentMgr.ListMaterialByEquipmentCodeMain(equipmentCodeMain, equipmentCodeSub, thirdLevel, spec, equipmentType);

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

                    #endregion Duplication Check

                    #region AddEquipment

                    if (isValidation)
                    {
                        typeEquipment.EquipmentCodeMain = EquipmentCodeMain["CodeCategory"].ToString();
                        typeEquipment.EquipmentCodeSub = EquipmentCodeSub["CodeCategory"].ToString();
                        typeEquipment.ThirdLevel = (ThirdLevel == null) ? "" :ThirdLevel["Code"].ToString().Trim() ;
                        typeEquipment.Spec = row[loader.Ord_Spec].ToString().Replace("'", "’");
                        typeEquipment.EquipmentType = row[loader.Ord_EquipmentType].ToString();
                        typeEquipment.ModelNumber = row[loader.Ord_ModelNumber].ToString();
                        typeEquipment.Description = row[loader.Ord_Description].ToString();
                        typeEquipment.CreatedBy = userinfo.SigmaUserId;

                        sigmaResult = equipmentMgr.AddEquipment(typeEquipment);

                        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();
                                    sigmaResult.IsSuccessful = CheckEquipmentCustomField(Exceldt, Exceldt.Columns[i].ToString().Trim(), sigmaResult.ScalarValue, RowValue);
                                }
                            }
                        }
                    }

                    #endregion AddEquipment

                }

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

                // 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
ファイル: ImportMgr.cs プロジェクト: paraneye/WebService
        private bool CheckEquipmentCustomField(DataTable Exceldt, string ColName, int EquipmentId, string CustomFieldValue)
        {
            CommonCodeMgr common = new CommonCodeMgr();
            CustomFieldMgr customFieldMgr = new CustomFieldMgr();
            EquipmentMgr equipmentMgr = new EquipmentMgr();
            MaterialCustomFieldMgr materialCustomFieldMgr = new MaterialCustomFieldMgr();

            TypeCustomField customField = new TypeCustomField();
            TypeEquipmentCustomField equipmentCustomField = new TypeEquipmentCustomField();

            SigmaResultType mResult = new SigmaResultType();
            SigmaResultType cResult = new SigmaResultType();

            DataSet CustomFiledSD = materialCustomFieldMgr.ListMaterialCustomFieldByFieldName(ColName);
            DataRow CustomFiledSR = CustomFiledSD.Tables[0].Rows[0];

            if (CustomFiledSD.Tables[0].Rows.Count > 0)
            {
                equipmentCustomField.EquipmentId = EquipmentId;
                equipmentCustomField.CustomFieldId = Convert.ToInt32(CustomFiledSR["CustomFieldId"].ToString());
                equipmentCustomField.Value = CustomFieldValue;
                equipmentCustomField.CreatedBy = userinfo.SigmaUserId;

                mResult = equipmentMgr.AddEquipmentCustomField(equipmentCustomField);
            }
            else
            {
                customField.FieldName = ColName;
                customField.IsDisplayable = "Y";
                customField.CreatedBy = userinfo.SigmaUserId;

                cResult = customFieldMgr.AddCustomField(customField);

                if (cResult.IsSuccessful)
                {
                    equipmentCustomField.EquipmentId = EquipmentId;
                    equipmentCustomField.CustomFieldId = cResult.ScalarValue;
                    equipmentCustomField.Value = CustomFieldValue;
                    equipmentCustomField.CreatedBy = userinfo.SigmaUserId;

                    mResult = equipmentMgr.AddEquipmentCustomField(equipmentCustomField);
                }
            }

            return mResult.IsSuccessful;
        }
コード例 #3
0
 public SigmaResultType GetEquipment(string equipmentId)
 {
     SigmaResultType result = new SigmaResultType();
     try
     {
         EquipmentMgr equipmentMgr = new EquipmentMgr();
         result = equipmentMgr.GetEquipment(equipmentId);
         return result;
     }
     catch (Exception ex)
     {
         // Log Exception
         ExceptionHelper.logException(ex);
         result.IsSuccessful = false;
         result.ErrorMessage = ex.Message;
         return result;
     }
 }
コード例 #4
0
        public SigmaResultType UpdateEquipment(TypeEquipment objEquipment)
        {
            SigmaResultType result = new SigmaResultType();

            try
            {
                EquipmentMgr materialMgr = new EquipmentMgr();
                result = materialMgr.AddEquipmentInfo(objEquipment);
                result.IsSuccessful = true;
                return result;
            }
            catch (Exception ex)
            {
                // Log Exception
                ExceptionHelper.logException(ex);
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
コード例 #5
0
        //public SigmaResultType RemoveEquipment(TypeEquipment objEquipment)
        //{
        //    SigmaResultType result = new SigmaResultType();
        //    try
        //    {
        //        EquipmentMgr equipmentMgr = new EquipmentMgr();
        //        result = equipmentMgr.RemoveEquipment(objEquipment);
        //        return result;
        //    }
        //    catch (Exception ex)
        //    {
        //        // Log Exception
        //        ExceptionHelper.logException(ex);
        //        result.IsSuccessful = false;
        //        result.ErrorMessage = ex.Message;
        //        return result;
        //    }
        //}
        public SigmaResultType MultiEquipment(List<TypeEquipment> listObj)
        {
            SigmaResultType result = new SigmaResultType();

            try
            {
                EquipmentMgr equipmentMgr = new EquipmentMgr();
                result = equipmentMgr.MultiEquipment(listObj);
                return result;
            }
            catch (Exception ex)
            {
                // Log Exception
                ExceptionHelper.logException(ex);
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return result;
            }
        }
コード例 #6
0
        public SigmaResultType ListEquipment()
        {
            SigmaResultType result = new SigmaResultType();
            try
            {
                var queryStr = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters;

                //Dictionary<string, string> dictionary = new Dictionary<string, string>();
                //dictionary.Add("EquipmentCodeMain", queryStr["EquipmentCodeMain"]);
                //dictionary.Add("EquipmentCodeSub", queryStr["EquipmentCodeSub"]);
                //dictionary.Add("ThirdLevel", queryStr["ThirdLevel"]);

                //string max = queryStr["max"];
                //string offset = queryStr["offset"];
                //string o_option = queryStr["o_option"];
                //string o_desc = queryStr["o_desc"];

                EquipmentMgr equipmentMgr = new EquipmentMgr();
                result = equipmentMgr.ListEquipment(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters);

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