Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 public DsMaster.INSURANCEDISCDataTable GetInsuranceByCust(string custid)
 {
     var ta = new DsMasterTableAdapters.INSURANCEDISCTableAdapter {Connection = {ConnectionString = _constr}};
     var ds = new DsMaster().INSURANCEDISC;
     ta.FillByCustNo(ds, custid);
     return ds;
 }