123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using Extensometer.Data;
- using Extensometer.Model;
- using Extensometer.Model.ResultModel;
- namespace Extensometer.BLL
- {
- public class ObjDataOperationClass
- {
- private static ObjDataOperationClass ObjDataOperation = new ObjDataOperationClass();
- private ObjDataOperationClass()
- { }
- public static ObjDataOperationClass GetObjDataOperationClass()
- {
- return ObjDataOperation;
- }
- private string ObjDbPath = string.Empty;
- /// <summary>
- /// 创建
- /// </summary>
- /// <param name="DbPath"></param>
- public void CreatObjDbFile(string DbPath)
- {
- using (var Db = new ObjectDBTable(DbPath))
- {
- ObjDbPath = DbPath;
- }
- }
- /// <summary>
- /// 加载
- /// </summary>
- /// <param name="DbPath"></param>
- public void LoadObjDbFile(string DbPath)
- {
- ObjDbPath = DbPath;
- LoadDll();
- }
- public void LoadDll()
- {
- Thread thread = new Thread(()=> {
- using (var Db = new ObjectDBTable(ObjDbPath))
- {
- }
- });
- thread.Start();
- }
- /// <summary>
- /// 全查询
- /// </summary>
- public List<ObjectData> CheckObjDb()
- {
- List<ObjectData> result = new List<ObjectData>();
- using (var Db = new ObjectDBTable(ObjDbPath))
- {
- result = Db.ObjectDatas.OrderBy(e => e.GaugeLeng).ToList();
- }
- return result;
- }
- /// <summary>
- /// 添加一条数据
- /// </summary>
- /// <param name="objectData"></param>
- /// <returns></returns>
- public ResultModel InsertObjDb(ObjectData objectData)
- {
- ResultModel result = new ResultModel();
- using (var Db = new ObjectDBTable(ObjDbPath))
- {
- if(Db.Insert(objectData)>0)
- {
- result.ErrCode = ErrCodeList.Success;
- result.ErrMessage = "添加成功";
- }
- }
- return result;
- }
- /// <summary>
- /// List<ObjectData>转成Exl表格
- /// </summary>
- /// <param name="list"></param>
- /// <param name="FilePath"></param>
- /// <returns></returns>
- //public ResultModel DataExport(List<ObjectData> list,string FilePath)
- //{
- // ResultModel resultModel = new ResultModel();
- // if (list.Count > 0)
- // {
- // object misValue = Missing.Value;
- // Application xlApp = new Application();
- // Workbook xlWorkBook = xlApp.Workbooks.Add(misValue);
- // Worksheet xlWorkSheet = (Worksheet)xlWorkBook.Worksheets.get_Item(1);
- // PropertyInfo[] props = GetPropertyInfoArray();
- // for (int i = 0; i < props.Length; i++)
- // {
- // xlWorkSheet.Cells[1, i + 1] = props[i].Name; //write the column name
- // }
- // for (int i = 0; i < list.Count; i++)
- // {
- // xlWorkSheet.Cells[i + 2, 1] = list[i].GaugeLeng.ToString();
- // xlWorkSheet.Cells[i + 2, 2] = list[i].Time.ToString();
- // xlWorkSheet.Cells[i + 2, 3] = list[i].Point1x.ToString();
- // xlWorkSheet.Cells[i + 2, 4] = list[i].Point1y.ToString();
- // xlWorkSheet.Cells[i + 2, 5] = list[i].Point2x.ToString();
- // xlWorkSheet.Cells[i + 2, 6] = list[i].Point2y.ToString();
- // xlWorkSheet.Cells[i + 2, 7] = list[i].StrainValue.ToString();
- // xlWorkSheet.Cells[i + 2, 8] = list[i].Distance.ToString();
- // xlWorkSheet.Cells[i + 2, 9] = list[i].Displacement.ToString();
- // xlWorkSheet.Cells[i + 2, 10] = list[i].ForceValue.ToString();
- // }
- // try
- // {
- // xlWorkBook.SaveAs(FilePath, XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
- // xlWorkBook.Close(true, misValue, misValue);
- // xlApp.Quit();
- // }
- // catch
- // { }
- // }
- // return resultModel;
- //}
- /// <summary>
- /// 查询数据库路径是否为空
- /// </summary>
- /// <returns></returns>
- public ResultModel CheckDataPathIsEmpty()
- {
- ResultModel resultModel = new ResultModel();
- try
- {
- if(string.IsNullOrEmpty(ObjDbPath))
- {
- resultModel.ErrCode = ErrCodeList.PathEmpty;
- resultModel.ErrMessage = "数据路径为空";
- }
- else
- {
- resultModel.ErrCode = ErrCodeList.Success;
- resultModel.ErrMessage = "";
- }
- }
- catch
- {
- resultModel.ErrCode = ErrCodeList.OtherErr;
- resultModel.ErrMessage = "未知错误";
- }
- return resultModel;
- }
- /// <summary>
- /// 反射获取类型的所有属性
- /// </summary>
- /// <returns></returns>
- private PropertyInfo[] GetPropertyInfoArray()
- {
- PropertyInfo[] props = null;
- try
- {
- Type type = typeof(ObjectData);
- object obj = Activator.CreateInstance(type);
- props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
- }
- catch
- { }
- return props;
- }
- }
- }
|