//Add publisher information public int UpdateBookPress(BookPress objBookPress) { //Preparing SQL statements string sql = "Update BookPress Set PressName= @PressName,PressTel=@PressTel,PressContact=@PressContact, PressAddress=@PressAddress "; sql += " Where PressId=@PressId "; //Preparing parameters in SQL statements SqlParameter[] para = new SqlParameter[] { new SqlParameter("@PressId", objBookPress.PressId), new SqlParameter("@PressName", objBookPress.PressName), new SqlParameter("@PressTel", objBookPress.PressTel), new SqlParameter("@PressContact", objBookPress.PressContact), new SqlParameter("@PressAddress", objBookPress.PressAddress), }; //Execute and return results try { return(SQLHelper.Update(sql, para)); } catch (Exception ex) { throw ex; } }
private void dgvPress_DoubleClick(object sender, EventArgs e) { //===============View publisher Information==== //Get click on this line of data BookPress objBookPress = new BookPress() { PressId = Convert.ToInt32(dgvPress.CurrentRow.Cells[0].Value), PressName = dgvPress.CurrentRow.Cells[1].Value.ToString(), PressTel = dgvPress.CurrentRow.Cells[2].Value.ToString(), PressContact = dgvPress.CurrentRow.Cells[3].Value.ToString(), PressAddress = dgvPress.CurrentRow.Cells[4].Value.ToString(), }; //Modify Actionflag---See actionFlag = 1; //Open the Detail form if (objFrmBookPressDetail == null) { objFrmBookPressDetail = new frmBookPressDetail(actionFlag, objBookPress); objFrmBookPressDetail.Show(); } else { objFrmBookPressDetail.Activate(); objFrmBookPressDetail.WindowState = FormWindowState.Normal; } }
//Add publisher information public int AddBookPress(BookPress objBookPress) { //Preparing SQL statements string sql = "Insert into BookPress (PressId, PressName, PressTel, PressContact, PressAddress ) "; sql += " values (@PressId, @PressName,@PressTel, @PressContact, @PressAddress) "; //Preparing parameters in SQL statements SqlParameter[] para = new SqlParameter[] { new SqlParameter("@PressId", objBookPress.PressId), new SqlParameter("@PressName", objBookPress.PressName), new SqlParameter("@PressTel", objBookPress.PressTel), new SqlParameter("@PressContact", objBookPress.PressContact), new SqlParameter("@PressAddress", objBookPress.PressAddress), }; //Execute and return results try { return(SQLHelper.Update(sql, para)); } catch (Exception ex) { throw ex; } }
private void btnUpdate_Click(object sender, EventArgs e) { //Modify Publishing house information //Get click on this line of data BookPress objBookPress = new BookPress() { PressId = Convert.ToInt32(dgvPress.CurrentRow.Cells[0].Value), PressName = dgvPress.CurrentRow.Cells[1].Value.ToString(), PressTel = dgvPress.CurrentRow.Cells[2].Value.ToString(), PressContact = dgvPress.CurrentRow.Cells[3].Value.ToString(), PressAddress = dgvPress.CurrentRow.Cells[4].Value.ToString(), }; //Modify Actionflag---Modifications actionFlag = 3; //Open the Detail form if (objFrmBookPressDetail == null) { objFrmBookPressDetail = new frmBookPressDetail(actionFlag, objBookPress); DialogResult result = objFrmBookPressDetail.ShowDialog(); if (result == DialogResult.OK) { //Refresh Data in DataGridView LoadPressInfo(); } } else { objFrmBookPressDetail.Activate(); objFrmBookPressDetail.WindowState = FormWindowState.Normal; } }
private void btnCommit_Click(object sender, EventArgs e) { //Determine if the input complies with the specification if (!CheckPressInput()) { return; } //Encapsulation objects BookPress objBookPress = new BookPress() { PressId = Convert.ToInt32(lblPressId.Text), PressName = txtPressName.Text.Trim(), PressTel = txtPressTel.Text.Trim(), PressContact = txtPressContact.Text.Trim(), PressAddress = txtPressAddress.Text.Trim(), }; //Submit switch (actionFlag) { case 2: //Added execution try { if (objBookPressServices.AddBookPress(objBookPress) == 1) { //Notice Successful! MessageBox.Show("Success in Adding Publishing House Information!", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information); //Close current from Close(); //Return OK this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show("Error adding publisher information! Specific errors:" + ex.Message, "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case 3: //The execution of the modification try { if (objBookPressServices.UpdateBookPress(objBookPress) == 1) { //Notice Successful! MessageBox.Show("Success in Adding Publishing House Information!", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information); //Close current form Close(); //Return OK this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show("Error adding publisher information! Specific errors:" + ex.Message, "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; } }
//Form initialization when used for modification private void LoadUpdateForm(BookPress objBookPress) { //【1】 Title changed to "Modify Publishing house" lblTitle.Text = "【Modify Press】"; //【2】 Initialize content lblPressId.Text = objBookPress.PressId.ToString(); txtPressName.Text = objBookPress.PressName; txtPressTel.Text = objBookPress.PressTel; txtPressContact.Text = objBookPress.PressContact; txtPressAddress.Text = objBookPress.PressAddress; //【3】 Modify the Close button name btnClose.Text = "Cancel and Close"; }
//-=================================Custom Methods================================ //Form initialization when used for viewing private void LoadViewForm(BookPress objBookPress) { //【1】 Change the Title name to "view publisher" lblTitle.Text = "【View Press】"; //【2】 Disable controls txtPressName.Enabled = false; txtPressTel.Enabled = false; txtPressContact.Enabled = false; txtPressAddress.Enabled = false; //【3】 Initialize content lblPressId.Text = objBookPress.PressId.ToString(); txtPressName.Text = objBookPress.PressName; txtPressTel.Text = objBookPress.PressTel; txtPressContact.Text = objBookPress.PressContact; txtPressAddress.Text = objBookPress.PressAddress; //【4】Hide Submit button btnCommit.Visible = false; }
//Construction method of carrying parameters public frmBookPressDetail(int flag, BookPress objBookPress) : this() { //flag: 1---view 2---add 3---modify //Initialization of local ActionFlag actionFlag = flag; //Perform different actions according to Flag switch (flag) { case 1: LoadViewForm(objBookPress); break; case 2: LoadAddForm(); break; case 3: LoadUpdateForm(objBookPress); break; } }