예제 #1
0
        public void CloseCommand()
        {
            try
            {
                oCommand.Cancel();
                oCommand.Dispose();
                oCommand = null;

                return;
            }
            catch
            {
                return;
            }
        }
예제 #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            OleDbCommand    cmd  = new OleDbCommand("Select * From employee  Where employee_id = ? and employee_pwd =?", conn);

            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("employee_id", this.txtId.Text);
            cmd.Parameters.AddWithValue("employee_pwd", this.txtPwd.Text);

            conn.Open();
            OleDbDataReader dr = cmd.ExecuteReader();

            //管理員登入
            if ((this.txtId.Text.Trim() == "admin" && this.txtPwd.Text == "123456"))
            {
                Session["admin_id"] = this.txtId.Text;
                Response.Redirect("aOrder_List.aspx");
            }
            //一般使用者登入
            else if (dr.Read())
            {
                Session["employee_no"]   = dr[0];
                Session["employee_name"] = dr[3];
                cmd.Cancel();
                dr.Close();
                conn.Close();
                conn.Dispose();
                Response.Redirect("uOrder_List.aspx");
            }
            else
            {
                this.lblRemind.Text = "帳號或密碼有誤,請重新輸入。";
                return;
            }
        }
예제 #3
0
        public void ProcessRequest(HttpContext context)
        {
            sOrder_no = context.Request.QueryString["order_no"];
            // 傳入的資料
            string order = context.Request["order"] ?? string.Empty;
            // 反序列化資料:將JSON格式轉換成物件
            List <Data> data = JsonConvert.DeserializeObject <List <Data> >(order);

            // 訂單資料存入資料庫
            string          sSql = @"Insert Into filledIn(order_no, employee_no, filledin_date, item_name, quantity, item_price, filledIn_remark) Values(?,?,?,?,?,?,?)";
            OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

            conn.Open();
            OleDbCommand cmd = new OleDbCommand(sSql, conn);

            for (int intA = 0; intA < data.Count; intA++)
            {
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("order_no", sOrder_no);
                cmd.Parameters.AddWithValue("employee_no", context.Session["employee_no"].ToString());
                cmd.Parameters.AddWithValue("filledin_date", DateTime.Now.ToString("yyyy/MM/dd HH:mm"));
                cmd.Parameters.AddWithValue("item_name", data[intA].Name);
                cmd.Parameters.AddWithValue("quantity", data[intA].Quantity);
                cmd.Parameters.AddWithValue("item_price", data[intA].Price);
                cmd.Parameters.AddWithValue("filledIn_remark", data[intA].Remark);
                cmd.ExecuteNonQuery();
            }

            cmd.Cancel();
            conn.Close();

            // 回傳資料並序列化成JSON
            context.Response.Write(JsonConvert.SerializeObject(data));
        }
예제 #4
0
        // 輸出訂單資料
        private void Inititle()
        {
            string sSql = "Select * From dessert_order A Left Join store B On A.store_no = B.store_no Where A.order_no = ?";

            OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            OleDbCommand    cmd  = new OleDbCommand(sSql, conn);

            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("order_no", sOrder_no);

            conn.Open();
            OleDbDataReader dr = cmd.ExecuteReader();

            dr.Read();
            if (dr.HasRows)
            {
                this.lblStoreName.Text   = dr["store_name"].ToString();
                this.lblPhone.Text       = dr["store_phone"].ToString();
                this.lblAddress.Text     = dr["store_address"].ToString();
                this.lblRemark.Text      = dr["store_remark"].ToString();
                this.txtStartDate.Text   = dr["start_date"].ToString();
                this.txtEndDate.Text     = dr["end_date"].ToString();
                this.txtOrderRemark.Text = dr["order_remark"].ToString();
            }
            else
            {
                Server.Transfer("~/ErrorPages/aOops.aspx");
            }

            cmd.Cancel();
            dr.Close();
        }
