public string DoSave() { string retval=string.Empty; SqlTransaction tran = null; var isnew = false; try { var cn = new SqlConnection {ConnectionString = _constr}; cn.Open(); tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted); var dt = new DsMaster().CUSTOMER; var ta = new DsMasterTableAdapters.CUSTOMERTableAdapter {Connection = {ConnectionString = _constr}}; ta.Fill(dt); ta.AssignConnection(cn, tran); var tains = new DsMasterTableAdapters.INSURANCEDISCTableAdapter {Connection = {ConnectionString = _constr}}; tains.AssignConnection(cn, tran); var dr = dt.FindByCUSTNO(customerRow.CUSTNO); if (dr != null) { dr.BeginEdit(); Utils.CustomerNo = customerRow.CUSTNO; dr.EUSERID = Utils.Userid; dr.EDATE = DateTime.Now.Date; } else { dr = (DsMaster.CUSTOMERRow) dt.NewRow(); isnew = true; var autoid = new DataManager().GetAutoId(13); autoid++; Utils.CustomerNo = new DataManager().CreateFormatedAutoNo(autoid); dr.CUSTNO = Utils.CustomerNo; dr.CUSERID = Utils.Userid; dr.CDATE = DateTime.Now.Date; } dr.CUSTOMERTYPE = customerRow.CUSTOMERTYPE; dr.CUSTOMERNAME = customerRow.CUSTOMERNAME; dr.CUSTCOMP = customerRow.CUSTCOMP; dr.CUSTOMERID = customerRow.CUSTOMERID; dr.PHONE = customerRow.PHONE; dr.Mobile = customerRow.Mobile; dr.EMAIL = customerRow.EMAIL; dr.NOTE = customerRow.NOTE; dr.FIXDISC = customerRow.FIXDISC; dr.FIXDISCAMTPER = customerRow.FIXDISCAMTPER; dr.CREDITLIMIT = customerRow.CREDITLIMIT; dr.COMPANY = Utils.Company; dr.PAYTYPE = customerRow.PAYTYPE; dr.MEMBERNO = customerRow.MEMBERNO; if (isnew) { dt.Rows.Add(dr); ta.Update(dt); } else { dr.EndEdit(); ta.Update(dt); } if (insurancediscDataTable != null) { foreach (DsMaster.INSURANCEDISCRow di in insurancediscDataTable.Rows) { di.CUSTNO = Utils.CustomerNo; } tains.Update(insurancediscDataTable); } tran.Commit(); new DataManager().UpdateAutoNum(13); retval = "1"; } catch (Exception ex) { retval = ex.ToString(); if (tran != null) tran.Rollback(); } return retval; }
public string UpdateCustomerPoints(string custno, decimal points, string sqlsync) { string retval = "1"; SqlTransaction tran = null; try { var cn = new SqlConnection(sqlsync); cn.Open(); tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted); var ta = new DsMasterTableAdapters.CUSTOMERTableAdapter(); ta.AssignConnection(cn, tran); ta.UpdateCustomerPoints(points, custno); tran.Commit(); } catch (Exception ex) { if (tran != null) tran.Rollback(); retval = ex.ToString(); } return retval; }