protected void rgCountries_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { DayCareBAL.CountryService proxyCountry = new DayCareBAL.CountryService(); rgCountries.DataSource = proxyCountry.LoadCountries(); }
protected void Page_Load(object sender, EventArgs e) { // List<countries> lstCountry = new List<countries>(); //XmlSerializer serializer = new XmlSerializer(typeof(List<countries>)); // serializer = new XmlSerializer(typeof(List<countries>)); // TextReader textReader = new StreamReader(Server.MapPath("XML/country_state.xml")); //lstCountry = (List<countries>)serializer.Deserialize(textReader); //textReader.Close(); #region Add State to DB //XmlDocument xDoc = new XmlDocument(); //xDoc.Load(Server.MapPath("XML/country_state.xml")); //XmlNodeList lst = xDoc.GetElementsByTagName("country"); //SqlConnection cn = new System.Data.SqlClient.SqlConnection("Data Source=192.168.1.100;Initial Catalog=DayCare;Persist Security Info=True;User ID=sa;Password=password;Integrated Security=False"); //cn.Open(); //SqlDataReader dr; //SqlCommand cmCountry = new SqlCommand(); //SqlCommand cmState = new SqlCommand(); //Guid id = new Guid(); //Guid CountryId = new Guid(); //Guid StateId = new Guid(); //int cnt = 0, country = 0; //StringBuilder sbCountryNotAvailable = new StringBuilder(); //foreach (XmlNode xmlNode in lst) //{ // CountryId = Guid.NewGuid(); // cmCountry.CommandText = "insert into Country (Id,Name) values('" + CountryId + "','" + xmlNode.Attributes[0].Value.ToUpper() + "')"; // cmCountry.Connection = cn; // cmCountry.CommandType = System.Data.CommandType.Text; // cmCountry.ExecuteNonQuery(); // //cmCountry.CommandText = "select * from Country where Name='" + xmlNode.Attributes[0].Value.ToUpper() + "'"; // //cmCountry.Connection = cn; // //cmCountry.CommandType = System.Data.CommandType.Text; // //dr = cmCountry.ExecuteReader(); // //id = new Guid(); // //if (dr.Read()) // //{ // // id = new Guid(dr["Id"].ToString()); // //} // //dr.Close(); // //if (!id.ToString().Equals("00000000-0000-0000-0000-000000000000")) // //{ // if (xmlNode.HasChildNodes) // { // foreach (XmlNode xln in xmlNode.ChildNodes) // { // StateId = Guid.NewGuid(); // string StateName = xln.InnerText; // //cmState.CommandText = "insert into State(Id,Name,CountryId) values('" + StateId + "','" + StateName + "','" + id + "')"; // cmState.CommandText = "insert into State(Id,Name,CountryId) values('" + StateId + "','" + StateName + "','" + CountryId + "')"; // cmState.CommandType = System.Data.CommandType.Text; // cmState.Connection = cn; // cmState.ExecuteNonQuery(); // cnt++; // } // } // //} // //else // //{ // // country++; // // sbCountryNotAvailable.Append(country + "." + xmlNode.Attributes[0].Value.ToUpper() + "\n\n"); // //} //} //StreamWriter sw = new StreamWriter("D:\\Country.xls"); //sw.Write(sbCountryNotAvailable.ToString()); //sw.Dispose(); sw.Close(); #endregion #region "DataSet to XML" //DataSet ds = new DataSet(); //SqlConnection cn = new System.Data.SqlClient.SqlConnection("Data Source=192.168.1.100;Initial Catalog=DayCare;Persist Security Info=True;User ID=sa;Password=password;Integrated Security=False"); //cn.Open(); //SqlDataAdapter da=new SqlDataAdapter("select Id,Name from Country order by name",cn); //da.Fill(ds,"Country"); //ds.Tables["Country"].WriteXml("D://CountryList.xml"); //da = new SqlDataAdapter("select Id,Name,CountryId from State order by countryId", cn); //da.Fill(ds, "State"); //ds.Tables["State"].WriteXml("D://StateList.xml"); //cn.Close(); #endregion if (!IsPostBack) { Common.BindCountryDropDown(ddlCountry); } XmlDocument x = new XmlDocument(); DayCareBAL.CountryService proxyCountry = new DayCareBAL.CountryService(); DayCarePL.CountryProperties objCountry = new DayCarePL.CountryProperties(); objCountry.Name = "Test"; //if (proxyCountry.Save(objCountry)) //{ //} List <DayCarePL.CountryProperties> lst = proxyCountry.LoadCountries(); }
public bool SubmitRecord(object source, GridCommandEventArgs e) { bool result = false; try { DayCareBAL.CountryService proxyCountry = new DayCareBAL.CountryService(); DayCarePL.CountryProperties objCountry = new DayCarePL.CountryProperties(); Telerik.Web.UI.GridDataItem item = (Telerik.Web.UI.GridDataItem)e.Item; var InsertItem = e.Item as Telerik.Web.UI.GridEditableItem; Telerik.Web.UI.GridEditManager editMan = InsertItem.EditManager; if (InsertItem != null) { foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns) { if (column is IGridEditableColumn) { IGridEditableColumn editableCol = (column as IGridEditableColumn); if (editableCol.IsEditable) { IGridColumnEditor editor = editMan.GetColumnEditor(editableCol); switch (column.UniqueName) { case "Name": { objCountry.Name = (editor as GridTextColumnEditor).Text.Trim().ToString(); ViewState["Name"] = objCountry.Name; break; } } } } } if (e.CommandName != "PerformInsert") { objCountry.Id = new Guid(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"].ToString()); if (!objCountry.Name.Trim().Equals(hdnName.Value.Trim())) { bool ans = Common.CheckDuplicate("Country", "Name", objCountry.Name, "update", objCountry.Id.ToString()); if (ans) { MasterAjaxManager = this.Page.Master.FindControl("RadAjaxManager1") as Telerik.Web.UI.RadAjaxManager; MasterAjaxManager.ResponseScripts.Add(string.Format("ShowMessage('{0}','{1}')", "Already Exist", "false")); return(false); } } } else { bool ans = Common.CheckDuplicate("Country", "Name", objCountry.Name, "insert", ""); if (ans) { MasterAjaxManager = this.Page.Master.FindControl("RadAjaxManager1") as Telerik.Web.UI.RadAjaxManager; MasterAjaxManager.ResponseScripts.Add(string.Format("ShowMessage('{0}','{1}')", "Already Exist", "false")); return(false); } } hdnName.Value = ""; result = proxyCountry.Save(objCountry); if (result) { MasterAjaxManager = this.Page.Master.FindControl("RadAjaxManager1") as Telerik.Web.UI.RadAjaxManager; MasterAjaxManager.ResponseScripts.Add(string.Format("ShowMessage('{0}','{1}')", "Saved Successfully", "false")); } } } catch (Exception ex) { DayCarePL.Logger.Write(DayCarePL.LogType.EXCEPTION, DayCarePL.ModuleToLog.Country, "SubmitRecord", ex.Message.ToString(), DayCarePL.Common.GUID_DEFAULT); result = false; } return(result); }