protected void DeletePacket(Object sender, EventArgs e) { int packetId; if (int.TryParse(ddlPacketName.SelectedValue, out packetId)) { PatientEdPacket packet = new PatientEdPacket(); packet.Delete(packetId); // refresh page this.LoadPacketDDL(); this.Page_Load(sender, e); } }
/// <summary> /// Save the packet; packet requires a disease, visit type and packet name /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SaveDefaultDocument(object sender, ImageClickEventArgs e) { PatientEducationDa da = new PatientEducationDa(); int dId = 0; //= this.ddlDiseaseType.SelectedValue; int vId = 0; //= this.ddlVisitType.SelectedValue; int pId = 0; //= this.ddlPacketName.SelectedValue; if (!String.IsNullOrEmpty(this.ddlDiseaseType.SelectedValue) && !String.IsNullOrEmpty(this.ddlVisitType.SelectedValue)) { dId = Int32.Parse(this.ddlDiseaseType.SelectedValue); vId = Int32.Parse(this.ddlVisitType.SelectedValue); } if (this.ddlPacketName.SelectedValue.Equals(ADDNEW) && !string.IsNullOrEmpty(this.txtPacketName.Value)) { // adding new; insert packet name and get new primary key for insertion into disease_visits_packets table string newPacketName = txtPacketName.Value; PatientEdPacket packet = new PatientEdPacket(); packet[PatientEdPacket.PacketName] = newPacketName; packet.Save(); pId = int.Parse(packet[PatientEdPacket.PacketId].ToString()); // new packet name was used so refresh the drop down list, select the recent addition, and make the delete button available ListItem li = new ListItem(newPacketName, pId.ToString()); ddlPacketName.Items.Insert(1, li); ddlPacketName.SelectedIndex = 1; txtPacketName.Value = ""; txtPacketName.Visible = false; BtnDeletePacket.Visible = true; } else if (!string.IsNullOrEmpty(this.ddlPacketName.SelectedValue)) { pId = int.Parse(this.ddlPacketName.SelectedValue); } if (pId > 0 && dId > 0 && vId > 0) // update or insert default doc { List <string> checkedPartsList = new List <string>(); foreach (TreeNode sectionNode in contentTV.Nodes) { foreach (TreeNode topicNode in sectionNode.ChildNodes) { foreach (TreeNode subTopicNode in topicNode.ChildNodes) { if (subTopicNode.Checked) { checkedPartsList.Add(subTopicNode.Value); } } } } PatientEdDisease_VisitType_SubTopic biz = new PatientEdDisease_VisitType_SubTopic(); DataTable defaultDocPartsDt = da.GetDefaultDocumentByDiseaseVisitPacketIds(dId, vId, pId); // start by deleting nodes that may have been removed foreach (DataRow dr in defaultDocPartsDt.Rows) { string drId = dr[PatientEdDisease_VisitType_SubTopic.DiseaseVisitTypeSubTopicId].ToString(); string stId = dr[PatientEdDisease_VisitType_SubTopic.SubTopicId].ToString(); if (!checkedPartsList.Contains(stId)) { //delete this record biz.Get(Int32.Parse(drId)); biz.Delete(); } else { //remove it from the list of checked parts, as we have confirmed it is already in the db checkedPartsList.Remove(stId); } } //save the new additions foreach (string defaultDocpart in checkedPartsList) { //add new profile doc parts to the db PatientEdDisease_VisitType_SubTopic bizObj = new PatientEdDisease_VisitType_SubTopic(); bizObj[PatientEdDisease_VisitType_SubTopic.SubTopicId] = Int32.Parse(defaultDocpart); bizObj[PatientEdDisease_VisitType_SubTopic.VisitTypeId] = vId.ToString(); bizObj[PatientEdDisease_VisitType_SubTopic.DiseaseId] = dId.ToString(); bizObj[PatientEdDisease_VisitType_SubTopic.PacketId] = pId.ToString(); bizObj.Save(); } GetRootNodes(); this._callbackType.Value = String.Empty; } }