Пример #1
0
 public List <NTS.WEB.Model.Itemcode> GetItemCodeList(string whereStr, string sortStr)
 {
     return(itemcodeBll.GetItemcodeList(whereStr, sortStr));
 }
Пример #2
0
        /// <summary>
        /// 导出所有能源信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string ExportItemEnergy(string starttime, string endtime, string objectid, string timeunit, string counttype, string SavePath)
        {
            try
            {
                Itemcode itemcodeBll = new Itemcode();

                ReportQueryModelNew model = new ReportQueryModelNew();
                model.startime   = DateTime.Parse(starttime);
                model.endtime    = DateTime.Parse(endtime);
                model.objectid   = objectid;
                model.timeunit   = (ReportStyleNew)(int.Parse(timeunit));
                model.objecttype = 0;
                model.itemcode   = counttype;

                string strPath    = SavePath; // AppDomain.CurrentDomain.BaseDirectory + "temp_file\\";
                string strTemPath = AppDomain.CurrentDomain.BaseDirectory + "ExcelTemplate\\项目能耗查询.xls";

                IList <Model.Itemcode> itemcode = itemcodeBll.GetItemcodeList(
                    " and itemcodenumber = '" + counttype + "'", "");
                string strUnit = "mch";
                if (itemcode.Count > 0)
                {
                    strUnit = itemcode[0].Unit;
                }

                #region 第2种方法
                DataTable dtlist = GetItemcodeData(model);

                string name = GetBaseLayerObjectName(model.objectid);


                #endregion

                if (dtlist != null)
                {
                    string temp_path = strPath; //AppDomain.CurrentDomain.BaseDirectory + "temp_file\\";
                    if (!Directory.Exists(temp_path))
                    {
                        Directory.CreateDirectory(temp_path);
                        string[] files = Directory.GetFiles(temp_path);
                        foreach (string fn in files)
                        {
                            File.Delete(temp_path + fn);
                        }
                    }
                    string save_path = DateTime.Now.Ticks + ".xls";

                    string templatePath = strTemPath; // AppDomain.CurrentDomain.BaseDirectory + "template\\区域能耗查询.xls";

                    string        datetime = model.startime.ToString("yyyy-MM-dd") + "~" + (model.timeunit == ReportStyleNew.DayStyle ? model.endtime.ToString("yyyy-MM-dd HH:59:59") : model.endtime.ToString("yyyy-MM-dd"));
                    TemplateParam param    = new TemplateParam(name, new CellParam(0, 0), datetime, new CellParam(3, 0), false, new CellParam(4, 0));
                    //param.DataColumn = new[] { 0, 3, 6, 7, 8, 9};
                    param.DataColumn = new[] { 0, 1, 3, 6, 7 };

                    param.ItemUnit     = "能耗值:(" + strUnit + ")";
                    param.ItemUnitCell = new CellParam(4, 4);
                    dtlist.TableName   = "能耗查询统计";

                    string strDownFile = temp_path + save_path;

                    //return "{\"status\":\"success\",\"msg\":\"" + "/temp_file/" + save_path + "\"}";
                    ExportHelper.ExportExcel(dtlist, strDownFile, strTemPath, param);

                    //return "{\"status\":\"success\",\"msg\":\"" + "/temp_file/" + save_path + "\"}";

                    return("{\"status\":\"success\",\"msg\":\"" + "/temp_file/" + save_path + "\"}");
                }
                else
                {
                    return("{\"status\":\"error\",\"msg\":\"导出失败:当前无任何数据\"}");
                }
            }
            catch (Exception ex)
            {
                return("{\"status\":\"error\",\"msg\":\"导出失败:没有数据!\"}");
            }
        }
Пример #3
0
        public ResultDevice GetDeviceList(QueryDevice2 query)
        {
            var pAction = new ExecuteProcess();
            try
            {
                StringBuilder sbTree = new StringBuilder();

                List<Device> deviceList;
                if (query.ItemCode == "00000")
                {
                    if (query.ObjType == AreaType.Area)
                    {
                        deviceList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(" and areaid=" + query.ObjectId, " order by deviceid");
                    }
                    else
                    {
                        deviceList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(" and areaid2=" + query.ObjectId, " order by deviceid");

                    }
                }
                else
                {
                    string itemCodeAll = query.ItemCode;
                    Itemcode objItem = new Itemcode();
                    var itemcodeList = objItem.GetItemcodeList("  and ItemCodeNumber='" + query.ItemCode + "'", " order by itemcodeid")[0];
                    var itemcodeListChild = objItem.GetItemcodeList("  and ParentID=" + itemcodeList.ItemcodeID, " order by itemcodeid");
                    itemCodeAll = itemcodeListChild.Aggregate("'" + itemCodeAll + "'", (current, itemcode) => current + ("," + "'" + itemcode.ItemCodeNumber + "'"));
                    if (query.ObjType == AreaType.Area)
                    {
                        deviceList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(" and ItemCodeID in (" + itemCodeAll + ") and areaid=" + query.ObjectId, " order by deviceid");
                    }
                    else
                    {
                        deviceList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(" and ItemCodeID in (" + itemCodeAll + ") and areaid2=" + query.ObjectId, " order by deviceid");

                    }
                }
                //sbTree.Append("[");
                //for (var device = 0; device < deviceList.Count; device++)
                //{
                //    sbTree.Append("{\"text\": \"" + deviceList[device].DeviceName + "\",\"id\": " + deviceList[device].DeviceID + ",\"classes\": \"equip\"}");
                //    sbTree.Append(device == deviceList.Count - 1 ? "" : ",");
                //}
                //sbTree.Append("]");

                List<DeviceUnit> lstDvc = new List<DeviceUnit>();

                foreach (var device in deviceList)
                {
                    DeviceUnit du = new DeviceUnit();
                    du.DeviceID = device.DeviceID;
                    du.DeviceName = device.DeviceName;
                    lstDvc.Add(du);
                }

                ResultDevice result = new ResultDevice();
                result.DeviceUnitList = lstDvc;
                pAction.Success = true;
                result.ActionInfo = pAction;
                return result;
            }
            catch (Exception ex)
            {
                pAction.Success = false;
                pAction.ExceptionMsg = ex.Message;
                return new ResultDevice() { ActionInfo = pAction };
            }
        }