예제 #5
0
        public static string GetGameStoragePrice(string storageid)
        {
            string          price   = "";
            string          strPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\" + DBName + ".accdb";
            string          conStr  = "Provider=Microsoft.ACE.OLEDB.12.0;Data source=" + strPath;
            OleDbConnection conn    = new OleDbConnection(conStr);

            conn.Open();

            OleDbCommand    command = new OleDbCommand("select * from StorageInfo where ID = " + storageid, conn);
            OleDbDataReader dr      = command.ExecuteReader();

            if (dr.Read())
            {
                price = dr.GetString(dr.GetOrdinal("price"));
            }

            dr.Close();
            dr = null;

            command.Cancel();
            command.Dispose();
            command = null;

            conn.Close();
            conn.Dispose();
            conn = null;

            return(price);
        }
예제 #6
0
        // 取得店家基本資料
        private void GetStoreData()
        {
            OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            OleDbCommand    cmd  = new OleDbCommand("Select * From store Where store_no = ?", conn);

            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("aStore_no", sStore_no);
            conn.Open();
            OleDbDataReader dr = cmd.ExecuteReader();

            dr.Read();

            if (dr.HasRows)
            {
                this.txtStore.Text   = dr.GetString(1);
                this.txtPhone.Text   = dr.GetString(2);
                this.txtAddress.Text = dr.GetString(3);
                this.txtRemark.Text  = dr.GetString(4);
            }
            else
            {
                Server.Transfer("~/ErrorPages/aOops.aspx");
            }

            cmd.Cancel();
            dr.Close();
        }
예제 #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        OleDbConnection Conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        OleDbDataReader dr = null;

        OleDbCommand cmd = new OleDbCommand("SELECT [商品ID], [商品名稱]  FROM [商品主黨]", Conn);

        try     //==== 以下程式,只放「執行期間」的指令!=====================
        {
            Conn.Open();
            dr = cmd.ExecuteReader();
        }
        catch (Exception ex)
        {
            Response.Write("<b>Error Message----  </b>" + ex.ToString() + "<HR/>");
        }

        finally
        {
            if (dr != null)
            {
                cmd.Cancel();
                dr.Close();
            }
            if (Conn.State == ConnectionState.Open)
            {
                Conn.Close();
                Conn.Dispose();
            }
        }
    }
예제 #8
0
        // 刪除資料
        private void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string sSql = "Delete From item Where item_no = ?";

            try
            {
                OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                OleDbCommand    cmd  = new OleDbCommand(sSql, conn);
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("item_no", this.GridView1.DataKeys[e.RowIndex].Value.ToString());
                conn.Open();
                cmd.ExecuteNonQuery();
                cmd.Cancel();
                conn.Close();

                // 重新綁定資料
                DataTable dt = (DataTable)ViewState["dt"];
                dt.Rows.RemoveAt(e.RowIndex);

                ViewState["dt"] = dt;
                BindItem();

                GetCategory();
            }
            catch (Exception ex)
            {
                this.divAlert.Style.Add("display", "block");
                this.lblAlert.Text = "Error : " + ex.Message;
            }
        }
예제 #9
0
        /// <summary>
        /// 此为搜索使用
        /// </summary>
        /// <returns></returns>
        public static List <string> GetGameListName()
        {
            List <string> gameList = new List <string>();

            string          strPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\" + DBName + ".accdb";
            string          conStr  = "Provider=Microsoft.ACE.OLEDB.12.0;Data source=" + strPath;
            OleDbConnection conn    = new OleDbConnection(conStr);

            conn.Open();

            OleDbCommand    command = new OleDbCommand("select * from GameList", conn);
            OleDbDataReader dr      = command.ExecuteReader();

            while (dr.Read())
            {
                string zhName = dr.GetString(dr.GetOrdinal("ZhName"));
                string enName = dr.GetString(dr.GetOrdinal("EnName"));
                gameList.Add(zhName + enName);
            }

            dr.Close();
            dr = null;

            command.Cancel();
            command.Dispose();
            command = null;

            conn.Close();
            conn.Dispose();
            conn = null;

            return(gameList);
        }
