private static void LoadFarmTran() { var nodeList = new List <FarmTran>(); XDocument docNew = XDocument.Load(@"C:\Users\user\Downloads\XMLanalysis-master\XMLanalysis-master\FarmTransData.xml"); //Console.WriteLine(docNew.ToString()); IEnumerable <XElement> nodes = docNew.Element("DocumentElement").Elements("row"); nodeList = nodes .Select(node => { var item = new FarmTran(); item.transactionDate = getValue(node, "交易日期"); item.cropCode = getValue(node, "作物代號"); item.cropName = getValue(node, "作物名稱"); item.marketCode = getValue(node, "市場代號"); item.marketName = getValue(node, "市場名稱"); item.priceHigh = getValue(node, "上價"); item.priceMid = getValue(node, "中價"); item.priceLow = getValue(node, "下價"); item.priceAvg = getValue(node, "平均價"); item.transactionNum = getValue(node, "交易量"); return(item); }).ToList(); FarmTranTable mFarm = new FarmTranTable(); nodeList.ForEach(item => { mFarm.InsertData(item); }); Console.ReadKey(); }
public ActionResult Edit(int Id, FarmTran input) { var model = db.FarmTrans.Find(Id); model.marketCode = input.marketCode; model.marketName = input.marketName; model.priceAvg = input.priceAvg; model.priceHigh = input.priceHigh; model.priceMid = input.priceMid; model.priceLow = input.priceLow; db.SaveChanges(); return(RedirectToAction("Index")); }
static void Main(string[] args) { var nodeList = new List <FarmTran>(); XDocument docNew = XDocument.Load("/C#/XMLanalysis/FarmTransData.xml"); //Console.WriteLine(docNew.ToString()); IEnumerable <XElement> nodes = docNew.Element("DocumentElement").Elements("row"); nodeList = nodes .Select(node => { var item = new FarmTran(); item.transactionDate = getValue(node, "交易日期"); item.cropCode = getValue(node, "作物代號"); item.cropName = getValue(node, "作物名稱"); item.marketCode = getValue(node, "市場代號"); item.marketName = getValue(node, "市場名稱"); item.priceHigh = getValue(node, "上價"); item.priceMid = getValue(node, "中價"); item.priceLow = getValue(node, "下價"); item.priceAvg = getValue(node, "平均價"); item.transactionNum = getValue(node, "交易量"); return(item); }).ToList(); Display(nodeList); /* * var nodeList = new List<FarmTran>(); * * var xml = XElement.Load("/C#/XMLanalysis/FarmTransData.xml"); * var nodes = xml.Descendants("row").ToList(); * nodeList = nodes * .Where(x =>x.IsEmpty)//.Where(x => !x.IsEmpty) * .ToList().Select(node => { * var item = new FarmTran(); * item.transactionDate = getValue(node, "交易日期"); * item.cropCode = getValue(node, "作物代號"); * item.cropName = getValue(node, "作物名稱"); * item.marketCode = getValue(node, "市場代號"); * item.marketName = getValue(node, "市場名稱"); * item.priceHigh = getValue(node, "上價"); * item.priceMid = getValue(node, "中價"); * item.priceLow = getValue(node, "下價"); * item.priceAvg = getValue(node, "平均價"); * item.transactionNum = getValue(node, "交易量"); * return item; * }).ToList(); * */ Console.ReadKey(); }
public void InsertData(FarmTran item) { count += 1; connection.Open(); SqlCommand cmd = connection.CreateCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = string.Format($"insert into Farmtran (Id,交易日期,作物代號,作物名稱,市場代號,市場名稱,上價,中價,下價,平均價,交易量) " + $"values ('{count}','{item.transactionDate}','{item.cropCode}',N'{item.cropName}','{item.marketCode}',N'{item.marketName}','{item.priceHigh}','{item.priceMid}','{item.priceLow}','{item.priceAvg}','{item.transactionNum}')"); cmd.ExecuteNonQuery(); connection.Close(); }
internal void InsertData(FarmTran item) { count += 1; SqlConnection connection = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=mDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"); connection.Open(); SqlCommand cmd = connection.CreateCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = string.Format($"insert into Farmtran (Id,交易日期,作物代號,作物名稱,市場代號,市場名稱,上價,中價,下價,平均價,交易量) " + $"values ('{count}','{item.transactionDate}','{item.cropCode}',N'{item.cropName}','{item.marketCode}',N'{item.marketName}','{item.priceHigh}','{item.priceMid}','{item.priceLow}','{item.priceAvg}','{item.transactionNum}')"); cmd.ExecuteNonQuery(); connection.Close(); }
static void Main(string[] args) { //-------------------------------------------------------------ShengYaoo MGenericsDB <FarmTran> mFarm = new FarmTranTable(); /* * var nodeList = mFarm.Xml_Load(); * nodeList.ForEach(item => * { * mFarm.InsertData(item); * });*/ mFarm.ShowData(mFarm.QueryData("作物名稱", "椰子")); var farm = new FarmTran(); farm.transactionDate = "107.4.13"; mFarm.UpdateData(1, farm); mFarm.ShowData(mFarm.QueryData("交易日期", "107.4.13")); Console.ReadKey(); Console.Clear(); mFarm.DeleteData("交易日期", "107.4.13"); mFarm.ShowData(mFarm.QueryData("交易日期", "107.4.13")); Console.ReadKey(); //-------------------------------------------------------------YuSyuan1208 MGenericsDB <Pharmacy_03> mPharmacy_03 = new PharmacyTable_03(); /*var nodeList = mPharmacy_03.Xml_Load(); * nodeList.ForEach(item => * { * PharmacyTable_03 SqlData; * SqlData = new PharmacyTable_03(); * SqlData.InsertData(item); * });*/ mPharmacy_03.ShowData(mPharmacy_03.QueryData("機構名稱", "和平藥局")); var nPharmacy_03 = new Pharmacy_03(); nPharmacy_03.機構名稱 = "機構名稱"; nPharmacy_03.機構狀態 = "機構狀態"; nPharmacy_03.地址 = "地址"; nPharmacy_03.電話 = "電話"; mPharmacy_03.UpdateData(1, nPharmacy_03); mPharmacy_03.DeleteData("機構名稱", "機構名稱"); Console.ReadKey(); //-------------------------------------------------------------JustSoGreat MGenericsDB <PharmaceuticalFactory> mPF = new PharmaTable(); var nodeList = mPF.Xml_Load(); //nodeList.ForEach(item => //{ // mPF.InsertData(item); //}); //mPF.ShowData(mPF.QueryData("類別", "西藥製劑廠")); var pf = new PharmaceuticalFactory(); pf.type = "test藥廠"; pf.name = "高應藥廠"; mPF.UpdateData(227, pf); Console.WriteLine("UPDATE ID:227,類別:test藥廠,名稱:高應藥廠"); mPF.DeleteData("ID", "1"); Console.WriteLine("Delete ID:1"); Console.ReadKey(); //-------------------------------------------------------------husano896 MGenericsDB <桃園公共自行車即時服務資料> mPark = new ParkingDB(); var nodeList2 = mPark.Xml_Load(); var testitem = new 桃園公共自行車即時服務資料(); testitem.parkName = @"測試停車場"; mPark.InsertData(testitem); Console.ReadKey(); }