public static void Save_ChargeMeter_Project_Point(ChargeMeter_Project data, SqlHelper helper) { var data_detail = ChargeMeter_ProjectDetail.GetChargeMeter_ProjectDetailByID(data.ID, helper); var point = new ChargeMeter_Project_Point(); point.MeterFullName = data_detail.FinalName; point.ChargeMeter_ProjectID = data.ID; point.ProjectID = data.ProjectID; point.MeterID = data.MeterID; point.MeterName = data.MeterName; point.MeterNumber = data.MeterNumber; point.MeterCategoryID = data.MeterCategoryID; point.MeterType = data.MeterType; point.MeterSpec = data.MeterSpec; point.MeterCoefficient = data.MeterCoefficient; point.MeterRemark = data.MeterRemark; point.MeterChargeID = data.MeterChargeID; point.MeterHouseNo = data.MeterHouseNo; point.MeterLocation = data.MeterLocation; point.SortOrder = data.SortOrder; point.MeterStartPoint = data.MeterStartPoint; point.MeterEndPoint = data.MeterEndPoint; point.MeterTotalPoint = data.MeterTotalPoint; point.AddTime = data.AddTime; point.AddUserName = data.AddUserName; point.WriteStatus = data.WriteStatus; point.FeeStatus = data.FeeStatus; point.WriteDate = data.WriteDate; point.WriteUserName = data.WriteUserName; point.IsAPPWriteEnable = data.IsAPPWriteEnable; point.UpdateTime = DateTime.Now; point.UpdateUserName = User.GetCurrentUserName(); point.Save(helper); }
public static void GetChargeMeter_ProjectDetailRoomIDList(int RoomID, out int PreRoomID, out int NextRoomID, out int CurrentRoomID, string keywords = "", List <int> ALLProjectIDList = null, int UserID = 0, int ProjectID = 0) { PreRoomID = 0; NextRoomID = 0; CurrentRoomID = 0; var parameters = new List <SqlParameter>(); var conditions = new List <string>(); conditions.Add("[IsAPPWriteEnable]=1"); conditions.Add("[MeterType]=1"); var list = new ChargeMeter_Project[] { }; if (ALLProjectIDList != null && ALLProjectIDList.Count > 0) { List <string> cmdlist = ViewRoomFeeHistory.GetProjectIDListConditions(ALLProjectIDList, IncludeRelation: false, RoomIDName: "[ProjectID]", UserID: UserID); conditions.Add("(" + string.Join(" or ", cmdlist.ToArray()) + ")"); } if (!string.IsNullOrEmpty(keywords)) { conditions.Add("([Project].[Name] like @keywords or [Project].[FullName] like @keywords)"); parameters.Add(new SqlParameter("@keywords", "%" + keywords + "%")); } if (ProjectID > 0) { conditions.Add("([Project].[ID]=@ProjectID or [Project].[AllParentID] like @AllParentID)"); parameters.Add(new SqlParameter("@ProjectID", ProjectID)); parameters.Add(new SqlParameter("@AllParentID", "%," + ProjectID + ",%")); } list = GetList <ChargeMeter_Project>("select [ChargeMeter_Project].[ProjectID] from [ChargeMeter_Project] left join [Project] on [Project].ID=[ChargeMeter_Project].ProjectID where " + string.Join(" and ", conditions.ToArray()) + " order by [Project].DefaultOrder asc", parameters).ToArray(); if (list.Length == 0) { return; } var ProjectIDList = list.Select(p => p.ProjectID).Distinct().ToArray(); if (RoomID > 0) { for (int i = 0; i < ProjectIDList.Length; i++) { if (RoomID == ProjectIDList[i]) { CurrentRoomID = RoomID; if (i > 0) { PreRoomID = ProjectIDList[i - 1]; } if (i < ProjectIDList.Length - 1) { NextRoomID = ProjectIDList[i + 1]; } } } return; } CurrentRoomID = ProjectIDList[0]; if (ProjectIDList.Length > 1) { NextRoomID = ProjectIDList[1]; } }
public static void Save_ChargeMeter_Project(ChargeMeter_Project data, ChargeMeter meter, SqlHelper helper) { data.MeterName = meter.MeterName; data.MeterNumber = meter.MeterNumber; data.MeterCategoryID = meter.MeterCategoryID; data.MeterType = meter.MeterType; data.MeterSpec = meter.MeterSpec; data.MeterCoefficient = meter.MeterCoefficient; data.MeterRemark = meter.MeterRemark; data.MeterChargeID = meter.MeterChargeID; data.MeterHouseNo = meter.MeterHouseNo; data.MeterLocation = meter.MeterLocation; data.SortOrder = meter.SortOrder; data.WriteStatus = 0; data.FeeStatus = 0; data.Save(helper); }
private void importmeterpointdata(HttpContext context) { HttpFileCollection uploadFiles = context.Request.Files; if (uploadFiles.Count == 0) { context.Response.Write("请选择一个文件"); return; } if (string.IsNullOrEmpty(uploadFiles[0].FileName)) { context.Response.Write("请选择一个文件"); return; } string msg = string.Empty; bool ImportFailed = false; int TotalNumber = 0; using (SqlHelper helper = new SqlHelper()) { try { helper.BeginTransaction(); #region 导入处理 for (int j = 0; j < uploadFiles.Count; j++) { HttpPostedFile postedFile = uploadFiles[j]; string filepath = HttpContext.Current.Server.MapPath("~/upload/ImportChaoBiao/" + DateTime.Now.ToString("yyyyMMdd")); if (!System.IO.Directory.Exists(filepath)) { System.IO.Directory.CreateDirectory(filepath); } string filename = DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmss") + "_" + postedFile.FileName; string fullpath = Path.Combine(filepath, filename); postedFile.SaveAs(fullpath); DataTable table = ExcelExportHelper.NPOIReadExcel(fullpath); for (int i = 0; i < table.Rows.Count; i++) { int ID = 0; int.TryParse(table.Rows[i]["仪表ID"].ToString(), out ID); Foresight.DataAccess.ChargeMeter_Project projectbiao = null; if (ID > 0) { projectbiao = Foresight.DataAccess.ChargeMeter_Project.GetChargeMeter_Project(ID, helper); } if (projectbiao == null) { msg += "<p>第" + (i + 2) + "行上传失败。原因:仪表不存在</p>"; ImportFailed = true; break; } projectbiao.MeterName = table.Rows[i]["仪表名称"].ToString(); projectbiao.MeterNumber = table.Rows[i]["仪表编号"].ToString(); projectbiao.MeterCategoryID = ChargeMeter_Project.GetMeterCategoryID(table.Rows[i]["仪表种类"].ToString()); if (projectbiao.MeterCategoryID == 0) { msg += "<p>第" + (i + 2) + "行上传失败。原因:仪表种类不存在</p>"; ImportFailed = true; break; } projectbiao.MeterType = ChargeMeter_Project.GetMeterTypeID(table.Rows[i]["仪表类型"].ToString()); if (projectbiao.MeterType == 0) { msg += "<p>第" + (i + 2) + "行上传失败。原因:仪表类型不存在</p>"; ImportFailed = true; break; } projectbiao.MeterSpec = ChargeMeter_Project.GetMeterSpec(table.Rows[i]["仪表规格"].ToString()); if (projectbiao.MeterSpec == 0) { msg += "<p>第" + (i + 2) + "行上传失败。原因:仪表规格不存在</p>"; ImportFailed = true; break; } projectbiao.MeterCoefficient = WebUtil.GetDecimalByStr(table.Rows[i]["倍率"].ToString()); projectbiao.MeterHouseNo = table.Rows[i]["缴费户号"].ToString(); projectbiao.MeterLocation = table.Rows[i]["仪表位置"].ToString(); projectbiao.MeterRemark = table.Rows[i]["备注"].ToString(); projectbiao.SortOrder = WebUtil.GetIntByStr(table.Rows[i]["排序序号"].ToString()); projectbiao.MeterStartPoint = WebUtil.GetDecimalByStr(table.Rows[i]["上次读数"].ToString()); projectbiao.MeterEndPoint = WebUtil.GetDecimalByStr(table.Rows[i]["本次读数"].ToString()); projectbiao.Save(helper); TotalNumber = i; } } #endregion if (!ImportFailed) { helper.Commit(); msg += "<p>导入完成</p>"; } else { helper.Rollback(); msg += "<p>导入失败</p>"; } } catch (Exception ex) { LogHelper.WriteError("ImportGongTanHandler", "visit: importmeterdata", ex); helper.Rollback(); msg += "<p>第" + (TotalNumber + 2) + "行上传失败。原因:" + ex.Message + "</p>"; } context.Response.Write(msg); } }