예제 #10
0
        /// <summary>
        /// Execute database command directly and display result to data grid
        /// </summary>
        /// <param name="oleCommand"></param>
        /// <param name="targetDataGridView"></param>
        public void CommandExec(string oleCommand, DataGridView targetDataGridView)
        {
            OleDbConnection DBConnection = new OleDbConnection(ConnectString());
            OleDbCommand    DBCommand    = new OleDbCommand(oleCommand, DBConnection);

            DBConnection.Open();
            if (DBConnection.State == ConnectionState.Open)
            {
                try
                {
                    DBCommand.ExecuteNonQuery();
                    OleDbDataAdapter dataAdapter = new OleDbDataAdapter(oleCommand, DBConnection);
                    DataSet          dataSet     = new DataSet();
                    dataAdapter.Fill(dataSet);

                    targetDataGridView.DataSource = dataSet.Tables[0];
                    DBCommand.Cancel();
                }
                catch (OleDbException dberr)
                {
                    MessageBox.Show(dberr.Message, dberr.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    DBConnection.Close();
                }
                finally
                {
                    DBConnection.Close();
                }
            }
            else
            {
                MessageBox.Show("Something's wrong with Database connection, Check Directory.");
            }
        }
예제 #11
0
        // 新增餐點類別至資料庫
        private void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("AddNew"))
            {
                string sCategoryName = (this.GridView1.FooterRow.FindControl("txtCategoryNameFooter") as TextBox).Text.Trim();

                if (sCategoryName == "")
                {
                    GetData();
                    this.divNotify.Style.Add("display", "block");
                    this.lblNotify.Text = "您忘記輸入類別名稱了。";
                    return;
                }

                OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                OleDbCommand    cmd  = new OleDbCommand("Insert Into item_category(itemCategory_name, store_no) Values(?,?)", conn);
                cmd.Parameters.AddWithValue("itemCategory_name", sCategoryName);
                cmd.Parameters.AddWithValue("store_no", sStore_no);
                conn.Open();
                cmd.ExecuteNonQuery();
                cmd.Cancel();
                conn.Close();

                GetData();
            }
        }
예제 #12
0
        /// <summary>
        /// 得到用户密码
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public static string GetUserPasswd(string userID)
        {
            string          passwd  = "";
            string          strPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\" + DBName + ".accdb";
            string          conStr  = "Provider=Microsoft.ACE.OLEDB.12.0;Data source=" + strPath;
            OleDbConnection conn    = new OleDbConnection(conStr);

            conn.Open();

            OleDbCommand    command = new OleDbCommand("select * from UserList where ID = " + userID, conn);
            OleDbDataReader dr      = command.ExecuteReader();

            if (dr.Read())
            {
                passwd = dr.GetString(dr.GetOrdinal("passwd"));
            }

            dr.Close();
            dr = null;

            command.Cancel();
            command.Dispose();
            command = null;

            conn.Close();
            conn.Dispose();
            conn = null;
            return(passwd);
        }
