public ActionResult Read([DataSourceRequest] DataSourceRequest request) { List<Drug> list = new List<Drug>(); try { list = new DrugData().GetDrugs(); } catch (Exception ex) { } return Json(list.ToDataSourceResult(request), JsonRequestBehavior.AllowGet); }
private void ddlDrug_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e) { if (ddlDrug.SelectedItem != null && ddlDrug.SelectedValue.ToString() != "System.Data.DataRowView") { int brandid = 0; try { brandid = (int)ddlDrug.SelectedItem.Value; } catch { brandid = ((Drug)ddlDrug.SelectedItem.Value).BrandId; } if (brandid != 0) { try { Drug _drug = new DrugData().GetDrugById(brandid); txtCompany.Text = _drug.Company; txtContents.Text = _drug.DrugContent; txtFormulation.Text = _drug.Formulation; txtInstructions.Text = txtInstructions.Text + " " + _drug.Instructions; } catch { } } else { txtCompany.Text = ""; txtContents.Text = ""; txtFormulation.Text = ""; } } }
private void btnAddDrug_Click(object sender, EventArgs e) { string brandname = txtBrandName.Text.Trim(); if (brandname == "") { MessageBox.Show("Enter Brand Name"); return; } else { Drug drug = new Drug() { BrandName = brandname, Company = txtCompany.Text.Trim(), DrugContent = txtContents.Text.Trim(), Formulation = txtFormulation.Text.Trim(), Instructions = txtInstructions.Text.Trim(), CreatedOn = DateTime.Now }; bool result = new DrugData().Add(drug); if (result) { txtBrandName.Text = ""; txtImagingName.Text = ""; txtCompany.Text = ""; txtContents.Text = ""; txtFormulation.Text = ""; txtInstructions.Text = ""; MessageBox.Show("Drug added successfully"); } else { MessageBox.Show("Cannot add drug : contact Admin"); } } }
public static void PopulateDrug(RadDropDownList ddl) { try { List<Drug> drugs = new DrugData().GetDrugs(); drugs.Insert(0, new Drug() { BrandId = 0, BrandName = "Select" }); ddl.DataSource = drugs; ddl.ValueMember = "BrandId"; ddl.DisplayMember = "BrandName"; } catch (Exception x) { FileLogger.LogError(x); } }