public BLAutot Get(string aid) { try { if (File.Exists(strFileName)) { BLAutot objAuto = new BLAutot(); XPathDocument doc = new XPathDocument(strFileName); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator iterator; iterator = nav.Select("//Auto[aid='" + aid + "']"); while (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); objAuto.aid = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("aid").InnerXml); objAuto.rekkari = nav2.Select("//Auto").Current.SelectSingleNode("rekkari").InnerXml; objAuto.merkki = nav2.Select("//Auto").Current.SelectSingleNode("merkki").InnerXml; objAuto.malli = nav2.Select("//Auto").Current.SelectSingleNode("malli").InnerXml; objAuto.vm = Convert.ToInt32(nav2.Select("//Auto").Current.SelectSingleNode("vm").InnerXml); objAuto.myyntiHinta = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("myyntiHinta").InnerXml); objAuto.sisaanOstoHinta = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("sisaanOstoHinta").InnerXml); } return(objAuto); } } catch (Exception ex) { throw ex; } return(null); }
protected void btnAddNew_Click(object sender, EventArgs e) { autoLista.Add(new Auto()); autoLista = BLAutot.SortList(autoLista, "Malli", "ASC"); gvAutot.EditIndex = 0; toGridView(autoLista); }
protected void initMyStuff() { autoLista = BLAutot.HaeAutot(); toGridView(autoLista); if (Session["UserAuthentication"] != null) { btnSave.Visible = true; btnAddNew.Visible = true; LoginWindow.Visible = false; btnLogout.Visible = true; gvAutot.AutoGenerateEditButton = true; gvAutot.AutoGenerateDeleteButton = true; } else { Session["UserAuthentication"] = null; lblInfo.Text = null; btnSave.Visible = false; btnAddNew.Visible = false; LoginWindow.Visible = true; btnLogout.Visible = false; gvAutot.AutoGenerateEditButton = false; gvAutot.AutoGenerateDeleteButton = false; } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (!Page.IsValid) return; BLAutot auto = new BLAutot(); auto.rekkari = txtrekkari.Text; auto.merkki = txtmerkki.Text; auto.malli = txtmalli.Text; auto.vm = Convert.ToInt32(txtvm.Text); auto.myyntiHinta = Convert.ToInt64(txtmyyntiHinta.Text); auto.sisaanOstoHinta = Convert.ToInt64(txtsisaanOstoHinta.Text); auto.aid = Convert.ToInt64(hndId.Value); AutotDAL objAutoDAL = new AutotDAL(); if ((hndId.Value.Trim().Length > 0) && (Convert.ToInt64(hndId.Value) > 0)) objAutoDAL.Update(auto); else objAutoDAL.Create(auto); ClearScreen(); BindGrid(); lblMessage.Text = "Record saved successfully"; } catch (Exception ex) { lblMessage.Text = "There is an error occured while processing the request. Please verify the code!"; } }
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) { GridViewSortExpression = e.SortExpression; autoLista = BLAutot.jarjestaLista(autoLista, GridViewSortExpression, GetSortDirection()); contentToGridView(autoLista); }
protected void Page_Load(object sender, EventArgs e) { BLAutot blogic = new BLAutot(MapPath("~/App_Data/WanhatAutot.xml")); carList.DataSource = blogic.getAllCars(); carList.DataBind(); }
protected void Page_Init(Object sender, EventArgs e) { blogic = new BLAutot(MapPath("~/App_Data/WanhatAutot.xml")); edit = Request.QueryString["id"] != null ? true : false; if (edit) { int id = int.Parse(Request.QueryString["id"]); header.Text = "Muokkaa auton tietoja"; auto = blogic.getCar(id); tbId.Text = auto.ID.ToString(); tbMerkki.Text = auto.Merkki; tbMalli.Text = auto.Malli; tbVuosiMalli.Text = auto.VuosiMalli.ToString(); tbMyyntiHinta.Text = auto.MyyntiHinta.ToString(); tbSisaanOstoHinta.Text = auto.SisaanOstoHinta.ToString(); tbRekkari.Text = auto.Rekkari; tbId.Enabled = false; } else { btnDelete.Visible = false; header.Text = "Lisää uusi auto"; auto = new Auto(); } }
protected void btn1_Click(object sender, EventArgs e) { string filename = MapPath("~/App_Data/WanhatAutott.xml"); grid.DataSource = BLAutot.GetCars(filename); grid.DataBind(); }
protected void BindGridView() { string filename = MapPath("~/App_Data/WanhatAutott.xml"); grid.DataSource = BLAutot.GetCars(filename); grid.DataBind(); }
/// <summary> /// This method is used for creating a new employee information in XML file /// </summary> /// <param name="employee">employee object</param> /// <returns>True - Success, False - Failure</returns> public bool Create(BLAutot auto) { try { // Checking if the file exist if (!File.Exists(strFileName)) { // If file does not exist in the database path, create and store an empty Autot node XmlTextWriter textWritter = new XmlTextWriter(strFileName, null); textWritter.WriteStartDocument(); textWritter.WriteStartElement("Wanhatautot"); textWritter.WriteEndElement(); textWritter.Close(); } // Create the XML document by loading the file XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(strFileName); // Creating Auto node XmlElement subNode = xmlDoc.CreateElement("Auto"); // Getting the maximum Id based on the XML data already stored string strId = CommonMethods.GetMaxValue(xmlDoc, "Wanhatautot" + "/" + "Auto" + "/" + "aid").ToString(); // Adding Id column. Auto generated column subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "aid", strId)); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "rekkari", auto.rekkari)); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "merkki", auto.merkki)); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "malli", auto.malli)); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "vm", auto.vm.ToString())); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "myyntiHinta", auto.myyntiHinta.ToString())); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "sisaanOstoHinta", auto.sisaanOstoHinta.ToString())); xmlDoc.DocumentElement.AppendChild(subNode); // Saving the file after adding the new auto node xmlDoc.Save(strFileName); return true; } catch (Exception ex) { throw ex; } }
/// <summary> /// This method is used for creating a new employee information in XML file /// </summary> /// <param name="employee">employee object</param> /// <returns>True - Success, False - Failure</returns> public bool Create(BLAutot auto) { try { // Checking if the file exist if (!File.Exists(strFileName)) { // If file does not exist in the database path, create and store an empty Autot node XmlTextWriter textWritter = new XmlTextWriter(strFileName, null); textWritter.WriteStartDocument(); textWritter.WriteStartElement("Wanhatautot"); textWritter.WriteEndElement(); textWritter.Close(); } // Create the XML document by loading the file XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(strFileName); // Creating Auto node XmlElement subNode = xmlDoc.CreateElement("Auto"); // Getting the maximum Id based on the XML data already stored string strId = CommonMethods.GetMaxValue(xmlDoc, "Wanhatautot" + "/" + "Auto" + "/" + "aid").ToString(); // Adding Id column. Auto generated column subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "aid", strId)); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "rekkari", auto.rekkari)); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "merkki", auto.merkki)); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "malli", auto.malli)); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "vm", auto.vm.ToString())); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "myyntiHinta", auto.myyntiHinta.ToString())); xmlDoc.DocumentElement.AppendChild(subNode); subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "sisaanOstoHinta", auto.sisaanOstoHinta.ToString())); xmlDoc.DocumentElement.AppendChild(subNode); // Saving the file after adding the new auto node xmlDoc.Save(strFileName); return(true); } catch (Exception ex) { throw ex; } }
protected void cvMyyntihinta_ServerValidate(object source, ServerValidateEventArgs args) { if (BLAutot.isValidHinta(args.Value)) { args.IsValid = true; } else { args.IsValid = false; } }
protected void cvVuosimalli_ServerValidate(object source, ServerValidateEventArgs args) { if (BLAutot.isValidVuosi(args.Value)) { args.IsValid = true; } else { args.IsValid = false; } }
protected void IniMyStuff() { autoLista = BLAutot.getAutot(); contentToGridView(autoLista); if ((String)Session["logged"] == "true") { log.Text = "Olet kirjautunut sisään."; btnLogin.Text = "Kirjaudu ulos"; } }
protected void cusCustom_ServerValidate(object source, ServerValidateEventArgs args) { if (BLAutot.isValidRekkari(args.Value)) { args.IsValid = true; } else { args.IsValid = false; } }
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { if (BLAutot.authenticateUser( BLAutot.regexString(Login1.UserName.ToString(), "userName"), BLAutot.regexString(Login1.Password.ToString(), "password"))) { e.Authenticated = true; } else { e.Authenticated = false; } }
protected void autoNakyma_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = autoNakyma.Rows[e.RowIndex]; autoLista[e.RowIndex].Merkki = BLAutot.regexString(((TextBox)(row.Cells[1].Controls[0])).Text, "Merkki"); autoLista[e.RowIndex].Aid = BLAutot.regexString((((TextBox)(row.Cells[2].Controls[0])).Text), "Aid"); autoLista[e.RowIndex].Rekkari = BLAutot.regexString((((TextBox)(row.Cells[3].Controls[0])).Text), "Rekkari"); autoLista[e.RowIndex].Malli = BLAutot.regexString((((TextBox)(row.Cells[4].Controls[0])).Text), "Malli"); autoLista[e.RowIndex].Vm = int.Parse(BLAutot.regexString((((TextBox)(row.Cells[5].Controls[0])).Text), "Vm")); autoLista[e.RowIndex].MyyntiHinta = int.Parse(BLAutot.regexString((((TextBox)(row.Cells[6].Controls[0])).Text), "MyyntiHinta")); autoLista[e.RowIndex].SOstoHinta = int.Parse(BLAutot.regexString((((TextBox)(row.Cells[6].Controls[0])).Text), "SOstoHinta")); autoNakyma.EditIndex = -1; toGridView(autoLista); }
protected void gvAutot_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = gvAutot.Rows[e.RowIndex]; Regex reg = new Regex(@"^[a-zA-Z'.\s]{7,7}$"); autoLista[e.RowIndex].Merkki = BLAutot.regexString(((TextBox)(row.Cells[1].Controls[0])).Text, "Merkki"); autoLista[e.RowIndex].Aid = BLAutot.regexString((((TextBox)(row.Cells[2].Controls[0])).Text), "Aid"); autoLista[e.RowIndex].Rekkari = BLAutot.regexString((((TextBox)(row.Cells[3].Controls[0])).Text), "Rekkari"); autoLista[e.RowIndex].Malli = BLAutot.regexString((((TextBox)(row.Cells[4].Controls[0])).Text), "Malli"); autoLista[e.RowIndex].Vm = int.Parse(BLAutot.regexString((((TextBox)(row.Cells[5].Controls[0])).Text), "Vm")); autoLista[e.RowIndex].MyyntiHinta = int.Parse(BLAutot.regexString((((TextBox)(row.Cells[6].Controls[0])).Text), "MyyntiHinta")); autoLista[e.RowIndex].OstoHinta = int.Parse(BLAutot.regexString((((TextBox)(row.Cells[6].Controls[0])).Text), "OstoHinta")); gvAutot.EditIndex = -1; toGridView(autoLista); }
protected void grdViewAuto_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { hndId.Value = grdViewAuto.Rows[e.NewSelectedIndex].Cells[2].Text.Trim(); if (hndId.Value.Length > 0) { AutotDAL objAutoDAL = new AutotDAL(); BLAutot auto = objAutoDAL.Get(hndId.Value); txtaid.Text = Convert.ToString(auto.aid); txtrekkari.Text = auto.rekkari; txtmerkki.Text = auto.merkki; txtmalli.Text = auto.malli; txtvm.Text = Convert.ToString(auto.vm); txtmyyntiHinta.Text = Convert.ToString(auto.myyntiHinta); txtsisaanOstoHinta.Text = Convert.ToString(auto.sisaanOstoHinta); lblMessage.Text = ""; } }
public IList <BLAutot> GetAll() { try { if (File.Exists(strFileName)) { // Loading the file into XPath document XPathDocument doc = new XPathDocument(strFileName); XPathNavigator nav = doc.CreateNavigator(); XPathExpression exp = nav.Compile("/Wanhatautot/Auto"); // Getting all autot // Sorting the records by aid exp.AddSort("aid", System.Xml.XPath.XmlSortOrder.Ascending, System.Xml.XPath.XmlCaseOrder.None, "", System.Xml.XPath.XmlDataType.Text); XPathNodeIterator iterator = nav.Select(exp); IList <BLAutot> objAutot = new List <BLAutot>(); while (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); BLAutot objAuto = new BLAutot(); objAuto.aid = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("aid").InnerXml); objAuto.rekkari = nav2.Select("//Auto").Current.SelectSingleNode("rekkari").InnerXml; objAuto.merkki = nav2.Select("//Auto").Current.SelectSingleNode("merkki").InnerXml; objAuto.malli = nav2.Select("//Auto").Current.SelectSingleNode("malli").InnerXml; objAuto.vm = Convert.ToInt32(nav2.Select("//Auto").Current.SelectSingleNode("vm").InnerXml); objAuto.myyntiHinta = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("myyntiHinta").InnerXml); objAuto.sisaanOstoHinta = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("sisaanOstoHinta").InnerXml); objAutot.Add(objAuto); } return(objAutot); } } catch (Exception ex) { throw ex; } return(null); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request["aid"] != null) { Session["aid"] = Request["aid"]; this.muokkaus = new BLAutot(Session["aid"].ToString()); this.muokkaus.populateTxtBoxes(txtMalli, txtMerkki, txtMyyntihinta, txtRekkari, txtSisaanostohinta, txtVm); } else { lblTesti.Text = "Pitaa tulla sivun H3100_Jinta-Rouppi.aspx kautta, että toimii"; } } if (IsPostBack) { this.muokkaus = new BLAutot(Session["aid"].ToString()); } }
public bool Update(BLAutot auto) { try { if (File.Exists(strFileName)) { XmlDocument objXmlDocument = new XmlDocument(); objXmlDocument.Load(strFileName); // Getting a particular Auto by selecting using Xpath query XmlNode node = objXmlDocument.SelectSingleNode("//Auto[aid='" + auto.aid + "']"); if (node != null) { // Assigning all the values node.SelectNodes("aid").Item(0).FirstChild.Value = auto.aid.ToString(); node.SelectNodes("rekkari").Item(0).FirstChild.Value = auto.rekkari; node.SelectNodes("malli").Item(0).FirstChild.Value = auto.malli; node.SelectNodes("merkki").Item(0).FirstChild.Value = auto.merkki; node.SelectNodes("vm").Item(0).FirstChild.Value = auto.vm.ToString(); node.SelectNodes("myyntiHinta").Item(0).FirstChild.Value = auto.myyntiHinta.ToString(); node.SelectNodes("sisaanOstoHinta").Item(0).FirstChild.Value = auto.sisaanOstoHinta.ToString(); } // Saving the file objXmlDocument.Save(strFileName); return(true); } else { Exception ex = new Exception("Database file does not exist in the folder"); throw ex; } } catch (Exception ex) { throw ex; } }
protected void btnUusiAuto_Click(object sender, EventArgs e) { if ((String)Session["logged"] == "true") { Regex rekkari = new Regex(@"^[A-Z]{3}-[0-9]{3}$"); if (rekkari.IsMatch(txtRekkari.Text)) { try { Auto a = new Auto(); a.Aid = txtAid.Text; a.Rekkari = txtRekkari.Text; a.Merkki = txtMerkki.Text; a.Malli = txtMalli.Text; a.Vm = int.Parse(txtVm.Text); a.MyyntiHinta = int.Parse(txtMyyntiHinta.Text); a.SisaanOstoHinta = int.Parse(txtSisaanOstoHinta.Text); autoLista.Add(a); autoLista = BLAutot.jarjestaLista(autoLista, "Malli", "ASC"); contentToGridView(autoLista); } catch (Exception) { } } } else { Response.Redirect("logon.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (!Page.IsValid) { return; } BLAutot auto = new BLAutot(); auto.rekkari = txtrekkari.Text; auto.merkki = txtmerkki.Text; auto.malli = txtmalli.Text; auto.vm = Convert.ToInt32(txtvm.Text); auto.myyntiHinta = Convert.ToInt64(txtmyyntiHinta.Text); auto.sisaanOstoHinta = Convert.ToInt64(txtsisaanOstoHinta.Text); auto.aid = Convert.ToInt64(hndId.Value); AutotDAL objAutoDAL = new AutotDAL(); if ((hndId.Value.Trim().Length > 0) && (Convert.ToInt64(hndId.Value) > 0)) { objAutoDAL.Update(auto); } else { objAutoDAL.Create(auto); } ClearScreen(); BindGrid(); lblMessage.Text = "Record saved successfully"; } catch (Exception ex) { lblMessage.Text = "There is an error occured while processing the request. Please verify the code!"; } }
public BLAutot Get(string aid) { try { if (File.Exists(strFileName)) { BLAutot objAuto = new BLAutot(); XPathDocument doc = new XPathDocument(strFileName); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator iterator; iterator = nav.Select("//Auto[aid='" + aid + "']"); while (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); objAuto.aid = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("aid").InnerXml); objAuto.rekkari = nav2.Select("//Auto").Current.SelectSingleNode("rekkari").InnerXml; objAuto.merkki = nav2.Select("//Auto").Current.SelectSingleNode("merkki").InnerXml; objAuto.malli = nav2.Select("//Auto").Current.SelectSingleNode("malli").InnerXml; objAuto.vm = Convert.ToInt32(nav2.Select("//Auto").Current.SelectSingleNode("vm").InnerXml); objAuto.myyntiHinta = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("myyntiHinta").InnerXml); objAuto.sisaanOstoHinta = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("sisaanOstoHinta").InnerXml); } return objAuto; } } catch (Exception ex) { throw ex; } return null; }
public IList<BLAutot> GetAll() { try { if (File.Exists(strFileName)) { // Loading the file into XPath document XPathDocument doc = new XPathDocument(strFileName); XPathNavigator nav = doc.CreateNavigator(); XPathExpression exp = nav.Compile("/Wanhatautot/Auto"); // Getting all autot // Sorting the records by aid exp.AddSort("aid", System.Xml.XPath.XmlSortOrder.Ascending, System.Xml.XPath.XmlCaseOrder.None, "", System.Xml.XPath.XmlDataType.Text); XPathNodeIterator iterator = nav.Select(exp); IList<BLAutot> objAutot = new List<BLAutot>(); while (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); BLAutot objAuto = new BLAutot(); objAuto.aid = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("aid").InnerXml); objAuto.rekkari = nav2.Select("//Auto").Current.SelectSingleNode("rekkari").InnerXml; objAuto.merkki = nav2.Select("//Auto").Current.SelectSingleNode("merkki").InnerXml; objAuto.malli = nav2.Select("//Auto").Current.SelectSingleNode("malli").InnerXml; objAuto.vm = Convert.ToInt32(nav2.Select("//Auto").Current.SelectSingleNode("vm").InnerXml); objAuto.myyntiHinta = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("myyntiHinta").InnerXml); objAuto.sisaanOstoHinta = Convert.ToInt64(nav2.Select("//Auto").Current.SelectSingleNode("sisaanOstoHinta").InnerXml); objAutot.Add(objAuto); } return objAutot; } } catch (Exception ex) { throw ex; } return null; }
public bool Update(BLAutot auto) { try { if (File.Exists(strFileName)) { XmlDocument objXmlDocument = new XmlDocument(); objXmlDocument.Load(strFileName); // Getting a particular Auto by selecting using Xpath query XmlNode node = objXmlDocument.SelectSingleNode("//Auto[aid='" + auto.aid + "']"); if (node != null) { // Assigning all the values node.SelectNodes("aid").Item(0).FirstChild.Value = auto.aid.ToString(); node.SelectNodes("rekkari").Item(0).FirstChild.Value = auto.rekkari; node.SelectNodes("malli").Item(0).FirstChild.Value = auto.malli; node.SelectNodes("merkki").Item(0).FirstChild.Value = auto.merkki; node.SelectNodes("vm").Item(0).FirstChild.Value = auto.vm.ToString(); node.SelectNodes("myyntiHinta").Item(0).FirstChild.Value = auto.myyntiHinta.ToString(); node.SelectNodes("sisaanOstoHinta").Item(0).FirstChild.Value = auto.sisaanOstoHinta.ToString(); } // Saving the file objXmlDocument.Save(strFileName); return true; } else { Exception ex = new Exception("Database file does not exist in the folder"); throw ex; } } catch (Exception ex) { throw ex; } }
protected void gvAutot_Sorting(object sender, GridViewSortEventArgs e) { GridViewSortExpression = e.SortExpression; toGridView(BLAutot.SortList(autoLista, GridViewSortExpression, GetSortDirection())); }
protected void btnSave_Click(object sender, EventArgs e) { BLAutot.VieAutot(autoLista); }