예제 #13
0
 private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
 {
     App.log($"Query status check @ {e.SignalTime} | Runtime : {runtime()} | Max RunTime : {App.queryMaxRunTime}");
     if (state == states.Running)
     {
         if (runtime() > App.queryMaxRunTime)
         {
             App.log($"need to cancel query.| Runtime : {runtime()} | Max RunTime : {App.queryMaxRunTime} ");
             Timing timing = new Timing(this.db);
             cmd.Cancel();
             timing.stop();
             timing.log("Cancelling Query");
             state  = states.Done;
             result = results.Stopped;
             timer.Stop();
             throw new TimeoutException($"SQL Query exceeded maximum allowed runtime. | Runtime : {runtime()} | Max RunTime : {App.queryMaxRunTime} ");
             // I should save/log this efffort and allow a retry - now while in memory?
             // or leave the scheduler retry
         }
         else
         {
             timer.Start();  // schedule another run
         }
     }
     else
     {
         App.log($@"This query should have stopped. Will stop 
                     {errorMsg}
                     {sql}");
         timer.Stop();
     }
 }
예제 #14
0
        private void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                // 新增店家
                if (e.CommandName.Equals("AddNew"))
                {
                    string sStoreName    = ((TextBox)this.GridView1.FooterRow.Cells[0].FindControl("txtStoreNameFooter")).Text.Trim();
                    string sStoreAddress = ((TextBox)this.GridView1.FooterRow.Cells[0].FindControl("txtAddressFooter")).Text.Trim();
                    string sStorePhone   = ((TextBox)this.GridView1.FooterRow.Cells[0].FindControl("txtPhoneFooter")).Text.Trim();
                    string sStoreRemark  = ((TextBox)this.GridView1.FooterRow.Cells[0].FindControl("txtRemarkFooter")).Text.Trim();

                    // 驗證資料
                    if (sStoreName == "")
                    {
                        GetData();
                        this.GridView1.FooterRow.Visible = true;
                        this.divNotify.Style.Add("display", "block");
                        this.lblNotify.Text = "您忘記輸入店家名稱了。";
                        return;
                    }
                    // 新增至資料庫
                    string          sSql = "Insert Into store(store_name, store_address, store_phone, store_remark) Values (?,?,?,?);";
                    OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                    OleDbCommand    cmd  = new OleDbCommand(sSql, conn);
                    cmd.Parameters.AddWithValue("store_name", sStoreName);
                    cmd.Parameters.AddWithValue("store_address", sStoreAddress);
                    cmd.Parameters.AddWithValue("store_phone", sStorePhone);
                    cmd.Parameters.AddWithValue("store_remark", sStoreRemark);

                    conn.Open();
                    cmd.ExecuteNonQuery();
                    cmd.Cancel();
                    conn.Close();

                    DataTable dt = (DataTable)ViewState["dt_sotre"];
                    // ViewState 新增餐點
                    DataRow row = dt.NewRow();
                    row["store_name"]    = sStoreName;
                    row["store_phone"]   = sStorePhone;
                    row["store_address"] = sStoreAddress;
                    row["store_remark"]  = sStoreRemark;
                    dt.Rows.InsertAt(row, 0);

                    ViewState["dt_sotre"] = dt;

                    GetData();
                } // 取消新增店家
                else if (e.CommandName.Equals("CancelAddNew"))
                {
                    this.GridView1.FooterRow.Visible = false;
                    GetData();
                }
            }
            catch (Exception ex)
            {
                this.divAlert.Style.Add("display", "block");
                this.lblAlert.Text = "Error : " + ex.Message;
            }
        }
예제 #15
0
        private int SaveLocal(DataSet objdatasetdto)
        {
            var objcon = new SqlConnection(ConfigurationManager.ConnectionStrings["SecureConnectionString"].ToString());

            for (var i = 0; i < objdatasetdto.Tables[0].Rows.Count; i++)
            {
                //access db
                var conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source= F:\\LED\\Local\\Pop.mdb");
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Open();
                var comm = new OleDbCommand();
                comm.CommandType = CommandType.Text;
                comm.Connection  = conn;
                comm.CommandText = "INSERT INTO Called ([No], Registration, [LO_NO]) values (" +
                                   objdatasetdto.Tables[0].Rows[i]["Queue_No"] + ", '" +
                                   objdatasetdto.Tables[0].Rows[i]["Registration"] + "', " +
                                   objdatasetdto.Tables[0].Rows[i]["LO_NO"] + ")";
                comm.ExecuteNonQuery();
                comm.Cancel();
                comm.Dispose();
            }
            return(1);
        }
예제 #16
0
 private void Disconnect()
 {
     if (_con != null && _con.State == ConnectionState.Open)
     {
         _cmd.Cancel();
         _con.Close();
     }
 }
예제 #17
0
파일: source.cs 프로젝트: zhimaqiao51/docs
    // <Snippet1>
    public void CreateCommand(string queryString, OleDbConnection connection)
    {
        OleDbCommand command = new OleDbCommand(queryString, connection);

        command.Connection.Open();
        command.ExecuteReader();
        command.Cancel();
    }
