コード例 #1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            sysDefsBindingSource.EndEdit();//Make sure changes get saved
            SysDefsTableAdapter defsAdapter = new SysDefsTableAdapter();

            //Perform database operations, and dispatch changes to the service
            foreach (SeeCommonDataSet.SysDefsRow defRow in seeCommonDataSet.SysDefs)
            {
                if (defRow.RowState == DataRowState.Added)
                {
                    defRow.DateCreated = DateTime.Now;
                    defRow.DbName      = defRow.Name.Replace(' ', '_'); //Set the database name
                    defsAdapter.Update(defRow);                         //Update the database
                    SysAdded(defRow.Name);                              //Notify the service
                }
                else if (defRow.RowState == DataRowState.Modified)
                {
                    string origName = (string)defRow["Name", DataRowVersion.Original];
                    string currName = (string)defRow["Name", DataRowVersion.Current];
                    if (origName != currName)
                    {
                        defRow.DbName = currName.Replace(' ', '_');
                    }                                //Update the database name
                    defsAdapter.Update(defRow);      //Update the database
                    SysModified(origName, currName); //Notify the service
                }
            }
        }
コード例 #2
0
        private void sysDefsBindingSource_ListChanged(object sender, ListChangedEventArgs e)
        {
            if (e.ListChangedType == ListChangedType.ItemDeleted)
            {
                DialogResult result = MessageBox.Show("All data will be lost." + Environment.NewLine + "Are you sure you want to remove this system?",
                                                      "Remove System", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                foreach (SeeCommonDataSet.SysDefsRow defRow in seeCommonDataSet.SysDefs)
                {
                    if (defRow.RowState == DataRowState.Deleted)
                    {
                        defRow.RejectChanges();//Get the original data back
                        if (result == DialogResult.Yes)
                        {
                            SysDeleted((string)defRow["Name", DataRowVersion.Original]); //Notify the service
                            defRow.Delete();                                             //Now delete the row
                            SysDefsTableAdapter defsAdapter = new SysDefsTableAdapter();
                            defsAdapter.Update(defRow);                                  //Update the database
                        }
                        break;
                    }
                }
                InvokeOnClick(buttonOK, new EventArgs());//Save any other changes and close
            }

            if (sysDefsBindingSource.List.Count > 0)
            {
                groupBox1.Enabled = true; nameTextBox.Enabled = true;
            }
            else
            {
                groupBox1.Enabled = false; nameTextBox.Enabled = false;
            }
        }