protected void RadGrid_VariantSpliter_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem myItem = (GridDataItem)e.Item; string myItemID = myItem.GetDataKeyValue("Variant_SpliterID").ToString(); HyperLink myAddPropertyLink = (HyperLink)myItem["Variant_SpliterID"].FindControl("hlink_AddProperty"); myAddPropertyLink.Attributes["href"] = "#"; myAddPropertyLink.Attributes["onclick"] = string.Format("return Show_ControlManager('PoP_PropertyCreate.aspx?Variant_SpliterID={0}&Action=Create');", myItemID); HyperLink myEditLink = (HyperLink)myItem["Variant_SpliterID"].FindControl("hlink_EditSpliter"); myEditLink.Attributes["href"] = "#"; myEditLink.Attributes["onclick"] = string.Format("return Show_ControlManager('PoP_SpliterEditor.aspx?Variant_SpliterID={0}');", myItemID); LinkButton myDeleteLink = (LinkButton)myItem["Variant_SpliterID"].FindControl("lbtn_DeleteSpliter"); myDeleteLink.OnClientClick = string.Format("return confirm('Are you sure you want to delete spliter \"{0}\" ?');", DataBinder.Eval(myItem.DataItem, "Spliter_Name")); } if (e.Item is GridNestedViewItem) { GridNestedViewItem myNestedItem = (GridNestedViewItem)e.Item; string myItemID = myNestedItem.ParentItem.GetDataKeyValue("Variant_SpliterID").ToString(); RadGrid myRadGrid = (RadGrid)myNestedItem.FindControl("RadGrid_VariantProperties"); ProductVariantMgr myProductVariantMgr = new ProductVariantMgr(); List <Variant_Property> myVariant_Properties = myProductVariantMgr.Get_Product_Variant_Properties_BySpliterID(myItemID); if (myVariant_Properties.Count < 1) { myRadGrid.Visible = false; } else { myRadGrid.DataSource = myVariant_Properties; myRadGrid.DataBind(); } } }
protected void RadGrid_VariantProperties_RowDrop(object sender, GridDragDropEventArgs e) { if (string.IsNullOrEmpty(e.HtmlElement) && e.DestDataItem != null) { if (e.DestDataItem.OwnerGridID == RadGrid_VariantSpliter.ClientID) { #region Dest drop is on Spliter ProductVariantMgr myProductVariantMgr = new ProductVariantMgr(); Variant_Property myVariant_Property = myProductVariantMgr.Get_Product_Variant_Property(e.DraggedItems[0].GetDataKeyValue("Variant_PropertyID").ToString()); Variant_Spliter myVariant_Spliter = myProductVariantMgr.Get_Product_Variant_Spliter(e.DestDataItem.GetDataKeyValue("Variant_SpliterID").ToString()); if (myVariant_Spliter.Variant_SpliterID != myVariant_Property.Variant_SpliterID) { List <Variant_Property> originVariant_Properties = myProductVariantMgr.Get_Product_Variant_Properties_BySpliterID(myVariant_Property.Variant_SpliterID); List <Variant_Property> destVariant_Properties = myProductVariantMgr.Get_Product_Variant_Properties_BySpliterID(myVariant_Spliter.Variant_SpliterID); Variant_Property draggedVariant_Property = Get_Variant_Property_in_List(originVariant_Properties, myVariant_Property.Variant_PropertyID); originVariant_Properties.Remove(draggedVariant_Property); destVariant_Properties.Add(draggedVariant_Property); // Update Property to new Spliter e2Data[] UpdateData_Property = { new e2Data("Variant_PropertyID", draggedVariant_Property.Variant_PropertyID), new e2Data("Variant_SpliterID", myVariant_Spliter.Variant_SpliterID) }; myProductVariantMgr.Edit_Product_Variant_Property(UpdateData_Property); // Sort Old list foreach (Variant_Property Variant_Property in originVariant_Properties) { // Variant Property e2Data[] UpdateData = { new e2Data("Variant_PropertyID", Variant_Property.Variant_PropertyID), new e2Data("SortOrder", (originVariant_Properties.IndexOf(Get_Variant_Property_in_List(originVariant_Properties, Variant_Property.Variant_PropertyID)) + 1).ToString()) }; myProductVariantMgr.Edit_Product_Variant_Property(UpdateData); } // Sort New list foreach (Variant_Property Variant_Property in destVariant_Properties) { // Variant Property e2Data[] UpdateData = { new e2Data("Variant_PropertyID", Variant_Property.Variant_PropertyID), new e2Data("SortOrder", (destVariant_Properties.IndexOf(Get_Variant_Property_in_List(destVariant_Properties, Variant_Property.Variant_PropertyID)) + 1).ToString()) }; myProductVariantMgr.Edit_Product_Variant_Property(UpdateData); } } #endregion } else { #region Dest drop is on Property ProductVariantMgr myProductVariantMgr = new ProductVariantMgr(); Variant_Property mydraggedVariant_Property = myProductVariantMgr.Get_Product_Variant_Property(e.DraggedItems[0].GetDataKeyValue("Variant_PropertyID").ToString()); Variant_Property mydestVariant_Property = myProductVariantMgr.Get_Product_Variant_Property(e.DestDataItem.GetDataKeyValue("Variant_PropertyID").ToString()); if (mydraggedVariant_Property.Variant_SpliterID == mydestVariant_Property.Variant_SpliterID) { // Under same spliter List <Variant_Property> myVariant_Properties = myProductVariantMgr.Get_Product_Variant_Properties_BySpliterID(mydestVariant_Property.Variant_SpliterID); Variant_Property draggedVariant_Property = Get_Variant_Property_in_List(myVariant_Properties, mydraggedVariant_Property.Variant_PropertyID); Variant_Property destVariant_Property = Get_Variant_Property_in_List(myVariant_Properties, mydestVariant_Property.Variant_PropertyID); int destIndex = myVariant_Properties.IndexOf(destVariant_Property); if (e.DropPosition == GridItemDropPosition.Above && e.DestDataItem.ItemIndex > e.DraggedItems[0].ItemIndex) { destIndex -= 1; } if (e.DropPosition == GridItemDropPosition.Below && e.DestDataItem.ItemIndex < e.DraggedItems[0].ItemIndex) { destIndex += 1; } myVariant_Properties.Remove(draggedVariant_Property); myVariant_Properties.Insert(destIndex, draggedVariant_Property); foreach (Variant_Property myVariant_Property in myVariant_Properties) { // Product Variant e2Data[] UpdateData = { new e2Data("Variant_PropertyID", myVariant_Property.Variant_PropertyID), new e2Data("SortOrder", (myVariant_Properties.IndexOf(Get_Variant_Property_in_List(myVariant_Properties, myVariant_Property.Variant_PropertyID)) + 1).ToString()) }; myProductVariantMgr.Edit_Product_Variant_Property(UpdateData); } } else { // Different spliter List <Variant_Property> originVariant_Properties = myProductVariantMgr.Get_Product_Variant_Properties_BySpliterID(mydraggedVariant_Property.Variant_SpliterID); List <Variant_Property> destVariant_Properties = myProductVariantMgr.Get_Product_Variant_Properties_BySpliterID(mydestVariant_Property.Variant_SpliterID); Variant_Property draggedVariant_Property = Get_Variant_Property_in_List(originVariant_Properties, mydraggedVariant_Property.Variant_PropertyID); Variant_Property destVariant_Property = Get_Variant_Property_in_List(destVariant_Properties, mydestVariant_Property.Variant_PropertyID); int destIndex = destVariant_Properties.IndexOf(destVariant_Property); if (e.DropPosition == GridItemDropPosition.Below) { destIndex += 1; } originVariant_Properties.Remove(draggedVariant_Property); destVariant_Properties.Insert(destIndex, draggedVariant_Property); // Update Property to new Spliter e2Data[] UpdateData_Property = { new e2Data("Variant_PropertyID", draggedVariant_Property.Variant_PropertyID), new e2Data("Variant_SpliterID", destVariant_Property.Variant_SpliterID) }; myProductVariantMgr.Edit_Product_Variant_Property(UpdateData_Property); // Sort Old list foreach (Variant_Property myVariant_Property in originVariant_Properties) { // Variant Property e2Data[] UpdateData = { new e2Data("Variant_PropertyID", myVariant_Property.Variant_PropertyID), new e2Data("SortOrder", (originVariant_Properties.IndexOf(Get_Variant_Property_in_List(originVariant_Properties, myVariant_Property.Variant_PropertyID)) + 1).ToString()) }; myProductVariantMgr.Edit_Product_Variant_Property(UpdateData); } // Sort New list foreach (Variant_Property myVariant_Property in destVariant_Properties) { // Variant Property e2Data[] UpdateData = { new e2Data("Variant_PropertyID", myVariant_Property.Variant_PropertyID), new e2Data("SortOrder", (destVariant_Properties.IndexOf(Get_Variant_Property_in_List(destVariant_Properties, myVariant_Property.Variant_PropertyID)) + 1).ToString()) }; myProductVariantMgr.Edit_Product_Variant_Property(UpdateData); } } #endregion } Control_Init(); } }