/// <summary> /// Các thao tác trên danh sách /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void grvDocumentKind_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("cmdEdit", StringComparison.OrdinalIgnoreCase)) { //BOffical ctl = new BOffical(); //ctl.Delete(int.Parse(e.CommandArgument.ToString())); hdfId.Value = e.CommandArgument.ToString(); BOffical ctl = new BOffical(); try { OOffical obj = ctl.Get(int.Parse(hdfId.Value))[0]; txtAddress.Text = obj.Address; txtDescription.Text = obj.Description; txtEmail.Text = obj.Email; txtFax.Text = obj.Fax; txtName.Text = obj.Name; txtTel.Text = obj.Tel; try { ddlParent.Items.FindByValue(obj.OfficalParent.ToString()).Selected = true; } catch (Exception ex) { } } catch (Exception ex) { } } else if (e.CommandName.Equals("cmdDelete", StringComparison.OrdinalIgnoreCase)) { BOffical ctl = new BOffical(); ctl.Delete(int.Parse(e.CommandArgument.ToString())); BindData(); } }
protected void btnSubmit_Click(object sender, EventArgs e) { BOffical ctl = new BOffical(); if (!string.IsNullOrEmpty(txtName.Text)) { OOffical obj = new OOffical(); if (hdfId.Value != "0") { try { obj = ctl.Get(int.Parse(hdfId.Value))[0]; } catch (Exception ex) { obj = new OOffical(); } } obj.Name = txtName.Text; obj.Description = txtDescription.Text; obj.Address = txtAddress.Text; obj.Email = txtEmail.Text; obj.Fax = txtFax.Text; obj.Tel = txtTel.Text; try { obj.OfficalParent = int.Parse(ddlParent.SelectedValue); } catch (Exception ea) { obj.OfficalParent = 0; } if (hdfId.Value != "0") { ctl.Update(obj.OfficalID, obj.Name, obj.Description, obj.Address, obj.Tel, obj.Fax, obj.Email, obj.OfficalParent); hdfId.Value = "0"; } else { ctl.Add(obj); BindData(); } ResetForm(); } }
public bool Add(OOffical obj) { SqlParameter[] sqlPara = new SqlParameter[7]; sqlPara[0] = new SqlParameter("@Name", SqlDbType.NVarChar); sqlPara[0].Value = obj.Name; sqlPara[1] = new SqlParameter("@Description", SqlDbType.NVarChar); sqlPara[1].Value = obj.Description; sqlPara[2] = new SqlParameter("@Address", SqlDbType.NVarChar); sqlPara[2].Value = obj.Address; sqlPara[3] = new SqlParameter("@Tel", SqlDbType.VarChar); sqlPara[3].Value = obj.Tel; sqlPara[4] = new SqlParameter("@Fax", SqlDbType.VarChar); sqlPara[4].Value = obj.Fax; sqlPara[5] = new SqlParameter("@Email", SqlDbType.VarChar); sqlPara[5].Value = obj.Email; sqlPara[6] = new SqlParameter("@OfficalParent", SqlDbType.Int); sqlPara[6].Value = obj.OfficalParent; return(RunProcudure("sp_tblOffical_add", sqlPara)); }