Ejemplo n.º 1
0
 public string DoSaveDrugDispatch(DsMaster.DDMASTRow drow,DsMaster.DDDETAILSDataTable dtTable)
 {
     string retval = string.Empty;
     SqlTransaction tran = null;
     var cn = new SqlConnection(_constr);
     try
     {
         cn.Open();
         var tadet = new  DsMasterTableAdapters.DDDETAILSTableAdapter() ;
         var tam = new DsMasterTableAdapters.DDMASTTableAdapter {Connection = {ConnectionString = _constr}};
         var dt = new DsMaster().DDMAST;
         tam.Fill(dt);
         tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted);
         tam.AssignConnection(cn, tran);
         tadet.AssignConnection(cn, tran);
         bool isnew = false;
         var dr = dt.FindByDNO(drow.DNO);
         if (dr != null)
         {
             dr.BeginEdit();
             Utils.DosageNo = drow.DNO;
         }
         else
         {
             isnew = true;
             var autoid = new DataManager().GetAutoId(19);
             autoid++;
             Utils.DosageNo = new DataManager().CreateFormatedAutoNo(autoid);
             dr = (DsMaster.DDMASTRow) dt.NewRow();
             dr.DNO = Utils.DosageNo;
             dr.PATNAME = drow.PATNAME;
             dr.HOSPITAL = drow.HOSPITAL;
             dr.DOCTOR = drow.DOCTOR;
             dr.TDATE = drow.TDATE;
             dr.COMP = drow.COMP;
         }
         foreach (DsMaster.DDDETAILSRow crow in dtTable.Rows)
         {
             crow.DNO = Utils.DosageNo;
         }
         if (isnew)
         {
             dt.Rows.Add(dr);
             tam.Update(dt);
         }
         else
         {
             dr.EndEdit();
             tam.Update(dt);
         }
         tadet.Update( dtTable);
         new DataManager().UpdateAutoNum(19);
         tran.Commit();
         retval = "1";
     }
     catch (Exception ex)
     {
         retval = ex.ToString();
         if (tran != null && cn.State == ConnectionState.Open)
         {
             tran.Rollback();
         }
     }
     return retval;
 }