Пример #1
0
        private void AddMenuItem_Click(object sender, EventArgs e)
        {
            ClientAddEditForm tempForm = new ClientAddEditForm();

            DialogResult resultDialog = tempForm.ShowDialog();

            if (resultDialog == DialogResult.OK)
            {
                Client item = tempForm.ResultModel;

                mainTable.Rows.Add(item.Id, item.FirstName, item.LastName, item.MiddleName, item.Phone);
            }
        }
Пример #2
0
        private void EditMenuItem_Click(object sender, EventArgs e)
        {
            Client temp = new Client()
            {
                Id         = (int)MainGrid.SelectedRows[0].Cells[0].Value,
                FirstName  = MainGrid.SelectedRows[0].Cells[1].Value.ToString(),
                LastName   = MainGrid.SelectedRows[0].Cells[2].Value.ToString(),
                MiddleName = MainGrid.SelectedRows[0].Cells[3].Value.ToString(),
                Phone      = MainGrid.SelectedRows[0].Cells[4].Value.ToString()
            };

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

            byte[] imageBytes = connString.QueryFirst <byte[]>("SELECT dbo.Client.Avatar FROM dbo.Client WHERE dbo.Client.Id = @id", new { temp.Id });

            temp.Avatar = imageBytes;

            if (connString.State != ConnectionState.Closed)
            {
                connString.Close();
            }

            ClientAddEditForm tempForm     = new ClientAddEditForm(temp);
            DialogResult      resultDialog = tempForm.ShowDialog();

            if (resultDialog == DialogResult.OK)
            {
                Client item = tempForm.ResultModel;

                mainTable.Rows.Find(item.Id).SetField(1, item.FirstName);
                mainTable.Rows.Find(item.Id).SetField(2, item.LastName);
                mainTable.Rows.Find(item.Id).SetField(3, item.MiddleName);
                mainTable.Rows.Find(item.Id).SetField(4, item.Phone);
            }
        }