Пример #1
0
    protected void updateMedicine(object sender, GridViewUpdateEventArgs e)
    {
        this.gvMedicine.Columns[1].Visible = true;
        int?   MedicineCatID     = 0;
        int?   MedicineCompanyID = 0;
        string MedicineID        = ((Label)gvMedicine.Rows[e.RowIndex].FindControl("editlblMedicineID")).Text;
        string MedicineName      = ((TextBox)gvMedicine.Rows[e.RowIndex].FindControl("edittxtMedicineName")).Text;
        string Price             = ((TextBox)gvMedicine.Rows[e.RowIndex].FindControl("edittxtPrice")).Text;
        string MedicineCatName   = ((DropDownList)gvMedicine.Rows[e.RowIndex].FindControl("editMedicineCategoryName")).Text;

        //dc.GetMedcineCategoryID(MedicineCatName, ref MedicineCatID);
        dc.GetMedicineCategoryID(MedicineCatName, ref MedicineCatID);
        string MedicineCompanyName = ((DropDownList)gvMedicine.Rows[e.RowIndex].FindControl("editMedicineCompanyName")).Text;

        dc.GetMedicineCompanyID(MedicineCompanyName, ref MedicineCompanyID);

        string ManufactureDate = ((TextBox)gvMedicine.Rows[e.RowIndex].FindControl("edittxtManufactureDate")).Text;
        string ExpiryDate      = ((TextBox)gvMedicine.Rows[e.RowIndex].FindControl("edittxtExpiryDate")).Text;
        string Amount          = ((TextBox)gvMedicine.Rows[e.RowIndex].FindControl("edittxtAmount")).Text;
        var    q = from medi in dc.Medicine_In_Stocks
                   where medi.MedicineID == Convert.ToInt32(MedicineID)
                   select medi;

        foreach (Medicine_In_Stock mis in q)
        {
            mis.MedicineName       = MedicineName;
            mis.Price              = Convert.ToDecimal(Price);
            mis.MedicineCategoryID = MedicineCatID;
            mis.MedicineCompanyID  = MedicineCompanyID;
            mis.ManufactureDate    = Convert.ToDateTime(ManufactureDate);
            mis.ExpiryDate         = Convert.ToDateTime(ExpiryDate);
            mis.Amount             = Convert.ToDecimal(Amount);
        }
        try
        {
            dc.SubmitChanges();
        }
        catch (Exception ex)
        {
            lblerr.Text = ex.ToString();
        }
        gvMedicine.EditIndex = -1;
        BindGridDataMedicine();
    }