示例#1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (mode == "add")
            {
                //create new row
                DataRow newRow = tabClients.NewRow();
                // Fill the columns of the record with the contents of the textboxes
                //newRow["Id"] = 9090;
                newRow["Name"]     = txtName.Text;
                newRow["Pin"]      = txtPin.Text;
                newRow["Type"]     = cboType.SelectedItem.ToString();
                newRow["Phone_no"] = txtPhone.Text;
                newRow["AgentId"]  = cboAgentId.Text;

                // Add the new datarow in the collection tabAgents.Rows
                tabClients.Rows.Add(newRow);

                // Save (or Synchronize Dataset.Datatable -> Database.Table ) the contents of dataset to database
                SqlCommandBuilder myBuilder = new SqlCommandBuilder(clsGlobal.adpClients);
                clsGlobal.adpClients.Update(clsGlobal.mySet, "Clients");

                //reload the datatable (or Synchronize Database.Table -> Dataset.Datatable ) the contents of database to dataset
                // first: delete the old datatable Clients
                clsGlobal.mySet.Tables.Remove("Clients");

                // second: reload the table Clients from database
                clsGlobal.adpClients.Fill(clsGlobal.mySet, "Clients");

                MessageBox.Show("One new client has added sucessfully");

                tabClients = clsGlobal.mySet.Tables["Clients"];

                int i = tabClients.Rows.Count - 1;
                clsGlobal.newClientId = tabClients.Rows[i]["Id"].ToString();
                if (tabClients.Rows[i]["Type"].ToString() == "seller")
                {
                    frmHouse house = new frmHouse();
                    house.Show();

                    //ActivateButtons(true, false, false, false, false, false, false);
                    //btnFirst.Enabled = btnNext.Enabled = btnPrevious.Enabled = btnLast.Enabled = false;
                }
            }
            else if (mode == "edit")
            {
                // positon the currentRow at the currentIndex in the tabClients.Rows
                DataRow currentRow = tabClients.Rows[currentIndex];

                // overwrite the columns of the record with the contents of the textboxes
                currentRow["Name"]     = txtName.Text;
                currentRow["Pin"]      = txtPin.Text;
                currentRow["Type"]     = cboType.SelectedItem.ToString();
                currentRow["Phone_no"] = txtPhone.Text;
                currentRow["AgentId"]  = cboAgentId.Text;

                // Save (or Synchronize Dataset.Datatable -> Database.Table ) the contents of dataset to database
                SqlCommandBuilder myBuilder = new SqlCommandBuilder(clsGlobal.adpClients);
                clsGlobal.adpClients.Update(clsGlobal.mySet, "Clients");

                //reload the datatable (or Synchronize Database.Table -> Dataset.Datatable ) the contents of database to dataset
                // first: delete the old datatable Clients
                clsGlobal.mySet.Tables.Remove("Clients");

                // second: reload the table Agents from database
                clsGlobal.adpClients.Fill(clsGlobal.mySet, "Clients");

                MessageBox.Show("Information of a client has updated sucessfully");

                tabClients = clsGlobal.mySet.Tables["Clients"];
            }

            displayClient();
            mode = "";
            ActivateButtons(true, true, true, false, false, true, true);
        }
示例#2
0
        private void mnuHouses_Click(object sender, EventArgs e)
        {
            frmHouse house = new frmHouse();

            house.Show();
        }