Exemplo n.º 1
0
        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                frmContactDetails myForm;
                myForm = new frmContactDetails();

                //Get contact types
                myForm.edtType.Items.Clear();
                myForm.dummyTypes.Clear();

                tblContactType _tblContactType = new tblContactType();
                DataTable      dummy           = new DataTable();
                int            retry           = 5;
                while (dummy.Rows.Count == 0 && retry > 0)
                {
                    dummy = _tblContactType.GetData().Copy();
                    retry = retry - 1;
                }

                List <string> tmp = new List <string>();

                foreach (DataRow ARec in dummy.Rows)
                {
                    myForm.edtType.Items.Add(ARec["Description"].ToString());
                    myForm.dummyTypes.Add(ARec["Type"].ToString());
                    tmp.Add(ARec["IDX"].ToString());
                }

                myForm.edtType.SelectedIndex = 0;

                myForm.ShowDialog();

                if (myForm.DialogResult == DialogResult.OK)
                {
                    if (myForm.dummyTypes[myForm.edtType.SelectedIndex] == "Number")
                    {
                        IDX = _tblClientContact.AddRec(dataGridView1.CurrentRow.Cells["IDX"].Value.ToString(), tmp[myForm.edtType.SelectedIndex], myForm.edt1.Text);
                    }
                    else
                    {
                        IDX = _tblClientContact.AddRec(dataGridView1.CurrentRow.Cells["IDX"].Value.ToString(), tmp[myForm.edtType.SelectedIndex], myForm.edt1.Text + "," + myForm.edt2.Text + "," + myForm.edt3.Text + ",");
                    }

                    DoRefresh();

                    foreach (DataGridViewRow ARec in dataGridView2.Rows)
                    {
                        if (ARec.Cells[0].Value.ToString() == IDX)
                        {
                            dataGridView2.CurrentCell = ARec.Cells[4];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Select a row first");
            }
        }
Exemplo n.º 2
0
        private void DoEdit2()
        {
            try
            {
                frmContactDetails myForm;
                myForm = new frmContactDetails();

                //Get contact types
                myForm.edtType.Items.Clear();
                myForm.dummyTypes.Clear();

                tblContactType _tblContactType = new tblContactType();
                DataTable      dummy           = new DataTable();
                int            retry           = 5;
                while (dummy.Rows.Count == 0 && retry > 0)
                {
                    dummy = _tblContactType.GetData().Copy();
                    retry = retry - 1;
                }

                List <string> tmp = new List <string>();

                foreach (DataRow ARec in dummy.Rows)
                {
                    myForm.edtType.Items.Add(ARec["Description"].ToString());
                    myForm.dummyTypes.Add(ARec["Type"].ToString());
                    tmp.Add(ARec["IDX"].ToString());
                }

                IDX = dataGridView2.CurrentRow.Cells["IDX"].Value.ToString();

                int tmpIDX = -1;

                for (int i = 0; i < tmp.Count; i++)
                {
                    if (dataGridView2.CurrentRow.Cells["ContactTypeIDX"].Value.ToString() == tmp[i])
                    {
                        tmpIDX = i;
                        break;
                    }
                }

                myForm.edtType.SelectedIndex = tmpIDX;

                if (myForm.dummyTypes[tmpIDX] == "Number")
                {
                    myForm.edt1.Text = dataGridView2.CurrentRow.Cells["Contact"].Value.ToString();
                }
                else
                {
                    string theData = dataGridView2.CurrentRow.Cells["Contact"].Value.ToString();
                    string A1      = theData.Substring(0, theData.IndexOf(","));
                    theData = theData.Substring(theData.IndexOf(",") + 1);
                    string A2 = theData.Substring(0, theData.IndexOf(","));
                    theData = theData.Substring(theData.IndexOf(",") + 1);
                    string A3 = theData.Substring(0, theData.IndexOf(","));

                    myForm.edt1.Text = A1;
                    myForm.edt2.Text = A2;
                    myForm.edt3.Text = A3;
                }

                myForm.ShowDialog();

                if (myForm.DialogResult == DialogResult.OK)
                {
                    if (myForm.dummyTypes[tmpIDX] == "Number")
                    {
                        IDX = _tblClientContact.EditRec(IDX, dataGridView1.CurrentRow.Cells["IDX"].Value.ToString(), tmp[myForm.edtType.SelectedIndex], myForm.edt1.Text);
                    }
                    else
                    {
                        IDX = _tblClientContact.EditRec(IDX, dataGridView1.CurrentRow.Cells["IDX"].Value.ToString(), tmp[myForm.edtType.SelectedIndex], myForm.edt1.Text + "," + myForm.edt2.Text + "," + myForm.edt3.Text + ",");
                    }

                    DoRefresh();

                    foreach (DataGridViewRow ARec in dataGridView2.Rows)
                    {
                        if (ARec.Cells[0].Value.ToString() == IDX)
                        {
                            dataGridView2.CurrentCell = ARec.Cells[4];
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("Select a row first");
            }
        }