예제 #18
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        //----上面已經事先寫好 Using System.Web.Configuration ----
        //---- (連結資料庫)----

        OleDbConnection Conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        Conn.Open();

        OleDbDataReader dr  = null;
        OleDbCommand    cmd = new OleDbCommand("select 會員ID, 會員帳號, 會員帳號, 會員密碼 from 會員資料 where 會員帳號 = '" + TextBox1.Text + "' and 會員密碼 = '" + TextBox2.Text + "'", Conn);

        //*** 請注意資料隱碼攻擊(SQL Injection攻擊)***

        dr = cmd.ExecuteReader();   //---- 這時候執行SQL指令,取出資料

        if (!dr.Read())
        {
            Response.Write("帳號或是密碼有錯!");

            cmd.Cancel();
            //----關閉DataReader之前,一定要先「取消」SqlCommand
            dr.Close();
            Conn.Close();
            Conn.Dispose();

            Response.End();   //--程式暫停。或是寫成 return,脫離這個事件。
        }
        else
        {
            Session["Login"] = "******";

            //--帳號密碼驗證成功,才能獲得這個 Session["Login"] = "******" 鑰匙

            Session["u_name"]   = dr["會員帳號"].ToString();
            Session["u_passwd"] = dr["會員密碼"].ToString();
            Session["u_id"]     = dr["會員ID"].ToString();
            cmd.Cancel();
            dr.Close();
            Conn.Close();
            Conn.Dispose();

            Response.Redirect("home.aspx");
            //--帳號密碼驗證成功,導向另一個網頁。
        }
    }
예제 #19
0
        public void ExecuteSqlTran(ArrayList SQLStringList, string bakname, HttpContext context)
        {
            string       str3;
            StreamReader reader = new StreamReader(Path.Combine(base.Server.MapPath("."), "ProgressBar.html"), Encoding.GetEncoding("gb2312"));
            string       s      = reader.ReadToEnd();

            reader.Close();
            context.Response.Write(s);
            context.Response.Flush();
            Thread.Sleep(200);
            OleDbConnection connection = null;

            connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + bakname);
            connection.Open();
            OleDbCommand command = new OleDbCommand {
                Connection  = connection,
                Transaction = connection.BeginTransaction()
            };

            try
            {
                double num   = 0.0;
                double count = SQLStringList.Count;
                double num3  = 0.0;
                for (int i = 0; i < SQLStringList.Count; i++)
                {
                    num++;
                    if ((((num / count) * 100.0) >= 1.0) && (Math.Round((double)((num / count) * 100.0)) > num3))
                    {
                        Thread.Sleep(1);
                        num3 = Math.Round((double)((num / count) * 100.0));
                        str3 = "<script>SetPorgressBar('已备份" + num.ToString() + "','" + num3.ToString() + "'); </script>";
                        context.Response.Write(str3);
                        context.Response.Flush();
                    }
                    string str4 = SQLStringList[i].ToString();
                    if (str4.Trim().Length > 1)
                    {
                        command.CommandText = str4;
                        command.ExecuteNonQuery();
                    }
                }
                command.Transaction.Commit();
            }
            catch (Exception exception)
            {
                command.Transaction.Rollback();
                throw new Exception(exception.Message);
            }
            command.Cancel();
            connection.Close();
            command.Dispose();
            connection.Dispose();
            str3 = "<script>hText(); </script>";
            context.Response.Write(str3);
            context.Response.Flush();
            context.Response.Write(base.ShowDialogBox("備份成功!", string.Format("/BillBackupManage/BillBackup.aspx?lid={0}", 100), 0));
        }
예제 #20
0
 public override void Cancel()
 {
     try {
         OleDbCommand.Cancel();
     }
     catch (OleDbException e) {
         throw new VfpException(e.Message, e);
     }
 }
예제 #21
0
        public int GetNumber()
        {
            OleDbCommand cmd = new OleDbCommand("Select iif(IsNull(Max(order_no)), 0, Max(order_no)) From OrderHead1 Where order_no like '" + iDateDefult + "%'", conn);

            conn.Open();
            iLatestNum = (int)cmd.ExecuteScalar();
            cmd.Cancel();
            conn.Close();

            return(iLatestNum);
        }
예제 #22
0
        private static void Test_Command_Cancel()
        {
            using (OleDbCommand cmd = new OleDbCommand("select * from code;", conn))
            {
                cmd.ExecuteReader();
                cmd.Cancel();

                OleDbCommand cmd_clone = cmd.Clone();
                Assert.AreEqual(cmd.ToString(), cmd_clone.ToString());
            }
        }
