private CRMCustomerStatus GetSaveEntity()
        {
            var entity = new CRMCustomerStatus();

            if (string.IsNullOrEmpty(txtID.Text.Trim()) == false)
            {
                entity.ID = int.Parse(txtID.Text.Trim());
            }
            if (string.IsNullOrEmpty(txtCustStatus.Text.Trim()) == false)
            {
                entity.CustStatus = txtCustStatus.Text.Trim();
            }
            return(entity);
        }
Example #2
0
        //---------------保存CRMCustomerStatus---------------------------
        public CRMCustomerStatus Save(CRMCustomerStatus 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 CRMCustomerStatuss
                          where t.ID == entity.ID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                {
                    this.CopyEntity(obj, entity);
                }
                else
                {
                    this.CRMCustomerStatuss.InsertOnSubmit(entity);
                }

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return(entity);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
 private CRMCustomerStatus GetSaveEntity()
 {
     var entity = new CRMCustomerStatus();
     if (string.IsNullOrEmpty(txtID.Text.Trim()) == false)
         entity.ID = int.Parse(txtID.Text.Trim());
     if (string.IsNullOrEmpty(txtCustStatus.Text.Trim()) == false)
         entity.CustStatus = txtCustStatus.Text.Trim();
     return entity;
 }
        //---------------保存CRMCustomerStatus---------------------------
        public CRMCustomerStatus Save(CRMCustomerStatus 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 CRMCustomerStatuss
                          where t.ID == entity.ID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                    this.CopyEntity(obj, entity);
                else
                    this.CRMCustomerStatuss.InsertOnSubmit(entity);

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