public SigmaResultType AddDrawing(TypeDrawing objDrawingid)
 {
     SigmaResultType result = new SigmaResultType();
     try
     {
         DrawingMgr drawingMgr = new DrawingMgr();
         result = drawingMgr.AddDrawing(objDrawingid);
         return result;
     }
     catch (Exception ex)
     {
         // Log Exception
         ExceptionHelper.logException(ex);
         result.IsSuccessful = false;
         result.ErrorMessage = ex.Message;
         return result;
     }
 }
Exemple #2
0
        public SigmaResultType UpdateDrawing(TypeDrawing objDrawingId)
        {
            TransactionScope scope = null;
            SigmaResultType result = new SigmaResultType();
            SigmaResultType refresult = new SigmaResultType();

            // Get connection string
            string connStr = ConnStrHelper.getDbConnString();
            string UpdatedBy = "leebw";

            // * Ref Drawing Check
            if (!string.IsNullOrEmpty(objDrawingId.ReferenceDrawings))
            {
                string xlsRefDrawingno = objDrawingId.ReferenceDrawings;
                string[] arrRefDrawingno = xlsRefDrawingno.Split(',');

                foreach (string refdrawno in arrRefDrawingno)
                {
                    refresult = GetDrawingByNumber(refdrawno.Trim());

                    if (refresult.AffectedRow < 1)
                    {
                        result.IsSuccessful = false;
                        result.ErrorMessage = "Incorrect Reference Drawing";
                        return result;
                    }
                }
            }

            // * Detail Drawing Check
            if (!string.IsNullOrEmpty(objDrawingId.DetailedDrawings))
            {
                string xlsDetailDrawingno = objDrawingId.DetailedDrawings;
                string[] arrDetailDrawingno = xlsDetailDrawingno.Split(',');

                foreach (string detaildrawno in arrDetailDrawingno)
                {
                    refresult = GetDrawingByNumber(detaildrawno.Trim());

                    if (refresult.AffectedRow < 1)
                    {
                        result.IsSuccessful = false;
                        result.ErrorMessage = "Incorrect Detail Drawing";
                        return result;
                    }
                }
            }

            // * Path 넘어오면 이미지 추가 - Image Add
            if (!string.IsNullOrEmpty(objDrawingId.FilePath))
            {
                SigmaResultType imageresult = new SigmaResultType();
                ImportDrawingMgr importDrawingImage = new ImportDrawingMgr();

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

                string rootPath = ConfigMgr.GetImportFilePath();
                string targetPath = ConfigMgr.GetTargetPath();

                string filePath = rootPath + objDrawingId.FilePath;

                imageresult = importDrawingImage.AddDrawingImage(filePath, targetPath);
            }
            //--------------------------------------------------------------------------------------------------------

            SqlParameter[] drawingParm = new SqlParameter[] {
                                new SqlParameter("@DrawingId", objDrawingId.DrawingId),
                                new SqlParameter("@CwpName", objDrawingId.CWP),
                                new SqlParameter("@Name", objDrawingId.Name),
                                new SqlParameter("@FileName", objDrawingId.FileName),
                                new SqlParameter("@Title", objDrawingId.Title),
                                new SqlParameter("@Description", objDrawingId.Description),
                                new SqlParameter("@Revision", objDrawingId.Revision),
                                new SqlParameter("@DrawingType", objDrawingId.DrawingType),
                                new SqlParameter("@UpdatedBy", UpdatedBy),
                                new SqlParameter("@ResultMsg", SqlDbType.VarChar, 100), // sp에서 output 설정했을 경우
                                new SqlParameter("RETURN_VALUE",SqlDbType.Int) // sp에서 return 값을 설정했을경우 사용
                    };

            drawingParm[9].Direction = ParameterDirection.Output;
            drawingParm[10].Direction = ParameterDirection.ReturnValue;

            using (scope = new TransactionScope(TransactionScopeOption.Required))
            {
                result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_UpdateDrawing", drawingParm);

                string resultMsg = (string)drawingParm[9].Value;
                int AffectedRow = (int)drawingParm[10].Value;

                if (AffectedRow > 0)
                {

                    // Ref. Drawing 있다면 등록
                    if (!string.IsNullOrEmpty(objDrawingId.ReferenceDrawings))
                    {
                        string xlsRefDrawingno = objDrawingId.ReferenceDrawings;
                        string[] arrRefDrawingno = xlsRefDrawingno.Split(',');

                        foreach (string refdrawno in arrRefDrawingno)
                        {
                            SqlParameter[] refdrawingParm = new SqlParameter[] {
                                new SqlParameter("@RefDrawingNo", refdrawno.Trim()),
                                new SqlParameter("@DrawingNo", objDrawingId.Name),
                                new SqlParameter("@DetailDrawingNo", ""),
                                new SqlParameter("@Revision", ""),
                                new SqlParameter("@CreatedBy", UpdatedBy),
                                new SqlParameter("RETURN_VALUE",SqlDbType.Int) // sp에서 return 값을 설정했을경우 사용
                            };

                            refdrawingParm[5].Direction = ParameterDirection.ReturnValue;

                            //using (scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                            //{
                            result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_AddReferenceDrawing", refdrawingParm);
                                //int AffectedRow = (int)drawingParm[5].Value;
                            AffectedRow = (int)refdrawingParm[5].Value;

                            //    scope.Complete();
                            //}
                        }
                    }

                    // Detail Drawing 있다면 등록
                    if (!string.IsNullOrEmpty(objDrawingId.DetailedDrawings))
                    {
                        string xlsDetailDrawingno = objDrawingId.DetailedDrawings;
                        string[] arrDetailDrawingno = xlsDetailDrawingno.Split(',');

                        foreach (string detaildrawno in arrDetailDrawingno)
                        {
                            SqlParameter[] detaildrawingParm = new SqlParameter[] {
                                new SqlParameter("@DetailDrawingNo", detaildrawno.Trim()),
                                new SqlParameter("@DrawingNo", objDrawingId.Name),
                                new SqlParameter("@Revision", ""),
                                new SqlParameter("@CreatedBy", UpdatedBy),
                                new SqlParameter("RETURN_VALUE",SqlDbType.Int) // sp에서 return 값을 설정했을경우 사용
                            };

                            detaildrawingParm[4].Direction = ParameterDirection.ReturnValue;

                            //using (scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                            //{
                            result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_AddDetailDrawing", detaildrawingParm);
                            AffectedRow = (int)detaildrawingParm[4].Value;

                            //    scope.Complete();
                            //}
                        }
                    }

                    // Image 를 Upload 했다면 바로 Binding 처리 되도록 한다.
                    if (!string.IsNullOrEmpty(objDrawingId.FilePath))
                    {
                        SqlParameter[] drawingBindingParm = new SqlParameter[] {
                                new SqlParameter("@DrawingId", objDrawingId.DrawingId),
                                new SqlParameter("@UpdatedBy", objDrawingId.UpdatedBy),
                                new SqlParameter("@ResultMsg", SqlDbType.VarChar, 100), // sp에서 output 설정했을 경우
                                new SqlParameter("RETURN_VALUE",SqlDbType.Int) // sp에서 return 값을 설정했을경우 사용
                        };

                        drawingBindingParm[2].Direction = ParameterDirection.Output;
                        drawingBindingParm[3].Direction = ParameterDirection.ReturnValue;

                        //DrawingID 번호 Return 받음
                        result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_UpdateBindingDrawingById", drawingBindingParm);

                        //result.IsSuccessful = true;
                        //result.ScalarValue = AffectedRow;
                    }

                    result.IsSuccessful = true;
                    result.ScalarValue = AffectedRow;
                }
                else
                {
                    result.IsSuccessful = false;
                    result.ErrorMessage = resultMsg;
                }
                scope.Complete();
            }

            return result;
        }
