Example #1
0
        private CRMCustomerEmpNum GetSaveEntity()
        {
            var entity = new CRMCustomerEmpNum();

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

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

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