Ejemplo n.º 1
0
        private void HandToggleUI()
        {
            EditorGUILayout.Space();

            Tools_Public.EnumButton <ExcelType>(ref m_type, position.width);

            Tools_Public.CenterLabel("---->" + m_type.ToString() + "<----");

            EditorGUILayout.Space();
        }
Ejemplo n.º 2
0
 public static bool InSql(int orderId, int processNum, string workPieceNum, ExcelType type, List <QualityDataInfo> infos, ref string errMsg)
 {
     try
     {
         using (JDJS_WMS_DB_USEREntities model = new JDJS_WMS_DB_USEREntities())
         {
             using (System.Data.Entity.DbContextTransaction mytran = model.Database.BeginTransaction())
             {
                 try
                 {
                     foreach (var info in infos)
                     {
                         JDJS_WMS_Quality_Detection_Measurement_Table jd = new JDJS_WMS_Quality_Detection_Measurement_Table()
                         {
                             OrderID           = orderId,
                             Measurements      = info.Measurements,
                             ToleranceRangeMax = info.ToleranceRangeMax,
                             ToleranceRangeMin = info.ToleranceRangeMin,
                             Type            = type.ToString(),
                             ProcessNum      = processNum,
                             SizeName        = info.SizeName,
                             StandardValue   = info.StandardValue,
                             WorkpieceNumber = workPieceNum,
                             OutOfTolerance  = info.OutOfTolerance
                         };
                         model.JDJS_WMS_Quality_Detection_Measurement_Table.Add(jd);
                     }
                     model.SaveChanges();
                     mytran.Commit();
                     errMsg = "ok";
                     return(true);
                 }
                 catch (Exception ex)
                 {
                     mytran.Rollback();
                     errMsg = ex.Message;
                     return(false);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         errMsg = ex.Message;
         return(false);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 以流的形式下载
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="type"></param>
 private static void DownloadExcel(MemoryStream stream, ExcelType type)
 {
     HttpContext.Current.Response.ClearContent();
     HttpContext.Current.Response.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}.{1}", DateTime.Now.ToString("yyyyMMdd"), type.ToString())); //导出xlsx,要引用5个dll
     //Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMdd") + ".xls");//注意导出的文件格式
     HttpContext.Current.Response.ContentType     = "application/excel";
     HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
     HttpContext.Current.Response.BinaryWrite(stream.ToArray());
     stream.Dispose();
     HttpContext.Current.Response.End();
 }
Ejemplo n.º 4
0
        private void ShowOpenExcel()
        {
            GUIStyle headStyle = GUIHelper.MakeHeader();

            GUILayout.Label("Select File", headStyle);
            EditorGUILayout.Space();

            GUILayout.BeginHorizontal();
            GUILayout.Label("File:", GUILayout.Width(50));

            string path = string.Empty;

            if (string.IsNullOrEmpty(excelFilePath))
            {
                path = Application.dataPath;
            }
            else
            {
                path = excelFilePath;
            }

            excelFilePath = GUILayout.TextField(path, GUILayout.Width(250));
            if (GUILayout.Button("...", GUILayout.Width(20)))
            {
                string folder = Path.GetDirectoryName(path);
#if UNITY_EDITOR_WIN
                path = EditorUtility.OpenFilePanel("Open Excel file", folder, "excel files;*.xls;*.xlsx");
#else
                path = EditorUtility.OpenFilePanel("Open Excel file", folder, "xls");
#endif

                if (path.Length != 0)
                {
                    fileName = Path.GetFileName(path);

                    // the path should be relative not absolute one to make it work on any platform.
                    int index = path.IndexOf("Assets");
                    if (index >= 0)
                    {
                        // set relative path
                        excelFilePath = path.Substring(index);

                        //
                        excelReader = new ExcelReader(path);

                        // pass absolute path
                        sheetsNames = excelReader.GetSheetNames();
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("Error",
                                                    @"Wrong folder is selected.
                        Set a folder under the 'Assets' folder! \n
                        The excel file should be anywhere under  the 'Assets' folder", "OK");
                        return;
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Label("Spreadsheet File: " + fileName);

            EditorGUILayout.Space();

            if (excelReader == null)
            {
                return;
            }

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Worksheet: ", GUILayout.Width(100));
                currentSheetIndex = EditorGUILayout.Popup(currentSheetIndex, sheetsNames, GUILayout.Width(60));
                currentExcelType  = (ExcelType)EditorGUILayout.EnumPopup(currentExcelType, GUILayout.Width(60));
                if (sheetsNames != null)
                {
                    currentSheetName = sheetsNames[currentSheetIndex];
                }
                if (GUILayout.Button("Refresh", GUILayout.Width(60)))
                {
                    // reopen the excel file e.g) new worksheet is added so need to reopen.
                    excelReader = new ExcelReader(path, currentSheetName, currentExcelType);
                    Debug.logger.Log("Current Path: " + path + "\nCurrent Sheet: " + currentSheetName
                                     + "\nCurrent Excel Type: " + currentExcelType.ToString());
                    sheetsNames = excelReader.GetSheetNames();

                    // one of worksheet was removed, so reset the selected worksheet index
                    // to prevent the index out of range error.
                    if (sheetsNames.Length <= currentSheetIndex)
                    {
                        currentSheetIndex = 0;

                        string message = "Worksheet was changed. Check the 'Worksheet' and 'Update' it again if it is necessary.";
                        EditorUtility.DisplayDialog("Info", message, "OK");
                    }
                }
            }
        }