/// <summary> /// 添加用户信息 /// </summary> /// <param name="departmentUser"></param> /// <param name="actdef"></param> /// <param name="prodef"></param> /*public static void AddUserToXML(DepartmentUser departmentUser,Department department, Actdef actdef, Prodef prodef) * { * String path = CreateActionCommon.GetXmlPath(prodef.Key); * XmlNode nodeActdef = null; * XmlDocument doc = GetActdefNode(actdef, prodef, out nodeActdef, path); * * * XmlNode nodeUser = nodeActdef.SelectSingleNode("user"); * if (nodeUser == null) * { * nodeUser = doc.CreateElement("user") as XmlNode; * nodeActdef.AppendChild(nodeUser); * } * * XmlElement elementUser = nodeUser as XmlElement; * elementUser.SetAttribute("ID", departmentUser.Id); * elementUser.SetAttribute("Name", departmentUser.Name); * elementUser.SetAttribute("ParentID", department.Id); * nodeActdef.AppendChild(elementUser); * * doc.Save(path); * * }*/ /// <summary> /// 添加操作元素 /// </summary> public static void AddElementToXML(String iframeId, LocationElementEntity locationElement, String prodefKey, String actdefId, DataGridView dgv, String childProdefId) { String path = CreateActionCommon.GetXmlPath(prodefKey, childProdefId); XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNode nodeIframeChild = doc.SelectSingleNode("//Actdef[@ID='" + actdefId + "']/iframe/iframeChild[@ID='" + iframeId + "']"); if (nodeIframeChild == null) { throw new Exception("请先选择要操作的Iframe"); } XmlNode nodeElement = nodeIframeChild.SelectSingleNode("LocationElement[@ID='" + locationElement.Id + "']"); if (nodeElement == null) { nodeElement = doc.CreateElement("LocationElement"); nodeIframeChild.AppendChild(nodeElement); } XmlElement elementLocation = nodeElement as XmlElement; elementLocation.SetAttribute("ID", locationElement.Id); elementLocation.SetAttribute("LocationType", locationElement.LocationType); //定位方式 elementLocation.SetAttribute("Path", locationElement.LocationPath); //定位路径 elementLocation.SetAttribute("OperateType", locationElement.OperateType); //操作类型 elementLocation.SetAttribute("Order", locationElement.Order); //顺序 elementLocation.SetAttribute("DefaultValue", locationElement.LocationDefaultValue); if (!string.IsNullOrEmpty(locationElement.SqlSchemaId)) { elementLocation.SetAttribute("SqlSchemaId", locationElement.SqlSchemaId); //SQL方案内码 } else { elementLocation.SetAttribute("SqlSchemaId", ""); //SQL方案内码 } elementLocation.SetAttribute("Introduce", locationElement.Introduce); //备注说明 elementLocation.SetAttribute("IsRandom", locationElement.IsRanddom.ToString()); elementLocation.SetAttribute("WaitSecond", locationElement.WaitSecond.ToString()); //操作等待时间 List <XmlNode> listAllNode = nodeIframeChild.SelectNodes("LocationElement").ToList <XmlNode>(); listAllNode = listAllNode.OrderBy(p => TypeConvert.ToConvert <object, long>(p.Attributes["Order"].Value, false)).ToList(); foreach (XmlNode nodeDelete in nodeIframeChild.ChildNodes) { nodeDelete.ParentNode.RemoveChild(nodeDelete); } foreach (XmlNode nodeTemp in listAllNode) { nodeIframeChild.AppendChild(nodeTemp); } doc.Save(path); ReadLocationElement(doc, iframeId, actdefId, locationElement.Id, dgv); }
private void btnChildSave_Click(object sender, EventArgs e) { try { //selectIframe = "1c8dd507-0790-4338-9173-0fe90c3df281"; //childElementId = "6ca7a031-b933-4af3-8360-a1e48539bb7e"; //prodefId = "pid-ccce3e0a-89e2-453b-a271-1a9f376f8a9b"; if (cmbChildLoactionType.SelectedValue == null || cmbChildLoactionType.Text == "") { MessageBox.Show("请选择定位方式", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtChildLacationPath.Text == "") { MessageBox.Show("请输入定位路径", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cmbChildOperateType.SelectedValue == null || cmbChildOperateType.Text == "") { MessageBox.Show("请选择操作方式", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtChildLocationOrder.Text.Trim() == "") { MessageBox.Show("请输入操作顺序", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtChildLocationIntroduce.Text.Trim() == "") { MessageBox.Show("请输入操作说明", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cmbChildOperateType.SelectedValue.ToString().Equals("SENDKEYS") || cmbChildOperateType.SelectedValue.ToString().Equals("FR") || cmbChildOperateType.SelectedValue.ToString().Equals("CIRCLESENDKEYS")) { if (txtChildLocationDefaultValue.Text == "") { MessageBox.Show("请输入操作默认值", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else if (cmbChildOperateType.SelectedValue.ToString().Equals("QT")) { if (txtChildLocationDefaultValue.Text == "") { MessageBox.Show("请输入操作默认值", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } List <DataGridViewRow> dataGridViewRows = dgvChildElement.Rows.ToList <DataGridViewRow>(); DataGridViewRow rowSelcet = dataGridViewRows.Where(o => o.Cells["ChildOrder"].Value.ToString().Equals(txtChildLocationOrder.Text)) .FirstOrDefault(); if (rowSelcet != null) { if (!rowSelcet.Cells["ChildLocationID"].Value.ToString().Equals(lblChildLocationID.Text)) { if ( MessageBox.Show("当前操作顺序已存在,是否插入添加?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { dataGridViewRows.ForEach(p => { int order = TypeConvert.ToConvert <object, int>(p.Cells["ChildOrder"].Value, false); if (order >= TypeConvert.ToConvert <object, int>(txtChildLocationOrder.Text)) { p.Cells["ChildOrder"].Value = order + 1; } }); CreateActionUtil.UpdateChildElementOrder(dataGridViewRows, prodefId, childProdefId, actdefId, _selectIframeId, locationElementId); } else { return; } } } if (lblChildLocationID.Text == "") { lblChildLocationID.Text = Guid.NewGuid().ToString(); } LocationElementEntity element = new LocationElementEntity(); element.Id = lblChildLocationID.Text; element.LocationType = cmbChildLoactionType.SelectedValue.ToString(); element.LocationPath = txtChildLacationPath.Text; element.OperateType = cmbChildOperateType.SelectedValue.ToString(); element.LocationDefaultValue = txtChildLocationDefaultValue.Text; if (txtChildLocationDefaultValue.Tag != null) { element.SqlSchemaId = txtChildLocationDefaultValue.Tag.ToString(); } element.Order = txtChildLocationOrder.Text; element.Introduce = txtChildLocationIntroduce.Text; element.IsRanddom = chkChildLocationRandom.Checked; element.WaitSecond = (String.IsNullOrEmpty(txtChildOperateTime.Text)) ? 0 : Convert.ToInt32(txtChildOperateTime.Text); CreateActionUtil.AddChildElementToXML(_selectIframeId, locationElementId, element, prodefId, actdefId, dgvChildElement, childProdefId); } catch (Exception er) { MessageBox.Show(er.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }