private void OnCreateChanage(object sender, EventArgs e) { ZoneEntity newEntity = (ZoneEntity)sender; bindingSource1.Add(newEntity); bindingSource1.ResetBindings(false); }
protected void MasterPage_YesClickHandler(object sender, EventArgs e) { if (ViewState["Delete"] != null) { try { ZoneEntity entity = new ZoneEntity(); entity.OperationId = (int)OperationType.Delete; entity.ZoneId = Utility.GetLong(ViewState["ZoneId"]); OperationStatusEntity c = new ConfigrationRepository(SessionContext).UpdateZone(entity); if (c.StatusResult == true) { ShowInfoMessage(c.InfoMessage); ClearPageControl(); FillGrid(); } else { ShowErrorMessage(c.InfoMessage); } } catch (BaseException bex) { ShowErrorMessage(bex.Message); } } }
public M3App(IHaContext ha) { Ha = ha; // Ha.CallService("notify", "persistent_notification", new { message = "Hello", title = "Yay it works in HassModel via HaContext" }, true);; _climateEntity = new ClimateEntity(ha, "climate.dummy_thermostat"); _climateEntity.StateAllChanges().Where(e => e.New?.Attributes?.Temperature > 20).Subscribe(); _climateEntity.StateAllChanges().Subscribe(OnNext); string? state = _climateEntity.State; string? state2 = _climateEntity.EntityState?.State; // is the same DateTime?lastChanged = _climateEntity.EntityState?.LastChanged; Ha.StateChanges().Subscribe(e => { }); // Entity that has not changed yet is retrieved on demand var zone = new ZoneEntity(Ha, "zone.home"); var lat = zone.Attributes?.latitude; var netEnergySensor = new NumericSensorEntity(Ha, "sensor.netto_energy"); // NumericSensor has double? as state double?netEnergy = netEnergySensor.State; double?netEnergy2 = netEnergySensor.EntityState?.State; netEnergySensor.StateChanges().Subscribe(e => Console.WriteLine($"{e.New?.Attributes?.FriendlyName} {e.New?.State} {e.New?.Attributes?.UnitOfMeasurement}")); // Prints: 'Netto energy 8908.81 kWh' }
public void Update(int Id, ZoneEntity T) { using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["API"].ConnectionString)) { using (SqlCommand cmd = c.CreateCommand()) { if (T.ContinentFR != null && T.ContinentEN != null && T.ZoneFR != null && T.ZoneEN != null && T.ZoneQty != 0 && Id != 0) { cmd.CommandText = "SP_UpdateZone"; cmd.CommandType = CommandType.StoredProcedure; SqlParameter ContinentEN = new SqlParameter("ContinentEN", T.ContinentEN); SqlParameter ContinentFR = new SqlParameter("ContinentFR", T.ContinentFR); SqlParameter ZoneEN = new SqlParameter("ZoneEN", T.ZoneEN); SqlParameter ZoneFR = new SqlParameter("ZoneFR", T.ZoneFR); SqlParameter ZoneQty = new SqlParameter("ZoneQty", T.ZoneQty); SqlParameter PId = new SqlParameter("Id", Id); cmd.Parameters.Add(ContinentEN); cmd.Parameters.Add(ContinentFR); cmd.Parameters.Add(ZoneEN); cmd.Parameters.Add(ZoneFR); cmd.Parameters.Add(ZoneQty); cmd.Parameters.Add(PId); c.Open(); cmd.ExecuteNonQuery(); } } } }
public ZoneEntity GetOne(int id) { using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["API"].ConnectionString)) { using (SqlCommand cmd = c.CreateCommand()) { cmd.CommandText = "SELECT * FROM Zones WHERE Id = @Id AND Active = 1"; cmd.Parameters.AddWithValue("Id", id); c.Open(); using (SqlDataReader Tab = cmd.ExecuteReader()) { if (Tab.Read()) { ZoneEntity S = new ZoneEntity() { Id = (int)Tab["Id"], ContinentEN = Tab["ContinentEN"].ToString(), ContinentFR = Tab["ContinentFR"].ToString(), ZoneEN = Tab["ZoneEN"].ToString(), ZoneFR = Tab["ZoneFR"].ToString(), ZoneQty = (int)Tab["ZoneQty"], Active = (int)Tab["Active"] }; return(S); } else { return(null); } } } } }
private string BanIpByRateLimitRule(ZoneEntity zoneEntity, bool ifTestStage, CloudFlareApiService cloudflare, int timeStage, string requestHost, string ip, int period, int threshold, int requestCount) { var sbDetail = new StringBuilder(); if (ifTestStage) { sbDetail.AppendFormat("Ban IP [{0}] successfully.<br />", ip); } else { var cloudflareAccessRuleResponse = cloudflare.BanIp(ip, "Ban Ip By Attack Prevent Windows service!"); if (cloudflareAccessRuleResponse.Success) { sbDetail.AppendFormat("Ban IP [{0}] and add ban history successfully.<br />", ip); BanIpHistoryBusiness.Add(new BanIpHistory() { IP = ip, ZoneId = zoneEntity.ZoneId, RuleId = 0, Remark = string.Format("IP [{0}] visited [{2}] [{3}] times, time range:[{1}].<br /> Exceeded rate limit threshold(Period=[{4}],Threshold=[{5}]).", ip, timeStage, requestHost, requestCount, period, threshold) }); } else { sbDetail.AppendFormat("Ban IP [{0}] failure, the reason is:[{1}].<br />", ip, cloudflareAccessRuleResponse.Errors.Length > 0 ? cloudflareAccessRuleResponse.Errors[0].message : "No error message from Cloudflare."); } } return(sbDetail.ToString()); }
///<summary> ///查询所有货区 ///</summary> ///<returns></returns> public List <ZoneEntity> GetAllZone() { List <ZoneEntity> list = new List <ZoneEntity>(); try { #region 请求数据 System.Text.StringBuilder loStr = new System.Text.StringBuilder(); //loStr.Append("vhNo=").Append(vehicleNO); string jsons = string.Empty; string jsonQuery = WebWork.SendRequest(jsons, WebWork.URL_GetAllZone); if (string.IsNullOrEmpty(jsonQuery)) { MsgBox.Warn(WebWork.RESULT_NULL); //LogHelper.InfoLog(WebWork.RESULT_NULL); return(list); } #endregion #region 正常错误处理 JsonGetAllZone bill = JsonConvert.DeserializeObject <JsonGetAllZone>(jsonQuery); if (bill == null) { MsgBox.Warn(WebWork.JSON_DATA_NULL); return(list); } if (bill.flag != 0) { MsgBox.Warn(bill.error); return(list); } #endregion #region 赋值数据 foreach (JsonGetAllZoneResult jbr in bill.result) { ZoneEntity asnEntity = new ZoneEntity(); asnEntity.IsActive = jbr.isActive; asnEntity.TemperatureCode = jbr.tempCode; asnEntity.TemperatureName = jbr.tempName; asnEntity.WarehouseCode = jbr.whCode; asnEntity.WarehouseName = jbr.whName; asnEntity.ZoneCode = jbr.znCode; asnEntity.ZoneName = jbr.znName; asnEntity.ZoneTypeCode = jbr.ztCode; asnEntity.ZoneTypeName = jbr.ztName; list.Add(asnEntity); } return(list); #endregion } catch (Exception ex) { MsgBox.Err(ex.Message); } return(list); }
/// <summary> /// 检查货区编码是否已存在 /// </summary> /// <param name="dept"></param> /// <returns></returns> private bool IsZoneCodeExists(ZoneEntity zone) { IMapper map = DatabaseInstance.Instance(); string id = map.ExecuteScalar <string>("select ZN_CODE from WM_ZONE where ZN_CODE = @COD", new { COD = zone.ZoneCode }); return(!string.IsNullOrEmpty(id)); }
private void CreateActiveReportZoneTesting(ZoneEntity zone, DateTime date) { string title = date.ToString("MM/dd/yyyy HH"); string zoneId = zone.ZoneId; var list = ActionReportBusiness.GetListByTitle(title); if (list != null && list.Count(a => a.ZoneId == zoneId) > 0) { //如果本时段的数据已经存在则不必重复生成 return; } //24个小时,取第一分钟的数据 List <List <CloudflareLog> > cloudflareLogs = new List <List <CloudflareLog> >(); for (int i = 0; i < oneDayCount; i++) { double sample = 1; DateTime startTime = Convert.ToDateTime(date.ToString(string.Format("yyyy-MM-dd HH:{0}:00", i.ToString("00")))); DateTime endTime = Convert.ToDateTime(date.ToString(string.Format("yyyy-MM-dd HH:{0}:00", (i + 1).ToString("00")))); string authEmail = zone.AuthEmail; string authKey = zone.AuthKey; string key = string.Format("{0}-{1}-{2}-{3}", startTime.ToString("yyyyMMddHHmmss"), endTime.ToString("yyyyMMddHHmmss"), sample, zoneId); List <CloudflareLog> logs = new List <CloudflareLog>(); ICloudflareLogHandleSercie cloudflareLogHandleSercie = new CloudflareLogHandleSercie(zoneId, authEmail, authKey, sample, startTime, endTime, true); cloudflareLogHandleSercie.TaskStart(); logs = cloudflareLogHandleSercie.GetCloudflareLogs(key) .Where(a => !IfInSuffixList(a.ClientRequestURI)).ToList(); if (logs == null || logs.Count == 0) { logs = new List <CloudflareLog> { new CloudflareLog { ClientRequestHost = "www.comm100.com", ClientIP = "203.177.237.253", ClientRequestURI = "/visitor.ashx?siteId=1000325&visitorGuid=LKsJf9nGBk6RX2Ogk6bW1A" }, new CloudflareLog { ClientRequestHost = "www.comm100.com", ClientIP = "203.177.237.253", ClientRequestURI = "/VISITOR.ashx?siteId=1000325&visitorGuid=LKsJf9nGBk6RX2Ogk6bW1A" }, }; } cloudflareLogs.Add(logs); logService.Debug(key); } //为了防止异常导致之前已经存储进去的数据重复,先删除对应的数据 ActionReportBusiness.Delete(zoneId, title); GeneratedActiveReport(title, zone, cloudflareLogs); GeneratedWhiteListReport(title, zone, cloudflareLogs); }
private void ShowEditInfo(ZoneEntity zoneEntity) { txtCode.Text = zoneEntity.ZoneCode; txtName.Text = zoneEntity.ZoneName; listWarehouse.EditValue = zoneEntity.WarehouseCode; listZoneType.EditValue = zoneEntity.ZoneTypeCode; listTemprature.EditValue = zoneEntity.TemperatureCode; comboIsActive.Text = zoneEntity.IsActive; }
///<summary> ///根据仓库查询所有货区和货位 ///</summary> ///<returns></returns> public List <ZoneEntity> GetZoneByWarehouseCode(string warehouseCode) { List <ZoneEntity> list = new List <ZoneEntity>(); try { #region 请求数据 System.Text.StringBuilder loStr = new System.Text.StringBuilder(); loStr.Append("whCode=").Append(warehouseCode); string jsonQuery = WebWork.SendRequest(loStr.ToString(), WebWork.URL_GetZoneByWarehouseCode); if (string.IsNullOrEmpty(jsonQuery)) { MsgBox.Warn(WebWork.RESULT_NULL); //LogHelper.InfoLog(WebWork.RESULT_NULL); return(list); } #endregion #region 正常错误处理 JsonGetZoneByWarehouseCode bill = JsonConvert.DeserializeObject <JsonGetZoneByWarehouseCode>(jsonQuery); if (bill == null) { MsgBox.Warn(WebWork.JSON_DATA_NULL); return(list); } if (bill.flag != 0) { MsgBox.Warn(bill.error); return(list); } #endregion #region 赋值数据 foreach (JsonGetZoneByWarehouseCodeResult jbr in bill.result) { ZoneEntity asnEntity = new ZoneEntity(); asnEntity.ZoneCode = jbr.znCode; asnEntity.ZoneName = jbr.znName; list.Add(asnEntity); } return(list); #endregion } catch (Exception ex) { MsgBox.Err(ex.Message); } return(list); }
public LocationEntity PrepareSave() { LocationEntity editEntity = locationEntity; if (editEntity == null) { editEntity = new LocationEntity(); editEntity.WarehouseCode = GlobeSettings.LoginedUser.WarehouseCode; editEntity.WarehouseName = GlobeSettings.LoginedUser.WarehouseName; } editEntity.LocationCode = txtCode.Text.Trim(); editEntity.LocationName = txtName.Text.Trim(); ZoneEntity zone = listZones.Properties.GetDataSourceRowByKeyValue(listZones.EditValue) as ZoneEntity; editEntity.ZoneCode = zone.ZoneCode; editEntity.PassageCode = txtPassage.Text.Trim(); editEntity.ShelfCode = txtShelf.Text.Trim(); editEntity.FloorCode = txtFloor.Text.Trim(); editEntity.CellCode = txtCellCode.Text.Trim(); editEntity.SortOrder = (int)spinSortOrder.Value; editEntity.ZoneName = zone.ZoneName; if (listUnitGroup.EditValue != null) { editEntity.GrpCode = ConvertUtil.ToString(listUnitGroup.EditValue); editEntity.GrpName = listUnitGroup.Text; } else { editEntity.GrpCode = null; editEntity.GrpName = null; } if (listUnits.EditValue != null) { editEntity.UnitCode = ConvertUtil.ToString(listUnits.EditValue); editEntity.UnitName = listUnits.Text; } else { editEntity.UnitCode = editEntity.UnitName = null; } editEntity.LowerSize = (int)spinLowerSize.Value; editEntity.UpperSize = (int)spinUpperSize.Value; editEntity.IsActive = comboIsActive.Text; return(editEntity); }
public static void Add(ZoneEntity item) { string cons = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(); StringBuilder query = new StringBuilder(@"INSERT INTO dbo.t_Zone_Info ( ZoneId , ZoneName , AuthEmail , AuthKey , IfTestStage , IfEnable , IfAttacking , ThresholdForHost, PeriodForHost, IfAnalyzeByHostRule, HostNames ) VALUES ( @zoneID , -- ZoneId - nvarchar(512) @zoneName , -- ZoneName - nvarchar(256) @authEmail , -- AuthEmail - nvarchar(256) @authKey , -- AuthKey - nvarchar(256) @ifTest , -- IfTestStage - int @ifEnable , -- IfEnable - int @ifAttacking , -- IfAttacking - int @thresholdForHost , -- ThresholdForHost - int @periodForHost , -- PeriodForHost - int @ifAnalyzeByHostRule, -- IfAnalyzeByHostRule - int @hostNames -- HostNames )"); using (SqlConnection conn = new SqlConnection(cons)) { SqlCommand cmd = new SqlCommand(query.ToString(), conn); cmd.Parameters.AddWithValue("@zoneID", item.ZoneId); cmd.Parameters.AddWithValue("@zoneName", item.ZoneName); cmd.Parameters.AddWithValue("@authEmail", item.AuthEmail); cmd.Parameters.AddWithValue("@authKey", item.AuthKey); cmd.Parameters.AddWithValue("@ifTest", item.IfTestStage); cmd.Parameters.AddWithValue("@ifEnable", item.IfEnable); cmd.Parameters.AddWithValue("@ifAttacking", item.IfAttacking); cmd.Parameters.AddWithValue("@thresholdForHost", item.ThresholdForHost); cmd.Parameters.AddWithValue("@periodForHost", item.PeriodForHost); cmd.Parameters.AddWithValue("@ifAnalyzeByHostRule", item.IfAnalyzeByHostRule); cmd.Parameters.AddWithValue("@hostNames", item.HostNames); conn.Open(); cmd.ExecuteNonQuery(); } }
/// <summary> /// 编辑 /// </summary> private void ShowEditZone() { ZoneEntity editEntity = SelectedZoneRow; if (editEntity == null) { MsgBox.Warn("没有要修改的数据。"); return; } FrmZoneEdit frmPartitionEdit = new FrmZoneEdit(editEntity); frmPartitionEdit.DataSourceChanged += OnEditChanage; frmPartitionEdit.ShowDialog(); }
public static ZoneEntity GetZoneByZoneId(string zoneID) { string cons = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(); ZoneEntity result = new ZoneEntity(); StringBuilder query = new StringBuilder(@"SELECT [ZoneId], [ZoneName], [AuthEmail], [IfTestStage], [IfEnable], [IfAttacking], [Id], [ThresholdForHost], [PeriodForHost], [IfAnalyzeByHostRule], [HostNames], [AuthKey] from [t_Zone_Info] WHERE [ZoneId] = @zoneID "); using (SqlConnection conn = new SqlConnection(cons)) { var cmd = new SqlCommand(query.ToString(), conn); cmd.Parameters.AddWithValue("@zoneID", zoneID); conn.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { result = new ZoneEntity { ZoneId = Convert.ToString(reader["ZoneId"]), ZoneName = Convert.ToString(reader["ZoneName"]), AuthEmail = Convert.ToString(reader["AuthEmail"]), IfTestStage = Convert.ToInt32(reader["IfTestStage"]) > 0, IfEnable = Convert.ToInt32(reader["IfEnable"]) > 0, IfAttacking = Convert.ToInt32(reader["IfAttacking"]) > 0, TableID = Convert.ToInt32(reader["Id"]), AuthKey = Convert.ToString(reader["AuthKey"]), ThresholdForHost = Convert.ToInt32(reader["ThresholdForHost"]), PeriodForHost = Convert.ToInt32(reader["PeriodForHost"]), IfAnalyzeByHostRule = Convert.ToInt32(reader["IfAnalyzeByHostRule"]) > 0, HostNames = Convert.ToString(reader["HostNames"]), }; } } } return(result); }
private List <AuditLogEntity> BanIp(ZoneEntity zone, CloudFlareApiService cloudflare, AnalyzeResult analyzeResult) { List <AuditLogEntity> auditLogEntities = new List <AuditLogEntity>(); foreach (var rst in analyzeResult.result) { foreach (var broken in rst.BrokenIpList) { StringBuilder sbDetail = new StringBuilder(); if (rst.Url.EndsWith("*")) { var count = broken.RequestRecords.Sum(a => a.RequestCount); //logger.Debug(JsonConvert.SerializeObject(new { // count= count, // RequestRecords = broken.RequestRecords //})); sbDetail.Append($"IP [{broken.IP}] visited [{rst.Url}] [{count}] times, time range:[{analyzeResult.timeStage}].<br /> Exceeded rate limiting threshold(URL=[{rst.Url}],Period=[{rst.Period}],Threshold=[{rst.Threshold}],EnlargementFactor=[{rst.EnlargementFactor}]),details(only list the top 10 records):<br />"); var top10 = broken.RequestRecords.OrderByDescending(a => a.RequestCount).Take(10); foreach (var item in top10) { sbDetail.AppendFormat("[{0}] {1} times.<br />", item.FullUrl, item.RequestCount); } } else { var count = broken.RequestRecords.Sum(a => a.RequestCount); //logger.Debug(JsonConvert.SerializeObject(new //{ // count = count, // RequestRecords = broken.RequestRecords //})); sbDetail.Append($"IP [{broken.IP}] visited [{rst.Url}] [{count}] times, time range:[{analyzeResult.timeStage}].<br /> Exceeded rate limiting threshold(URL=[{rst.Url}],Period=[{rst.Period}],Threshold=[{rst.Threshold}],EnlargementFactor=[{rst.EnlargementFactor}]).<br />"); } string banIpLog = BanIpByRateLimitRule(zone, zone.IfTestStage, cloudflare, analyzeResult.timeStage, broken.RequestRecords.FirstOrDefault().HostName, broken.IP, rst.Period, rst.Threshold, rst.BrokenIpList.Count); if (!string.IsNullOrEmpty(banIpLog)) { sbDetail.Append(banIpLog); } auditLogEntities.Add(new AuditLogEntity(zone.TableID, LogLevel.Audit, sbDetail.ToString())); } } return(auditLogEntities); }
/// <summary> /// 基础管理(货区信息-更改货区信息) /// </summary> /// <param name="entity"></param> /// <param name="isNew"></param> /// <returns></returns> public bool SaveUpdateZone(ZoneEntity entity, bool isNew) { try { #region 请求数据 System.Text.StringBuilder loStr = new System.Text.StringBuilder(); loStr.Append("znCode=").Append(entity.ZoneCode).Append("&"); loStr.Append("znName=").Append(entity.ZoneName).Append("&"); loStr.Append("ztCode=").Append(entity.ZoneTypeCode).Append("&"); loStr.Append("whCode=").Append(entity.WarehouseCode).Append("&"); loStr.Append("tempCode=").Append(entity.TemperatureCode).Append("&"); loStr.Append("isActive=").Append(entity.IsActive); string jsonQuery = WebWork.SendRequest(loStr.ToString(), WebWork.URL_SaveUpdateZone); if (string.IsNullOrEmpty(jsonQuery)) { MsgBox.Warn(WebWork.RESULT_NULL); //LogHelper.InfoLog(WebWork.RESULT_NULL); return(false); } #endregion #region 正常错误处理 Sucess bill = JsonConvert.DeserializeObject <Sucess>(jsonQuery); if (bill == null) { MsgBox.Warn(WebWork.JSON_DATA_NULL); return(false); } if (bill.flag != 0) { MsgBox.Warn(bill.error); return(false); } #endregion return(true); } catch (Exception ex) { MsgBox.Err(ex.Message); } return(false); }
protected void btnSubmit_Click(object sender, EventArgs e) { try { ValidateBusinessData("G1"); ValidateBusinessData("G2"); ZoneEntity entity = new ZoneEntity(); if (Convert.ToString(ViewState["Add"]) == "Add") { entity.OperationId = 1; } else if (Convert.ToString(ViewState["Update"]) == "Update") { entity.OperationId = 2; entity.ZoneId = Utility.GetLong(ViewState["ZoneId"]); } entity.ZoneName = txtZoneName.Text.Trim(); entity.RegionId = Utility.GetLong(ddlRegion.SelectedValue); OperationStatusEntity c = new ConfigrationRepository(SessionContext).UpdateZone(entity); if (c.StatusResult == true) { ShowInfoMessage(c.InfoMessage); ClearPageControl(); FillGrid(); } else { ShowErrorMessage(c.InfoMessage); } } catch (ValidationException ex) { ShowErrorMessage(ex.Message); } catch (BaseException be) { ShowErrorMessage(be.DisplayMessage); } }
private LayoutEntity CreateLayout(string themeName) { LayoutEntity layoutEntity = _layoutService.Get(m => m.Title == themeName).FirstOrDefault(); if (layoutEntity == null) { layoutEntity = new LayoutEntity { Title = themeName, LayoutName = themeName }; layoutEntity.Zones = new ZoneCollection(); layoutEntity.Html = new LayoutHtmlCollection(); string[] zoneNames = new string[] { "Header", "Content", "Footer" }; for (int i = 0; i < zoneNames.Length; i++) { ZoneEntity zone = new ZoneEntity { ZoneName = zoneNames[i], HeadingCode = $"ZONE-{i}" }; layoutEntity.Zones.Add(zone); layoutEntity.Html.Add(new LayoutHtml { Html = "<div class=\"main custom-style container-fluid\"><div class=\"additional row\"><div class=\"additional col-md-12\"><div class=\"colContent row\"><div class=\"additional zone\">" }); layoutEntity.Html.Add(new LayoutHtml { Html = ZoneEntity.ZoneTag }); layoutEntity.Html.Add(new LayoutHtml { Html = zone.HeadingCode }); layoutEntity.Html.Add(new LayoutHtml { Html = ZoneEntity.ZoneEndTag }); layoutEntity.Html.Add(new LayoutHtml { Html = "</div></div></div></div></div>" }); } _layoutService.Add(layoutEntity); } return(layoutEntity); }
private bool Save() { if (!IsFieldValueValid()) { return(false); } bool success = false; try { ZoneEntity editEntity = PrepareSave(); //int ret = zoneDal.Save(editEntity, isNew); //if (ret == -1) // MsgBox.Warn("货区编号已存在,请改为其他的编号。"); //else if (ret == -2) // MsgBox.Warn("更新失败,该行已经被其他人删除。"); //else bool ret; if (isNew) { ret = SaveAddZone(editEntity, isNew); } else { ret = SaveUpdateZone(editEntity, isNew); } if (ret) { success = true; if (DataSourceChanged != null) { DataSourceChanged(editEntity, null); } } } catch (Exception ex) { MsgBox.Err(ex.Message); } return(success); }
public ZoneEntity PrepareSave() { ZoneEntity editEntity = zoneEntity; if (editEntity == null) { editEntity = new ZoneEntity(); } editEntity.ZoneCode = txtCode.Text.Trim(); editEntity.ZoneName = txtName.Text.Trim(); editEntity.WarehouseCode = ConvertUtil.ToString(listWarehouse.EditValue); editEntity.WarehouseName = ConvertUtil.ToString(listWarehouse.Text); editEntity.ZoneTypeCode = ConvertUtil.ToString(listZoneType.EditValue); editEntity.ZoneTypeName = ConvertUtil.ToString(listZoneType.Text); editEntity.TemperatureCode = ConvertUtil.ToString(listTemprature.EditValue); editEntity.TemperatureName = ConvertUtil.ToString(listTemprature.Text); editEntity.IsActive = comboIsActive.Text; return(editEntity); }
/// <summary> /// 添加或编辑货区 /// </summary> /// <param name="entity"></param> /// <param name="operatorFlag">添加或编辑</param> /// <returns></returns> public int Save(ZoneEntity entity, bool isNew) { IMapper map = DatabaseInstance.Instance(); int ret = -2; if (isNew) { //检查编号是否已经存在 if (IsZoneCodeExists(entity)) { return(-1); } ret = map.Execute("INSERT INTO WM_ZONE(ZN_CODE, ZN_NAME, ZT_CODE, WH_CODE, TEMP_CODE, IS_ACTIVE) " + "VALUES(@COD, @NAM, @ZT_CODE, @WH_CODE, @TEMP_CODE, @IS_ACTIVE)", new { COD = entity.ZoneCode, NAM = entity.ZoneName, ZT_CODE = entity.ZoneTypeCode, WH_CODE = entity.WarehouseCode, TEMP_CODE = entity.TemperatureCode, IS_ACTIVE = entity.IsActive }); } else { //更新 ret = map.Execute("update WM_ZONE set ZN_NAME = @NAM, ZT_CODE = @ZT_CODE, WH_CODE = @WH_CODE, TEMP_CODE = @TEMP_CODE, IS_ACTIVE = @IS_ACTIVE where ZN_CODE = @COD", new { COD = entity.ZoneCode, NAM = entity.ZoneName, ZT_CODE = entity.ZoneTypeCode, WH_CODE = entity.WarehouseCode, TEMP_CODE = entity.TemperatureCode, IS_ACTIVE = entity.IsActive }); } return(ret); }
/// <summary> /// 删除 /// </summary> private void DoDeleteSelectedZone() { ZoneEntity removeEntity = SelectedZoneRow; if (removeEntity == null) { MsgBox.Warn("没有要删除的数据。"); return; } if (MsgBox.AskOK(string.Format("确定要删除货区{0}吗?", removeEntity.ZoneCode)) == DialogResult.OK) { bool ret = DeleteZone(removeEntity.ZoneCode); if (ret) { bindingSource1.Remove(removeEntity); } else { MsgBox.Warn("不能删除,该货区有相关联的货位。"); } } }
public static void Edit(ZoneEntity item) { string cons = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(); StringBuilder query = new StringBuilder(@"UPDATE dbo.t_Zone_Info SET ZoneId=@zoneID, ZoneName=@zoneName, AuthEmail=@authEmail, AuthKey=@authKey, IfTestStage=@ifTest, IfEnable=@ifEnable, ThresholdForHost=@thresholdForHost, PeriodForHost=@periodForHost, IfAnalyzeByHostRule=@ifAnalyzeByHostRule, IfAttacking=@ifAttacking, HostNames=@hostNames WHERE Id=@id"); using (SqlConnection conn = new SqlConnection(cons)) { SqlCommand cmd = new SqlCommand(query.ToString(), conn); cmd.Parameters.AddWithValue("@zoneID", item.ZoneId); cmd.Parameters.AddWithValue("@zoneName", item.ZoneName); cmd.Parameters.AddWithValue("@authEmail", item.AuthEmail); cmd.Parameters.AddWithValue("@authKey", item.AuthKey); cmd.Parameters.AddWithValue("@ifTest", item.IfTestStage); cmd.Parameters.AddWithValue("@ifEnable", item.IfEnable); cmd.Parameters.AddWithValue("@ifAttacking", item.IfAttacking); cmd.Parameters.AddWithValue("@id", item.TableID); cmd.Parameters.AddWithValue("@thresholdForHost", item.ThresholdForHost); cmd.Parameters.AddWithValue("@periodForHost", item.PeriodForHost); cmd.Parameters.AddWithValue("@ifAnalyzeByHostRule", item.IfAnalyzeByHostRule); cmd.Parameters.AddWithValue("@hostNames", item.HostNames); conn.Open(); cmd.ExecuteNonQuery(); } }
public FrmZoneEdit(ZoneEntity zoneEntity) : this() { this.zoneEntity = zoneEntity; }
public static ZoneCollection GetZones(string[] html, out LayoutHtmlCollection result) { ZoneEntity zone = null; bool initZoneStart = false; result = new LayoutHtmlCollection(); ZoneCollection zones = new ZoneCollection(); foreach (string item in html) { if (item == ZoneEntity.ZoneTag) { zone = new ZoneEntity(); initZoneStart = true; continue; } else if (item == ZoneEntity.ZoneEndTag) { initZoneStart = false; if (zone.ID.IsNullOrEmpty()) { zone.ID = Guid.NewGuid().ToString("N"); } zones.Add(zone); result.Add(new LayoutHtml { Html = ZoneEntity.ZoneTag }); result.Add(new LayoutHtml { Html = zone.ID }); result.Add(new LayoutHtml { Html = ZoneEntity.ZoneEndTag }); continue; } if (!initZoneStart) { result.Add(new LayoutHtml { Html = item }); } else { if (item.Contains("name=\"ZoneName\"") || item.Contains("name=\"ZoneId\"")) { string[] zoneInfo = item.Split(new string[] { "<input" }, StringSplitOptions.RemoveEmptyEntries); foreach (string zonePart in zoneInfo) { if (zonePart.Contains("name=\"ZoneName\"")) { zone.ZoneName = zonePart.GetInnerContent("value=\"", "\"", 0); } else if (zonePart.Contains("name=\"ID\"")) { zone.ID = zonePart.GetInnerContent("value=\"", "\"", 0); } else if (zonePart.Contains("name=\"LayoutId\"")) { zone.LayoutId = zonePart.GetInnerContent("value=\"", "\"", 0); } } } } } return zones; }