protected override void OnKeyDown(KeyEventArgs e) { List <SliderItem> lightSliders = new List <SliderItem>(); int prevIx = -1; int nextIx = -1; SliderItem activeSlider = null; SliderItem secondRange = null; int ix = -1; base.OnKeyDown(e); if (e.Source is MultiSlider) { if (SelectedSlider != null) { if (e.Key == Key.Delete) { ix = SliderList.IndexOf(SelectedSlider); #region Delete Gradient if (SelectedSlider.Variant == PointVariant.Gradient) { if (SliderList.Count != 1) { if (ix == 0) { // первый слайдер в списке nextIx = 0; do // необходимо удалить промежуточные яркостные точки справа { nextIx++; if (SliderList[nextIx].Variant == PointVariant.Lightness) { lightSliders.Add(SliderList[nextIx]); } else { break; } } while (nextIx != SliderList.Count - 1); activeSlider = SliderList[nextIx]; foreach (SliderItem si in lightSliders) { SliderList.Remove(si); } goto M1; } if (ix == SliderList.Count - 1) { // последний слайдер в списке prevIx = SliderList.Count - 1; do // удаляем промежуточные яркостные точки слева { prevIx--; if (SliderList[prevIx].Variant == PointVariant.Lightness) { SliderList.Remove(SliderList[prevIx]); } else { break; } } while (prevIx != 0); activeSlider = SliderList[prevIx]; goto M1; } nextIx = ix; do // пропускаем промежуточные яркостные точки справа { nextIx++; if (SliderList[nextIx].Variant != PointVariant.Lightness) { break; } } while (nextIx != SliderList.Count - 1); activeSlider = SliderList[nextIx]; M1: SliderList.Remove(SelectedSlider); SelectedSlider.IsSelected = false; ReArrangeSliderItems(); if (activeSlider != null) { activeSlider.IsSelected = true; SelectedSlider = activeSlider; UpdatePatternCommand.Execute(activeSlider); } } return; } #endregion #region Delete Range if (SelectedSlider.Variant == PointVariant.RangeLeft || SelectedSlider.Variant == PointVariant.RangeRight) { if (SliderList.Count != 2) { // первый диапазон в списке if ((SelectedSlider.Variant == PointVariant.RangeLeft && ix == 0) || (SelectedSlider.Variant == PointVariant.RangeRight && ix == 1)) { if (SelectedSlider.Variant == PointVariant.RangeLeft) { nextIx = 1; secondRange = SliderList[nextIx]; // rangeRight } else { nextIx = ix; secondRange = SliderList[nextIx - 1]; // rangeLeft } do // необходимо удалить яркостные точки справа { nextIx++; if (SliderList[nextIx].Variant == PointVariant.Lightness) { lightSliders.Add(SliderList[nextIx]); } else { break; } } while (nextIx != SliderList.Count - 1); activeSlider = SliderList[nextIx]; foreach (SliderItem si in lightSliders) { SliderList.Remove(si); } goto M2; } // последний диапазон в списке if ((SelectedSlider.Variant == PointVariant.RangeRight && ix == SliderList.Count - 1) || (SelectedSlider.Variant == PointVariant.RangeLeft && ix == SliderList.Count - 2)) { if (SelectedSlider.Variant == PointVariant.RangeRight) { prevIx = SliderList.Count - 1 - 1; // rangeLeftIx secondRange = SliderList[prevIx]; } else { prevIx = ix; secondRange = SliderList[prevIx + 1]; } do // удаляем промежуточные яркостные точки слева { prevIx--; if (SliderList[prevIx].Variant == PointVariant.Lightness) { SliderList.Remove(SliderList[prevIx]); } else { break; } } while (prevIx != 0); activeSlider = SliderList[prevIx]; goto M2; } // диапазон внутри списка if (SelectedSlider.Variant == PointVariant.RangeLeft) { secondRange = SliderList[ix + 1]; nextIx = ix + 1; } else { secondRange = SliderList[ix - 1]; nextIx = ix; } do // пропускаем промежуточные яркостные точки справа { nextIx++; if (SliderList[nextIx].Variant != PointVariant.Lightness) { break; } } while (nextIx != SliderList.Count - 1); activeSlider = SliderList[nextIx]; M2: SliderList.Remove(SelectedSlider); SliderList.Remove(secondRange); ReArrangeSliderItems(); if (activeSlider != null) { activeSlider.IsSelected = true; SelectedSlider = activeSlider; UpdatePatternCommand.Execute(activeSlider); } } return; } #endregion #region Delete Lightness if (SelectedSlider.Variant == PointVariant.Lightness) { activeSlider = SliderList[ix + 1]; SliderList.Remove(SelectedSlider); //SelectedSlider.IsSelected = false; ReArrangeSliderItems(); activeSlider.IsSelected = true; SelectedSlider = activeSlider; UpdatePatternCommand.Execute(activeSlider); } #endregion } } } }
//bool startMove = false; private void SliderItemGotMouseCapture(object sender, MouseEventArgs e) { if (SelectedSlider != null) { SelectedSlider.IsSelected = false; } SliderItem si = sender as SliderItem; sliderIx = SliderList.IndexOf(si); SelectedSlider = si; SelectedSlider.IsSelected = true; Position = SelectedSlider.Pos; // firtst slider in list if (sliderIx == 0) { si.SelectionStart = 1; if (SelectedSlider.Variant == PointVariant.RangeLeft) { si.SelectionEnd = SliderList[sliderIx + 1].Value; } else { si.SelectionEnd = SliderList[sliderIx + 1].Value - 1; } return; } //last slider in list if (sliderIx == SliderList.Count - 1) { si.SelectionEnd = Maxlimit; if (SelectedSlider.Variant == PointVariant.RangeRight) { si.SelectionStart = SliderList[sliderIx - 1].Value; } else { si.SelectionStart = SliderList[sliderIx - 1].Value + 1; } return; } // internal slider if (SelectedSlider.Variant == PointVariant.RangeRight) { si.SelectionStart = SliderList[sliderIx - 1].Value; si.SelectionEnd = SliderList[sliderIx + 1].Value - 1; return; } if (SelectedSlider.Variant == PointVariant.RangeLeft) { si.SelectionStart = SliderList[sliderIx - 1].Value + 1; si.SelectionEnd = SliderList[sliderIx + 1].Value; return; } if (SelectedSlider.Variant != PointVariant.RangeLeft && SelectedSlider.Variant != PointVariant.RangeRight) { si.SelectionStart = SliderList[sliderIx - 1].Value + 1; si.SelectionEnd = SliderList[sliderIx + 1].Value - 1; return; } }
private void OnTrackClick(object sender, MouseButtonEventArgs e) { SliderItem newSlider = null; if (e.ClickCount == 2) // DoubleClick { if (e.Source is Border && (e.Source as Border).Name == "PART_Track") { System.Windows.Point pt = e.GetPosition((UIElement)sender); double halfStep = (slidersArea.ActualWidth + 2 * Margin.Left) / this.Maxlimit; int sliderPos = Convert.ToInt32(pt.X / halfStep) + 1; //Console.WriteLine($"ActualWidth + Margin {slidersArea.ActualWidth + 2 * this.Margin.Left}"); //Console.WriteLine($"ptX {pt.X}"); //Console.WriteLine($"LedPos: {sliderPos}"); //Console.WriteLine($"CurrentMode: {AddMode}"); // AddMode = 0 Gradient // AddMode = 1 Range // AddMode = 2 Lightness PatternPoint pp = Pattern[sliderPos - 1]; // нельзя добавить слайдер в существующую позицию if (SliderList.FirstOrDefault(p => p.Value == (double)sliderPos) != null) { return; } // если первая точка в Pattern if (sliderPos < SliderList[0].Value) { SliderItem tmpSi = SliderList[0]; switch (AddMode) { case 1: //Range SliderList[0].PatternPoint.CopyTo(pp, SliderList[0].SliderType); SliderItem rangeLeft = CreateSlider(sliderPos, Maxlimit, pp); rangeLeft.Variant = PointVariant.RangeLeft; newSlider = rangeLeft; SliderItem rangeRight = CreateSlider(sliderPos, Maxlimit, pp); rangeRight.Variant = PointVariant.RangeRight; SliderList.Insert(0, rangeRight); SliderList.Insert(0, rangeLeft); ReArrangeSliderItems(); UpdatePatternCommand.Execute(rangeRight); break; case 2: //Lightness break; default: //Gradient SliderList[0].PatternPoint.CopyTo(pp, SliderList[0].SliderType); SliderItem gradient = CreateSlider(sliderPos, Maxlimit, pp); newSlider = gradient; SliderList.Insert(0, gradient); ReArrangeSliderItems(); UpdatePatternCommand.Execute(gradient); break; } if (newSlider != null) { if (SelectedSlider != null) { SelectedSlider.IsSelected = false; } newSlider.IsSelected = true; SelectedSlider = newSlider; } return; } // если последняя точка в Pattern if (sliderPos > SliderList[SliderList.Count - 1].Value) { SliderItem lastSi = SliderList[SliderList.Count - 1]; switch (AddMode) { case 1: // Range SliderList[SliderList.Count - 1].PatternPoint.CopyTo(pp, SliderList[0].SliderType); SliderItem rangeLeft = CreateSlider(sliderPos, Maxlimit, pp); rangeLeft.Variant = PointVariant.RangeLeft; SliderItem rangeRight = CreateSlider(sliderPos, Maxlimit, pp); rangeRight.Variant = PointVariant.RangeRight; SliderList.Add(rangeLeft); SliderList.Add(rangeRight); ReArrangeSliderItems(); UpdatePatternCommand.Execute(rangeLeft); break; case 2: //Lightness break; default: //Gradient SliderList[SliderList.Count - 1].PatternPoint.CopyTo(pp, SliderList[0].SliderType); SliderItem gradient = CreateSlider(sliderPos, Maxlimit, pp); SliderList.Add(gradient); ReArrangeSliderItems(); UpdatePatternCommand.Execute(gradient); break; } return; } // точка между PatternPoint SliderItem prevSi = null; SliderItem nextSi = null; int minLeft = Maxlimit; int minRight = Maxlimit; foreach (SliderItem si in SliderList) { if (si.Value > sliderPos) { if ((si.Value - sliderPos) < minRight) { minRight = (int)si.Value - sliderPos; nextSi = si; } } if (si.Value < sliderPos) { if ((sliderPos - si.Value) < minLeft) { minLeft = sliderPos - (int)si.Value; prevSi = si; } } } // нельзя добавить точку внутри Range if (nextSi.Variant == PointVariant.RangeRight) { return; } newSlider = CreateSlider(sliderPos, Maxlimit, Pattern[sliderPos - 1]); int ix = SliderList.IndexOf(nextSi); if (AddMode == 1) { newSlider.Variant = PointVariant.RangeLeft; SliderItem rangeRight = CreateSlider(sliderPos, Maxlimit, Pattern[sliderPos - 1]); rangeRight.Variant = PointVariant.RangeRight; SliderList.Insert(ix, rangeRight); SliderList.Insert(ix, newSlider); ReArrangeSliderItems(); if (newSlider != null) { if (SelectedSlider != null) { SelectedSlider.IsSelected = false; } newSlider.IsSelected = true; SelectedSlider = newSlider; } return; } if (AddMode == 2) { newSlider.Variant = PointVariant.Lightness; newSlider.PatternPoint.SaveLightness(); } SliderList.Insert(ix, newSlider); ReArrangeSliderItems(); if (newSlider != null) { if (SelectedSlider != null) { SelectedSlider.IsSelected = false; } newSlider.IsSelected = true; SelectedSlider = newSlider; } } } }
/// <summary> /// Layer列表的HTML生成 /// </summary> public void PushAjaxSliders() { EffectDBEntity EffectDB = Setting_EffectDB; QueryParam qp = new QueryParam(); qp.OrderType = 0; qp.PageIndex = WebHelper.GetIntParam(Request, "PageIndex", 2); if (qp.PageIndex <= 1) { qp.PageSize = WebHelper.GetIntParam(Request, "FirstScreen", 10); if (qp.PageSize <= 0) { qp.PageSize = WebHelper.GetIntParam(Request, "LoadDisplay", 10); } } else { qp.PageSize = WebHelper.GetIntParam(Request, "LoadDisplay", 10); qp.FirstScreen = WebHelper.GetIntParam(Request, "FirstScreen", 10); } qp.Where.Add(new SearchParam(DNNGo_DNNGalleryProGame_Slider._.ModuleId, Settings_ModuleID, SearchType.Equal)); qp.Where.Add(new SearchParam(DNNGo_DNNGalleryProGame_Slider._.Status, (Int32)EnumStatus.Activated, SearchType.Equal)); Int32 Search_GroupID = WebHelper.GetIntParam(HttpContext.Current.Request, "GroupID", 0); if (Search_GroupID > 0) { qp.Where.Add(new SearchParam(DNNGo_DNNGalleryProGame_Slider._.ID, DNNGo_DNNGalleryProGame_Slider_Group.BuilderArticleIDs(Search_GroupID), SearchType.In)); } int RecordCount = 0; List <DNNGo_DNNGalleryProGame_Slider> SliderList = new List <DNNGo_DNNGalleryProGame_Slider>(); Int32 Sortby = Settings_Sortby; String Orderfld = WebHelper.GetStringParam(Request, "Order", ""); Int32 OrderType = WebHelper.GetIntParam(Request, "OrderBy", -1); if (!String.IsNullOrEmpty(Orderfld)) { if (Orderfld.ToLower() == "title") { Sortby = OrderType == 1 ? (Int32)EnumSortby.Title_Desc : (Int32)EnumSortby.Title; } else if (Orderfld.ToLower() == "starttime") { Sortby = OrderType == 1 ? (Int32)EnumSortby.Time_Desc : (Int32)EnumSortby.Time; } } if (Sortby == (Int32)EnumSortby.Time) { qp.Orderfld = DNNGo_DNNGalleryProGame_Slider._.StartTime; SliderList = DNNGo_DNNGalleryProGame_Slider.FindAll(qp, out RecordCount); } else if (Sortby == (Int32)EnumSortby.Time_Desc) { qp.OrderType = 1; qp.Orderfld = DNNGo_DNNGalleryProGame_Slider._.StartTime; SliderList = DNNGo_DNNGalleryProGame_Slider.FindAll(qp, out RecordCount); } else if (Sortby == (Int32)EnumSortby.Title) { qp.Orderfld = DNNGo_DNNGalleryProGame_Slider._.Title; SliderList = DNNGo_DNNGalleryProGame_Slider.FindAll(qp, out RecordCount); } else if (Sortby == (Int32)EnumSortby.Title_Desc) { qp.OrderType = 1; qp.Orderfld = DNNGo_DNNGalleryProGame_Slider._.Title; SliderList = DNNGo_DNNGalleryProGame_Slider.FindAll(qp, out RecordCount); } else if (Sortby == (Int32)EnumSortby.Random) { qp.Orderfld = " newid() "; SliderList = DNNGo_DNNGalleryProGame_Slider.FindRandomAll(qp, out RecordCount); } else { qp.Orderfld = DNNGo_DNNGalleryProGame_Slider._.Sort; SliderList = DNNGo_DNNGalleryProGame_Slider.FindAll(qp, out RecordCount); } if (qp.Pages < qp.PageIndex) //索引数大于总页面数时不返回记录 { SliderList = new List <DNNGo_DNNGalleryProGame_Slider>(); } Dictionary <String, Object> jsonSliders = new Dictionary <string, Object>(); TemplateFormat xf = new TemplateFormat(); foreach (var SliderItem in SliderList) { int index = SliderList.IndexOf(SliderItem); //index 为索引值 Dictionary <String, Object> jsonSlider = new Dictionary <String, Object>(); jsonSlider.Add("ID", SliderItem.ID); jsonSlider.Add("Sort", SliderItem.Sort); jsonSlider.Add("CreateTime", SliderItem.CreateTime); jsonSlider.Add("StartTime", SliderItem.StartTime); jsonSlider.Add("EndTime", SliderItem.EndTime); jsonSlider.Add("CreateTimeUS", SliderItem.CreateTime.ToString("MM/dd/yyy HH:mm:ss")); jsonSlider.Add("StartTimeUS", SliderItem.StartTime.ToString("MM/dd/yyy HH:mm:ss")); jsonSlider.Add("EndTimeUS", SliderItem.EndTime.ToString("MM/dd/yyy HH:mm:ss")); jsonSlider.Add("Status", SliderItem.Status == 1 ? "checked=\"checked\"" : ""); jsonSlider.Add("Pages", qp.Pages); foreach (var SliderSetting in Setting_SliderSettingDB) { String SliderName = SliderSetting.Name; String SliderValue = xf.ViewSliderSettingT <String>(SliderItem, SliderName, SliderSetting.DefaultValue); if (SliderSetting.ControlType == EnumControlType.Urls.ToString()) { jsonSlider.Add(SliderName, ViewLinkUrl(SliderValue, false)); } else { jsonSlider.Add(SliderName, SliderValue); } } //加载分组 if (EffectDB.Groups) { jsonSlider.Add("Groups", xf.ToGroups(SliderItem)); } //取出Layers数据 if (EffectDB.Layers) { Dictionary <String, Object> jsonLayers = new Dictionary <String, Object>(); List <DNNGo_DNNGalleryProGame_Layer> LayerList = SliderItem.LayerList; if (LayerList != null && LayerList.Count > 0) { foreach (var Layer in LayerList) { int indexLayer = LayerList.IndexOf(Layer); Dictionary <String, Object> jsonLayer = new Dictionary <String, Object>(); foreach (var LayerSetting in Setting_LayerSettingDB) { String LayerName = LayerSetting.Name; String LayerValue = xf.ViewLayerSettingT <String>(Layer, LayerName, LayerSetting.DefaultValue); if (LayerSetting.ControlType == EnumControlType.Urls.ToString()) { jsonLayer.Add(LayerName, ViewLinkUrl(LayerValue, false)); } else { jsonLayer.Add(LayerName, LayerValue); } } jsonLayer.Add("ID", Layer.ID); jsonLayer.Add("Sort", Layer.Sort); jsonLayer.Add("Clicks", Layer.Clicks); jsonLayer.Add("Views", Layer.Views); jsonLayer.Add("Heats", Layer.Heats); jsonLayer.Add("CreateTime", Layer.CreateTime); jsonLayers.Add((10000 - indexLayer).ToString(), jsonLayer); } } jsonSlider.Add("Layers", jsonLayers); } //取出扩展项 Dictionary <String, Object> jsonExtension = new Dictionary <String, Object>(); if (!String.IsNullOrEmpty(SliderItem.Extension)) { List <KeyValueEntity> ExtensionSettings = ConvertTo.Deserialize <List <KeyValueEntity> >(SliderItem.Extension); foreach (KeyValueEntity kv in ExtensionSettings) { if (!jsonExtension.ContainsKey(kv.Key)) { jsonExtension.Add(kv.Key, kv.Value); } } } jsonSlider.Add("Extensions", jsonExtension); jsonSliders.Add(index.ToString(), jsonSlider); } //转换数据为json JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); Response.Clear(); Response.Write(jsSerializer.Serialize(jsonSliders)); Response.End(); }