C# |
|
[WebMethod] |
public static RadTreeNodeData[] LoadNodes(RadTreeNodeData node) // called each time a node is expanded |
{ |
AttributeService.Attribute atts = new AttributeService.Attribute(); |
List<RadTreeNodeData> result = new List<RadTreeNodeData>(); |
DataSet ds = new DataSet(), ads = new DataSet(); |
DataTable data = new DataTable(), attributeData = new DataTable(); |
int WebP_Id = Int32.Parse(HttpContext.Current.Session["WebPID"].ToString()); |
ArrayList RadNodeChanged = new ArrayList(); |
|
ds = atts.GetChildrenByWebpId(WebP_Id, Convert.ToInt32(node.Value)); // gets the children for a specific item |
data = ds.Tables[0]; |
|
foreach (DataRow row in data.Rows) |
{ |
RadTreeNodeData childNode = new RadTreeNodeData(); |
|
childNode.Text = row["AttributeName"].ToString(); // adds the name and the text to "childNode" |
childNode.Value = row["Attribute_Id"].ToString(); |
|
if (atts.GetAllChildren(Convert.ToInt32(childNode.Value)).Tables[0].Rows.Count > 0) |
{ |
childNode.ExpandMode = TreeNodeExpandMode.WebService; |
} |
//can code go here to make the color of the node red when the parent is expanded? |
|
//attributeData = atts.GetAttributes(WebP_Id).Tables[0]; |
//foreach (DataRow dr in attributeData.Rows) |
//{ |
// if (String.Compare(dr["AttributeId"].ToString(), childNode.Value) == 0) |
// { |
// childNode.Attributes["ForeColor"] = System.Drawing.Color.Red; |
// } |
//} //doesn't work |
|
result.Add(childNode); |
} |
return result.ToArray(); |
} |
|
private static void LoadRootAttributeNodes(RadTreeView treeView, TreeNodeExpandMode expandMode) |
{ |
AttributeService.Attribute attser = new AttributeService.Attribute(); // function is called to set the origin nodes |
int WebP_Id = Int32.Parse(HttpContext.Current.Session["WebPID"].ToString()); |
DataSet ds = new DataSet(); |
ArrayList Cat = new ArrayList(); |
DataTable dt = new DataTable(); |
|
ds = attser.GetChildrenByWebpId(WebP_Id, 0); // zero being for the high level parent nodes |
dt = ds.Tables[0]; |
|
foreach (DataRow row in dt.Rows) |
{ |
RadTreeNode node = new RadTreeNode(); |
node.Text = row["AttributeName"].ToString(); |
node.Value = row["Attribute_Id"].ToString(); |
node.ExpandMode = expandMode; |
treeView.Nodes.Add(node); |
} |
|
} |
|
protected void AttributesTree_HandleDrop(object sender, RadTreeNodeDragDropEventArgs e) |
{ //drag and drop function, when an item is released from the tree, this function will be called |
RadTreeNode sourceNode = e.SourceDragNode, destNode = e.DestDragNode; |
RadTreeViewDropPosition dropPosition = e.DropPosition; |
AttributeService.Attribute atts = new AttributeService.Attribute(); |
ArrayList deletedCat = new ArrayList(); |
DataSet ds = new DataSet(); |
DataTable dt = (DataTable)Session["AttributesTable"]; |
bool existsInList = false; |
|
|
Session["TreeView"] = AttributeTree; |
|
foreach (GridDataItem dataItem in CurrentAttributesList.Items) |
{ |
if (dataItem.ForeColor == System.Drawing.Color.Red) |
{ |
deletedCat.Add(dataItem["AttributeId"].Text); |
} |
} |
|
foreach (RadTreeNode node in e.DraggedNodes) |
{ |
existsInList = false; |
foreach ( GridDataItem item in CurrentAttributesList.Items ) |
{ |
if (item["AttributeId"].Text == node.Value) |
{ |
existsInList = true; |
} |
} |
if (existsInList) |
{ |
Master.AttributePublishErrorMessage = "Please use an attribute that is not in the list"; // duplicate item |
} |
else |
{ |
ds = atts.GetAttributeByAttributeID(Convert.ToInt32(node.Value)); |
if (ds.Tables.Count > 0) |
{ |
foreach (DataRow dr in ds.Tables[0].Rows) |
{ |
if (String.Compare(dr["Parent_ID"].ToString(), "0") == 0) |
{ |
Master.AttributePublishErrorMessage = "Please use the lowest possible, non-parent attribute available."; |
} |
else |
{ |
dt.Rows.Add(dr["Attribute_ID"], dr["AttributeName"], dr["AttributePath"]); |
foreach (RadTreeNode currentnode in AttributeTree.SelectedNodes) |
{ |
currentnode.ForeColor = System.Drawing.Color.Red; |
RadTreeNodeChanged.Add(currentnode.Value); |
} |
} |
} |
} |
} |
} |
|
Session["AttributesTable"] = dt; |
CurrentAttributesList.DataSource = dt; |
CurrentAttributesList.DataBind(); |
|
for (int i = 0; i < CurrentAttributesList.Items.Count; i++) |
{ |
for (int j = 0; j < deletedCat.Count; j++) |
{ |
if (CurrentAttributesList.Items[i]["AttributeId"].Text == deletedCat[j].ToString()) |
{ |
CurrentAttributesList.Items[i].Font.Strikeout = true; |
CurrentAttributesList.Items[i].ForeColor = System.Drawing.Color.Red; |
} |
} |
} |
} |
|
public void CurrentAttributes(int webp_id) |
{ |
AttributeService.Attribute atts = new AttributeService.Attribute(); |
DataSet attributes = atts.GetAttributes(webp_id); |
DataTable attributeData = attributes.Tables[0]; |
CurrentAttributesList.DataSource = attributeData; |
CurrentAttributesList.DataBind(); |
Session["AttributesTable"] = attributeData; |
} |
protected void CurrentAttributesList_Command(Object source, CommandEventArgs e) |
{ // the rad grid function when a command for save, delete, or refresh |
int getWebP_Id = GetValidWebpId(SearchBox.Text), listIndex; |
WebServiceProxy wsp = new WebServiceProxy(); |
switch (e.CommandName) |
{ |
case "SaveChanges": //when the command is save, the attribute will be saved to the database |
|
AttributeService.Attribute atts = new AttributeService.Attribute(); |
CategoryStatus attributeStatus, status; |
currentAttributes = new ArrayList(); |
DataSet CurrentAttributeList = atts.GetAttributes(getWebP_Id); |
|
// load the current categories into a list, stores the status of each cat id |
foreach (DataRow dataRowAttribute in CurrentAttributeList.Tables[0].Rows) |
{ |
attributeStatus.CatId = Convert.ToString(dataRowAttribute["AttributeId"]); |
attributeStatus.Status = 0; |
attributeStatus.Primary = false; |
|
currentAttributes.Add(attributeStatus); |
} |
// cycles through the rad grid to detect changes |
foreach (GridDataItem dataItem in CurrentAttributesList.Items) |
{ |
string catid = dataItem["AttributeId"].Text; |
listIndex = FindInList(catid, currentAttributes); |
|
if (dataItem.ForeColor == System.Drawing.Color.Red) |
{ |
updateListStatus(currentAttributes, ListStatus.Remove, listIndex); |
} |
|
if (listIndex < 0) //not in the list, needs to be added |
{ |
status.CatId = catid; |
status.Status = ListStatus.AddPrimary; |
status.Primary = false; |
currentAttributes.Add(status); |
} |
else |
{ |
status = (CategoryStatus)currentAttributes[listIndex]; |
} |
} |
// stores the status of each cat id (add, remove, or no change) |
foreach (CategoryStatus cs in currentAttributes) |
{ |
switch (cs.Status) |
{ |
case ListStatus.NoChange: |
break; |
case ListStatus.AddPrimary: |
wsp.AddProductAttribute(getWebP_Id, Convert.ToInt32(cs.CatId), Request.ServerVariables["auth_user"], 0); |
break; |
case ListStatus.Remove: |
wsp.DeleteProductAttributes(getWebP_Id, Convert.ToInt32(cs.CatId)); |
break; |
} |
} |
CurrentAttributes(getWebP_Id); |
|
|
case "DeleteSelected": |
// using a for loop to loop through each item, then set the selected ones to be red and struck through |
// need to call a rebind instead of binding to a table to keep font attributes |
for (int i = 0; i < CurrentAttributesList.Items.Count; i++) |
{ |
if (CurrentAttributesList.Items[i].Selected) |
{ |
CurrentAttributesList.Items[i].Font.Strikeout = true; |
CurrentAttributesList.Items[i].ForeColor = System.Drawing.Color.Red; |
} |
} |
|
CurrentAttributesList.Rebind(); |
break; |
case "RebindGrid": // refresh grid back to original state, before any changes were made after hitting the save button |
getWebP_Id = GetValidWebpId(SearchBox.Text); |
CurrentAttributes(getWebP_Id); |
|
foreach (string id in RadTreeNodeChanged) |
{ |
ControlItem node = AttributeTree.FindChildByValue <ControlItem> (id); |
node.ForeColor = System.Drawing.Color.Black; //doesn't work |
} |
break; |
default: |
break; |
} |
} |