예제 #23
0
        //Заполнение DataTable
        public static DataTable GetDataTable(string p_query, OleDbParameter[] p_pr)
        {
            DataTable        m_dt   = new DataTable();
            OleDbConnection  m_conn = DataBaseHelper.GetOleDbConnection();
            OleDbCommand     m_cmd  = new OleDbCommand();
            OleDbDataAdapter m_da   = new OleDbDataAdapter();

            try
            {
                m_conn.Open();
            }
            catch (OleDbException e)
            {
                throw new Exception(e.Message);
            }
            catch (Exception e1)
            {
                throw new Exception(e1.Message);
            }

            m_cmd.Connection  = m_conn;
            m_cmd.CommandText = p_query;

            if (p_pr != null)
            {
                for (int i = 0; i < p_pr.Length; i++)
                {
                    m_cmd.Parameters.Add(p_pr[i]);
                }
            }

            m_da.SelectCommand = m_cmd;

            try
            {
                m_da.Fill(m_dt);
            }
            catch (OleDbException e)
            {
                throw new Exception(e.Message);
            }
            catch (Exception e1)
            {
                throw new Exception(e1.Message);
            }
            finally
            {
                m_cmd.Cancel();
                m_conn.Close();
            }

            return(m_dt);
        }
예제 #24
0
        // 更新餐點資料
        private void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string sSql = "Update item Set itemCategory_no = ?, item_name = ?, item_price = ? where item_no = ?";

            try
            {   // 抓取修改後的值
                string sCategoryNo   = ((DropDownList)this.GridView1.Rows[e.RowIndex].Cells[1].FindControl("ddlCategoryEdit")).Text.Trim();
                string sCategoryName = ((DropDownList)this.GridView1.Rows[e.RowIndex].Cells[1].FindControl("ddlCategoryEdit")).SelectedItem.Text;
                string sItemName     = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].FindControl("txtItemName")).Text.Trim();
                string sItemPrice    = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[3].FindControl("txtItemPrice")).Text.Trim();
                sItemPrice = Regex.Replace(sItemPrice, @"\b\s+\b", " ");        //字串中間多餘的空格去掉,只保留一個空格

                // 驗證資料
                string sErrMsg = Verify(sItemName, sItemPrice);

                if (sErrMsg != "")
                {
                    this.divNotify.Style.Add("display", "block");
                    this.lblNotify.Text = sErrMsg;
                    return;
                }
                // 更新資料庫
                OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                OleDbCommand    cmd  = new OleDbCommand(sSql, conn);
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("itemCategory_no", sCategoryNo);
                cmd.Parameters.AddWithValue("item_name", sItemName);
                cmd.Parameters.AddWithValue("item_price", sItemPrice);
                cmd.Parameters.AddWithValue("item_no", this.GridView1.DataKeys[e.RowIndex].Value.ToString());       //取得被選取列的主鍵
                conn.Open();
                cmd.ExecuteNonQuery();
                cmd.Cancel();
                conn.Close();
                // 更新ViewState的dt
                DataTable   dt  = (DataTable)ViewState["dt"];
                GridViewRow row = this.GridView1.Rows[e.RowIndex];
                dt.Rows[row.DataItemIndex]["itemCategory_no"]   = sCategoryNo;
                dt.Rows[row.DataItemIndex]["itemCategory_name"] = sCategoryName;
                dt.Rows[row.DataItemIndex]["item_name"]         = sItemName;
                dt.Rows[row.DataItemIndex]["item_price"]        = sItemPrice;
                // 離開編輯模式
                this.GridView1.EditIndex = -1;

                ViewState["dt"] = dt;
                BindItem();
                GetCategory();
            }
            catch (Exception ex)
            {
                this.divAlert.Style.Add("display", "block");
                this.lblAlert.Text = "Error : " + ex.Message;
            }
        }
