Esempio n. 1
0
        private CRMCustomerFrom GetSaveEntity()
        {
            var entity = new CRMCustomerFrom();

            if (string.IsNullOrEmpty(txtID.Text.Trim()) == false)
            {
                entity.ID = int.Parse(txtID.Text.Trim());
            }
            if (string.IsNullOrEmpty(txtCustFrom.Text.Trim()) == false)
            {
                entity.CustFrom = txtCustFrom.Text.Trim();
            }
            return(entity);
        }
Esempio n. 2
0
        //---------------保存CRMCustomerFrom---------------------------
        public CRMCustomerFrom Save(CRMCustomerFrom entity)
        {
            if (this.dataCtx.Connection != null)
            {
                if (this.dataCtx.Connection.State == ConnectionState.Closed)
                {
                    this.dataCtx.Connection.Open();
                }
            }
            DbTransaction tran = this.dataCtx.Connection.BeginTransaction();

            dataCtx.Transaction = tran;

            try
            {
                var qry = from t in CRMCustomerFroms
                          where t.ID == entity.ID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                {
                    this.CopyEntity(obj, entity);
                }
                else
                {
                    this.CRMCustomerFroms.InsertOnSubmit(entity);
                }

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return(entity);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
Esempio n. 3
0
        //---------------保存CRMCustomerFrom---------------------------
        public CRMCustomerFrom Save(CRMCustomerFrom entity)
        {
            if (this.dataCtx.Connection != null)
                if (this.dataCtx.Connection.State == ConnectionState.Closed)
                    this.dataCtx.Connection.Open();
            DbTransaction tran = this.dataCtx.Connection.BeginTransaction();
            dataCtx.Transaction = tran;

            try
            {
                var qry = from t in CRMCustomerFroms
                          where t.ID == entity.ID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                    this.CopyEntity(obj, entity);
                else
                    this.CRMCustomerFroms.InsertOnSubmit(entity);

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return entity;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }