Exemplo n.º 1
0
 public string DoDownLoadCustomer()
 {
     string retval = "1";
     var _remotecustomer = new Customer().GetCustomerMembersDataTable(true, _syncConstr);
     var ds = new DsMaster().CUSTOMER;
     var taCustomer = new DsMasterTableAdapters.CUSTOMERTableAdapter{Connection = { ConnectionString = Utils.Connectionstring } };
     taCustomer.Fill(ds);
     foreach (DataRow dr in _remotecustomer.Rows)
     {
         var isnew = false;
         var dsup = ds.FindByCUSTNO(dr["CUSTNO"].ToString());
         if (dsup != null)
         {
             dsup.BeginEdit();
         }
         else
         {
             dsup = (DsMaster.CUSTOMERRow)ds.NewRow();
             isnew = true;
             foreach (DataColumn dc in _remotecustomer.Columns)
             {
                 if (dc.ColumnName == "CUSTOMERPOINT")
                 {
                     dsup[dc.ColumnName] = 0;
                 }
                 else
                 {
                     dsup[dc.ColumnName] = dr[dc.ColumnName];
                 }
             }
         }
         bool update = true;
         if (!isnew)
         {
             update = Equals(dr, dsup);
         }
         if (!update)
         {
             foreach (DataColumn dc in _remotecustomer.Columns)
             {
                 if (dc.ColumnName == "CUSTOMERPOINT")
                 {
                     dsup[dc.ColumnName] = 0;
                 }
                 else
                 {
                     dsup[dc.ColumnName] = dr[dc.ColumnName];
                 }
             }
         }
         if (isnew)
         {
             ds.Rows.Add(dsup);
             var t = taCustomer.Update(ds);
             if (t == 0)
                 retval += "Customer master not created";
         }
         else
         {
             dsup.EndEdit();
             taCustomer.Update(dsup);
         }
     }
     return retval;
 }
Exemplo n.º 2
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;
        }