Exemple #3
0
        public SigmaResultType RemoveDrawing(TypeDrawing objDrawingId)
        {
            SigmaResultType result = new SigmaResultType();
            TransactionScope scope = null;

            // Get connection string
            string connStr = ConnStrHelper.getDbConnString();

            // Compose parameters
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@DrawingId", objDrawingId.DrawingId) };
            using (scope = new TransactionScope(TransactionScopeOption.Required))
            {
                result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, "usp_RemoveDrawing", parameters);
                result.IsSuccessful = true;
                scope.Complete();
            }

            return result;
        }
Exemple #4
0
        public SigmaResultType DrawingBinding(TypeDrawing objDrawingId)
        {
            SigmaResultType result = new SigmaResultType();
            TransactionScope scope = null;
            TypeUserInfo userinfo = AuthMgr.GetUserInfo();
            // Get connection string
            string connStr = ConnStrHelper.getDbConnString();

            // Compose parameters
            SqlParameter[] bindingParm = new SqlParameter[] {
                                new SqlParameter("@ProjectId", userinfo.CurrentProjectId),
                                new SqlParameter("@UpdatedBy", userinfo.SigmaUserId),
                                new SqlParameter("@ResultMsg", SqlDbType.VarChar, 100), // sp에서 output 설정했을 경우
                                new SqlParameter("RETURN_VALUE",SqlDbType.Int) // sp에서 return 값을 설정했을경우 사용
                    };

            bindingParm[2].Direction = ParameterDirection.Output;
            bindingParm[3].Direction = ParameterDirection.ReturnValue;

            using (scope = new TransactionScope(TransactionScopeOption.Required))
            {
                result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_UpdateBindingDrawing", bindingParm);

                string resultMsg = (string)bindingParm[2].Value;
                //Update 결과 건수
                int AffectedRow = (int)bindingParm[3].Value;

                result.IsSuccessful = true;
                result.ScalarValue = AffectedRow;
                result.StringValue = resultMsg;

                scope.Complete();
            }

            return result;
        }
        public SigmaResultType AddDrawing(string fileUrl, string exportfilepath)
        {
            TypeUserInfo userinfo = AuthMgr.GetUserInfo();

            DataTable dt = new DataTable();
            DataTable tmpDt = new DataTable();
            SigmaResultType result = new SigmaResultType();

            dt = Element.Shared.Common.ImportHelper.ImportWorkSheet(fileUrl, true);

            DataTable tmpdt = new DataTable();
            tmpdt = dt.Copy();
            tmpdt.Rows.Clear();
            tmpdt.Columns.Add("Fail reason");

            int failCnt = 0;

            foreach (DataRow r in dt.Rows)
            {
                TypeDrawing obj = new TypeDrawing();
                obj.CWP = r[0].ToString();
                obj.Name = r[1].ToString();
                obj.Revision = r[2].ToString();
                obj.FileName = r[3].ToString();
                obj.Title = r[4].ToString();
                obj.DrawingType = r[5].ToString();
                obj.Description = r[6].ToString();

                if (string.IsNullOrEmpty(GetFailreasonForRequired(r)))
                {
                    SigmaResultType rst = AddDrawing(obj);

                    if (!string.IsNullOrEmpty(rst.ErrorMessage) && rst.ErrorMessage != "Success")
                    {
                        tmpdt.Rows.Add(r.ItemArray);
                        tmpdt.Rows[tmpdt.Rows.Count - 1]["Fail reason"] = rst.ErrorMessage.ToString();
                        failCnt++;
                    }
                }
                else
                {
                    tmpdt.Rows.Add(r.ItemArray);
                    tmpdt.Rows[tmpdt.Rows.Count - 1]["Fail reason"] = GetFailreasonForRequired(r);
                    failCnt++;
                }
            }

            TypeImportHistory ImportHistory = new TypeImportHistory();
            ImportHistory.ImportCategory = "DRAWING";
            ImportHistory.ImportedFileName = Path.GetFileName(fileUrl).ToString();
            ImportHistory.ImportedDate = DateTime.Now.ToString();
            ImportHistory.TotalCount = dt.Rows.Count;
            ImportHistory.SuccessCount = dt.Rows.Count - failCnt;
            ImportHistory.FailCount = failCnt;
            ImportHistory.CreatedBy = userinfo.SigmaUserId;
            ImportHistoryMgr HistoryMgr = new ImportHistoryMgr();
            result = HistoryMgr.AddImportHistory(ImportHistory);

            //if exists error list
            if (tmpdt.Rows.Count > 0)
            {
                if (!System.IO.Directory.Exists(exportfilepath))
                {
                    System.IO.Directory.CreateDirectory(exportfilepath);
                }

                //excel file generate for direct call 'export' link
                Export2Excel.ConvertExcelfromData(tmpdt, result.ScalarValue + Path.GetExtension(fileUrl), exportfilepath);

                //csv file generate for import error list view
                Export2Excel.ConvertCSVFile(tmpdt, result.ScalarValue + ".csv", exportfilepath);

            }

            return result;
        }
        public SigmaResultType AddDrawing(TypeDrawing objDrawing)
        {
            TypeUserInfo userinfo = AuthMgr.GetUserInfo();

            TransactionScope scope = null;
            SigmaResultType result = new SigmaResultType();

            // Get connection string
            string connStr = ConnStrHelper.getDbConnString();

            List<SqlParameter> paramList = new List<SqlParameter>();
            paramList.Add(new SqlParameter("@ImportedSourceFileInfoID", 0));
            paramList.Add(new SqlParameter("@CwpName", objDrawing.CWP));
            paramList.Add(new SqlParameter("@Name", objDrawing.Name));
            paramList.Add(new SqlParameter("@FileName", objDrawing.FileName));
            paramList.Add(new SqlParameter("@Title", objDrawing.Title));
            paramList.Add(new SqlParameter("@Description", objDrawing.Description));
            paramList.Add(new SqlParameter("@Revision", objDrawing.Revision));
            paramList.Add(new SqlParameter("@DrawingType", objDrawing.DrawingType));
            paramList.Add(new SqlParameter("@CreatedBy", userinfo.SigmaUserId));
            paramList.Add(new SqlParameter("@ProjectId", userinfo.CurrentProjectId));
            paramList.Add(new SqlParameter("@ResultMsg", SqlDbType.VarChar, 100));
            paramList.Add(new SqlParameter("@DrawingId", SqlDbType.Int));
            paramList[10].Direction = ParameterDirection.Output;
            paramList[11].Direction = ParameterDirection.Output;

            using (scope = new TransactionScope(TransactionScopeOption.Required))
            {
                result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_AddDrawing", paramList.ToArray());
                result.ErrorMessage = paramList[10].Value.ToString();
                result.IsSuccessful = true;

                scope.Complete();
            }

            return result;
        }