예제 #25
0
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        string id;
        int    i = 0, z = 0, total = 0;

        int[]    array  = new int[300];
        int[]    idd    = new int[300];
        string[] strid  = new string[300];
        string[] strcol = new string[300];
        string[] strg   = new string[300];
        int[]    strdol = new int[300];

        id = Session["u_id"].ToString();
        OleDbConnection Conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        OleDbDataReader dr = null;

        Conn.Open();

        OleDbCommand cmd = new OleDbCommand("SELECT [購買商品],[會員ID], [顏色],[容量],[數量] ,[價格]  FROM [購物車]", Conn);

        dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            int    iddStr = (int)dr["會員ID"];
            String idStr  = (String)dr["購買商品"];
            String colStr = (String)dr["顏色"];
            String gStr   = (String)dr["容量"];
            int    muStr  = (int)dr["數量"];
            int    dolStr = (int)dr["價格"];

            idd[z]    = iddStr;
            strid[z]  = idStr;
            strcol[z] = colStr;
            strg[z]   = gStr;
            array[z]  = muStr;
            strdol[z] = dolStr;
            z         = z + 1;
        }
        cmd.Cancel();
        Conn.Close();
        for (i = 0; i < z; i++)
        {
            if (idd[i] == int.Parse(id))
            {
                total = total + (strdol[i] * array[i]);
            }
        }
        Label1.Text = total.ToString();
        Label2.Text = "本次消費金額" + total.ToString();
    }
예제 #26
0
        //Выполнение произвольного запроса
        public static bool ExecuteQuery(string p_query, OleDbParameter[] p_pr)
        {
            bool            m_result = true;
            OleDbConnection m_conn   = DataBaseHelper.GetOleDbConnection();
            OleDbCommand    m_cmd    = new OleDbCommand();

            try
            {
                m_conn.Open();
            }
            catch (OleDbException e)
            {
                throw new Exception(e.Message);
            }
            catch (Exception e1)
            {
                throw new Exception(e1.Message);
            }

            m_cmd.Connection  = m_conn;
            m_cmd.CommandText = p_query;

            if (p_pr != null)
            {
                for (int i = 0; i < p_pr.Length; i++)
                {
                    m_cmd.Parameters.Add(p_pr[i]);
                }
            }

            try
            {
                m_cmd.ExecuteNonQuery();
            }
            catch (OleDbException e)
            {
                m_result = false;
                throw new Exception(e.Message);
            }
            catch (Exception e1)
            {
                throw new Exception(e1.Message);
            }
            finally
            {
                m_cmd.Cancel();
                m_conn.Close();
                m_conn.Dispose();
            }

            return(m_result);
        }
예제 #27
0
        private void cbNev_SelectedIndexChanged(object sender, EventArgs e)
        {
            OleDbConnection kapcsolat = new OleDbConnection();

            kapcsolat.ConnectionString = connectionString;
            kapcsolat.Open();
            OleDbCommand emailKeres = new OleDbCommand("select [e-mail] from nevek where nev=('" + cbNev.Text +
                                                       "')", kapcsolat);

            tbEmail.Text = emailKeres.ExecuteScalar().ToString();
            emailKeres.Cancel();
            kapcsolat.Close();
        }
예제 #28
0
        public static string GetData(string sSql)
        {
            string sLatestNum;

            using (OleDbConnection conn = new OleDbConnection(connDB))
            {
                OleDbCommand cmd = new OleDbCommand(sSql, conn);
                conn.Open();
                sLatestNum = (string)cmd.ExecuteScalar();
                cmd.Cancel();
            }
            return(sLatestNum);
        }
예제 #29
0
        private void btnClear_Click(object sender, EventArgs e)
        {
            if (sender.Equals(this.btnClear))
            {
                OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                OleDbCommand    cmd  = new OleDbCommand("Delete From filledIn Where order_no = " + sOrder_no + "and employee_no ='" + Session["employee_no"].ToString() + "'", conn);
                conn.Open();
                cmd.ExecuteNonQuery();
                cmd.Cancel();
                conn.Close();

                GetFilledIn();
            }
        }
예제 #30
0
        private void frmModositas_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'nevekDataSet.nevek' table. You can move, or remove it, as needed.
            this.nevekTableAdapter.Fill(this.nevekDataSet.nevek);
            OleDbConnection kapcsolat = new OleDbConnection();

            kapcsolat.ConnectionString = connectionString;
            kapcsolat.Open();
            OleDbCommand emailKeres = new OleDbCommand("select [e-mail] from nevek where nev=('" + cbNev.Text +
                                                       "')", kapcsolat);

            tbEmail.Text = emailKeres.ExecuteScalar().ToString();
            emailKeres.Cancel();
            kapcsolat.Close();
        }