Exemplo n.º 1
0
        //修改(點擊表格)
        private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = dataGridView.CurrentRow.Index;

            if (index == -1)
            {
                return;
            }

            INVOICE_NUM invoiceNum = new INVOICE_NUM
            {
                Year       = dt.Rows[index]["Year"].ToString(),
                Month      = dt.Rows[index]["Month"].ToString(),
                Letter     = dt.Rows[index]["Letter"].ToString(),
                StartNum   = dt.Rows[index]["StartNum"].ToString(),
                EndNum     = dt.Rows[index]["EndNum"].ToString(),
                CurrentNum = dt.Rows[index]["CurrentNum"].ToString()
            };

            //透過建構式將資料傳到 AddForm
            AddForm addForm = new AddForm(invoiceNum);

            if (addForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            dt.Rows[index]["Year"]       = addForm.invoiceNum.Year;
            dt.Rows[index]["Month"]      = addForm.invoiceNum.Month;
            dt.Rows[index]["Letter"]     = addForm.invoiceNum.Letter;
            dt.Rows[index]["StartNum"]   = addForm.invoiceNum.StartNum;
            dt.Rows[index]["EndNum"]     = addForm.invoiceNum.EndNum;
            dt.Rows[index]["CurrentNum"] = addForm.invoiceNum.CurrentNum;
            dt.Rows[index]["CreateDate"] = DateTime.Now;

            scb = new SqlCommandBuilder(sda); //產生update命令
            sda.Update(dt);                   //將修改的資料寫入資料庫
        }
Exemplo n.º 2
0
        //修改
        private void editBtn_Click(object sender, EventArgs e)
        {
            #region
            //int id = (int)dataGridView.CurrentRow.Cells["ID"].Value;
            //string query = $"select * from INVOICE_NUM where InvoiceID={id}";

            //SqlConnection conn = new SqlConnection(config);
            //SqlCommand cmd = new SqlCommand(query, conn);
            //conn.Open();

            //SqlDataReader dr = cmd.ExecuteReader();

            //INVOICE_NUM invoiceNum = new INVOICE_NUM();

            //while (dr.Read())
            //{
            //  invoiceNum.Year = dr["Year"].ToString();
            //  invoiceNum.Month = dr["Month"].ToString();
            //  invoiceNum.Letter = dr["Letter"].ToString();
            //  invoiceNum.StartNum = dr["StartNum"].ToString();
            //  invoiceNum.EndNum = dr["EndNum"].ToString();
            //  invoiceNum.CurrentNum = dr["CurrentNum"].ToString();
            //}

            //dr.Close();
            //conn.Close();
            #endregion
            int index = dataGridView.CurrentRow.Index;

            if (index == -1)
            {
                return;
            }

            INVOICE_NUM invoiceNum = new INVOICE_NUM
            {
                Year       = dt.Rows[index]["Year"].ToString(),
                Month      = dt.Rows[index]["Month"].ToString(),
                Letter     = dt.Rows[index]["Letter"].ToString(),
                StartNum   = dt.Rows[index]["StartNum"].ToString(),
                EndNum     = dt.Rows[index]["EndNum"].ToString(),
                CurrentNum = dt.Rows[index]["CurrentNum"].ToString()
            };

            //透過建構式將資料傳到 AddForm
            AddForm addForm = new AddForm(invoiceNum);

            if (addForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            dt.Rows[index]["Year"]       = addForm.invoiceNum.Year;
            dt.Rows[index]["Month"]      = addForm.invoiceNum.Month;
            dt.Rows[index]["Letter"]     = addForm.invoiceNum.Letter;
            dt.Rows[index]["StartNum"]   = addForm.invoiceNum.StartNum;
            dt.Rows[index]["EndNum"]     = addForm.invoiceNum.EndNum;
            dt.Rows[index]["CurrentNum"] = addForm.invoiceNum.CurrentNum;
            dt.Rows[index]["CreateDate"] = DateTime.Now;

            scb = new SqlCommandBuilder(sda); //產生update命令
            sda.Update(dt);                   //將修改的資料寫入資料庫
        }