protected void btnAdd_Click(object sender, EventArgs e) { try { string sql = "Select ma_donvi from don_vi where ma_donvi='" + txt_madv.Text + "'"; string ma = ""; foreach (DataRow dt in db.bindDataTable(sql).Rows) { ma = dt["ma_donvi"].ToString(); } if (ma == txt_madv.Text) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "myalert", "$.notify('Mã đơn vị đã tồn tại !!!', 'error');", true); } else { DTO_DV dv = new DTO_DV(txt_madv.Text, txt_tendv.Text, txt_diachi.Text, txt_mota.Text); if (bus_dv.Query("_Insert_donvi", dv)) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "myalert", "$.notify('Thêm đơn vị thành công !!!', 'success');", true); hienthi(); clearAll(); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "myalert", "$.notify('Thêm đơn vị thất bại !!!', 'error');", true); } } } catch (Exception ex) { } }
protected void btnEdit_Click(object sender, EventArgs e) { try { DTO_DV dv = new DTO_DV(txt_madv_edit.Text, txt_tendv_edit.Text, txt_diachi_edit.Text, txt_mota_edit.Text); if (bus_dv.Query("_Update_donvi", dv)) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "myalert", "$.notify('Cập nhật đơn vị thành công !!!', 'success');", true); hienthi(); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "myalert", "$.notify('Cập nhật đơn vị thất bại !!!', 'error');", true); } } catch (Exception ex) { } }
public bool ExcuteQuery_DV(String name, DTO_DV dv) { try { SqlConnection connection = new SqlConnection(conn); SqlCommand command = new SqlCommand(name, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@ma_donvi", dv.MaDV)); command.Parameters.Add(new SqlParameter("@ten_donvi", dv.TenDV)); command.Parameters.Add(new SqlParameter("@dia_chi", dv.DiaChi)); command.Parameters.Add(new SqlParameter("@mo_ta", dv.MoTa)); connection.Open(); command.ExecuteNonQuery(); connection.Close(); connection.Dispose(); return(true); } catch { return(false); } }
public bool Query(String name, DTO_DV dv) { return(dal_dv.ExcuteQuery_DV(name, dv)); }