Exemplo n.º 1
0
        /// <summary>
        /// 修改变量
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void bChange_Click(object sender, EventArgs e)
        {
            DataGridViewRow editRow = null;

            foreach (DataGridViewRow row in dataGridViewX1.Rows)
            {
                if ((bool)row.Cells["checkColumn"].EditedFormattedValue)
                {
                    editRow = row;
                    break;
                }
            }

            if (editRow != null)
            {
                DataRow[] rows = table.Select(string.Format("ID = '{0}'",
                                                            editRow.Cells["idColumn"].EditedFormattedValue));
                EditForm     eForm  = new EditForm(rows[0]);
                DialogResult result = eForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    Hashtable editData    = eForm.EditData;
                    string    id          = editData["id"] as string;
                    string    name        = editData["name"] as string;
                    string    description = editData["description"] as string;
                    string    startIndex  = editData["startIndex"] as string;
                    string    length      = editData["length"] as string;

                    try
                    {
                        if (conn.State == ConnectionState.Closed)
                        {
                            conn.Open();
                        }

                        string sqlString = string.Format("UPDATE VarData SET Name = '{0}', Description = '{1}', StartIndex = '{2}', Length = '{3}' WHERE ID = '{4}'",
                                                         name, description, startIndex, length, id);
                        SqlCommand cmd = conn.CreateCommand();
                        cmd.CommandText = sqlString;
                        cmd.ExecuteNonQuery();
                        sqlString = "SELECT * FROM VarData";
                        table     = GetDataTable(sqlString);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show("在更新变量信息时产生sql异常:" + ex.ToString());
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open)
                        {
                            conn.Close();
                        }
                    }

                    // 刷新数据
                    RefreshDataGridView("所有用户", "所有变量类型", "所有绑定类型", "所有绑定对象");
                }
            }
            else
            {
                MessageBox.Show("请先选中要修改的数据行!", "变量管理",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 修改变量
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void bChange_Click(object sender, EventArgs e)
        {
            DataGridViewRow editRow = null;

            foreach(DataGridViewRow row in dataGridViewX1.Rows)
            {
                if((bool)row.Cells["checkColumn"].EditedFormattedValue)
                {
                    editRow = row;
                    break;
                }
            }

            if(editRow != null)
            {
                DataRow[] rows = table.Select(string.Format("ID = '{0}'", 
                    editRow.Cells["idColumn"].EditedFormattedValue));
                EditForm eForm = new EditForm(rows[0]);
                DialogResult result = eForm.ShowDialog();
                if(result == DialogResult.OK)
                {
                    Hashtable editData = eForm.EditData;
                    string id = editData["id"] as string;
                    string name = editData["name"] as string;
                    string description = editData["description"] as string;
                    string startIndex = editData["startIndex"] as string;
                    string length = editData["length"] as string;

                    try
                    {
                        if(conn.State == ConnectionState.Closed)
                        {
                            conn.Open();
                        }

                        string sqlString = string.Format("UPDATE VarData SET Name = '{0}', Description = '{1}', StartIndex = '{2}', Length = '{3}' WHERE ID = '{4}'",
                            name, description, startIndex, length, id);
                        SqlCommand cmd = conn.CreateCommand();
                        cmd.CommandText = sqlString;
                        cmd.ExecuteNonQuery();
                        sqlString = "SELECT * FROM VarData";
                        table = GetDataTable(sqlString);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show("在更新变量信息时产生sql异常:" + ex.ToString());
                    }
                    finally
                    {
                        if(conn.State == ConnectionState.Open)
                        {
                            conn.Close();
                        }
                    }

                    // 刷新数据
                    RefreshDataGridView("所有用户", "所有变量类型", "所有绑定类型", "所有绑定对象");
                }
            }
            else
            {
                MessageBox.Show("请先选中要修改的数据行!", "变量管理",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }            
        }