private void btnAdd_Click(object sender, EventArgs e) { txtDeliveryDate.Format = DateTimePickerFormat.Custom; txtDeliveryDate.CustomFormat = "yyyy/MM/dd"; SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Spris;Persist Security Inf" + "o=True;User ID=sa;Password=99437510"); String SQLStringSearch = "SELECT * FROM Product WHERE (ProductName = '" + txtProductName.Text.ToString() + "') AND (CreateDate = '" + txtCreateDate.Text.ToString() + "') AND (ExpiryDate = '" + txtExpiryDate.Text.ToString() + "') AND (WareHouseName = '" + txtWarehouseName.Text.ToString() + "')"; SqlCommand cmdSearch = new SqlCommand(SQLStringSearch, conn); String SQLStringAdd = "INSERT INTO Product " + " (ProductName, Unit, Type, CreateDate, ExpiryDate, DeliveryDate, WarehouseName, Stock) " + "VALUES " + " ('" + txtProductName.Text + "', " + "'" + txtUnit.Text + "', " + "'" + txtType.Text + "', " + "'" + txtCreateDate.Text + "', " + "'" + txtExpiryDate.Text + "', " + "'" + txtDeliveryDate.Text.ToString() + "', " + "'" + txtWarehouseName.Text + "', " + "'" + txtStock.Text + "') "; SqlCommand cmdAdd = new SqlCommand(SQLStringAdd, conn); try { conn.Open(); if (txtType.Text.ToString() != "") { String SQLTypeSearch = "SELECT * FROM Type WHERE TypeName ='" + txtType.Text.ToString() + "'"; SqlCommand TypeSearch = new SqlCommand(SQLTypeSearch, conn); SqlDataAdapter d = new SqlDataAdapter(TypeSearch); DataTable dt = new DataTable(); d.Fill(dt); if (dt.Rows.Count > 0) { } else { String SQLTypeInsert = "INSERT INTO Type (TypeName) VALUES ('" + txtType.Text.ToString() + "') "; SqlCommand TypeInsert = new SqlCommand(SQLTypeInsert, conn); TypeInsert.ExecuteNonQuery(); } } try { int iCountAdd, iCountUpdate; //執行SQL指令 SqlDataReader SearchReader; SearchReader = cmdSearch.ExecuteReader(); if (SearchReader.Read()) { int stock = Int32.Parse(txtStock.Text.ToString()); int news = Int32.Parse(SearchReader["Stock"].ToString()); stock = stock + news; txtStock.Text = stock.ToString(); SearchReader.Close(); String SQLStringUpdate = "UPDATE Product SET Stock = '" + txtStock.Text.ToString() + "' WHERE (ProductName = '" + txtProductName.Text.ToString() + "') AND (CreateDate = '" + txtCreateDate.Text.ToString() + "') AND (ExpiryDate = '" + txtExpiryDate.Text.ToString() + "')"; SqlCommand cmdUpdate = new SqlCommand(SQLStringUpdate, conn); iCountUpdate = cmdUpdate.ExecuteNonQuery(); MessageBox.Show(txtProductName.Text.ToString() + "物品已存在,物品數量更新成功!\r\n\r\n目前物品總數共" + txtStock.Text.ToString()); } else { SearchReader.Close(); int stock = Int32.Parse(txtStock.Text.ToString()); if (stock == 0) { MessageBox.Show("物品數量不得為0"); } else { //執行SQL指令 iCountAdd = cmdAdd.ExecuteNonQuery(); MessageBox.Show("新增記錄成功!\r\n\r\n共" + iCountAdd.ToString() + "筆記錄"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } finally { //關閉SqlConnection物件 conn.Close(); } }
/** * Updates to run on a lucene IndexReader: * mark any current page record deleted. */ public void ApplyReads(SearchReader state) { state.DeleteArticle(_article); }
protected override void DoStuff() { if (uri.AbsolutePath == "/robots.txt") { RobotsTxt(); return; } if (uri.AbsolutePath == "/stats") { ShowStats(); return; } string[] paths = uri.AbsolutePath.Split(new char[] { '/' }, 4); if (paths.Length != 4) { SendError(404, "Not found", "Not a recognized search path."); log.Warn("Unknown request " + uri.AbsolutePath); return; } what = paths[1]; dbname = paths[2]; searchterm = HttpUtility.UrlDecode(paths[3], Encoding.UTF8); log.InfoFormat("query:{0} what:{1} dbname:{2} term:{3}", rawUri, what, dbname, searchterm); IDictionary query = new QueryStringMap(uri); state = SearchPool.ForWiki(dbname); contentType = "text/plain"; if (what.Equals("titlematch")) { DoTitleMatches(); } else if (what.Equals("titleprefix")) { DoTitlePrefix(); } else if (what.Equals("search")) { int startAt = 0, endAt = 100; if (query.Contains("offset")) { startAt = Math.Max(Int32.Parse((string)query["offset"]), 0); } if (query.Contains("limit")) { endAt = Math.Min(Int32.Parse((string)query["limit"]), maxlines); } NamespaceFilter namespaces = new NamespaceFilter((string)query["namespaces"]); DoNormalSearch(startAt, endAt, namespaces); } else if (what.Equals("quit")) { // TEMP HACK for profiling System.Environment.Exit(0); } else if (what.Equals("raw")) { DoRawSearch(); } else { SendError(404, "Not Found", "Unrecognized search type. Try one of: " + "titlematch, titleprefix, search, quit, raw."); log.Warn("Unknown request type [" + what + "]; ignoring."); } }