示例#1
0
        private CRMCountry GetSaveEntity()
        {
            var entity = new CRMCountry();

            if (string.IsNullOrEmpty(txtCountryID.Text.Trim()) == false)
            {
                entity.CountryID = int.Parse(txtCountryID.Text.Trim());
            }
            if (string.IsNullOrEmpty(txtCountry.Text.Trim()) == false)
            {
                entity.Country = txtCountry.Text.Trim();
            }
            return(entity);
        }
示例#2
0
        //---------------保存CRMCountry---------------------------
        public CRMCountry Save(CRMCountry entity)
        {
            if (this.dataCtx.Connection != null)
            {
                this.dataCtx.Connection.Open();
            }
            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 CRMCountrys
                          where t.CountryID == entity.CountryID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                {
                    this.CopyEntity(obj, entity);
                }
                else
                {
                    this.CRMCountrys.InsertOnSubmit(entity);
                }

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return(entity);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
示例#3
0
        //---------------保存CRMCountry---------------------------
        public CRMCountry Save(CRMCountry entity)
        {
            if (this.dataCtx.Connection != null) this.dataCtx.Connection.Open(); 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 CRMCountrys
                          where t.CountryID == entity.CountryID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                    this.CopyEntity(obj, entity);
                else
                    this.CRMCountrys.InsertOnSubmit(entity);

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return entity;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
示例#4
0
 private CRMCountry GetSaveEntity()
 {
     var entity = new CRMCountry();
     if (string.IsNullOrEmpty(txtCountryID.Text.Trim()) == false)
         entity.CountryID = int.Parse(txtCountryID.Text.Trim());
     if (string.IsNullOrEmpty(txtCountry.Text.Trim()) == false)
         entity.Country = txtCountry.Text.Trim();
     return entity;
 }