Ejemplo n.º 1
0
        //传入Sql语句事务测试
        private bool InSqlTransactionTest(string mainId, string detailId)
        {
            //可以支持任意流行数据库类型,指定相关的数据库提供者即可(OracleProvider、SqlProvider、SqLiteProvider、MySqlProvider、DB2Provider、OleDbProvider)

            IDbProvider dbProvider = new SqlProvider(SystemInfo.BusinessDbConnectionString);
            bool        result     = true;

            try
            {
                dbProvider.BeginTransaction();
                //主表
                string sqlMain = string.Format("DELETE FROM CASE_PRODUCTIN_MAIN WHERE ID = {0}", mainId);
                dbProvider.ExecuteNonQuery(sqlMain);
                //子表
                string sqlDetail = string.Format("DELETE FROM CASE_PRODUCTIN_DETAIL WHERE ID = {0}", detailId);
                dbProvider.ExecuteNonQuery(sqlMain);
                //事务提交 
                dbProvider.CommitTransaction();
            }
            catch (Exception ex)
            {
                //事务回滚
                dbProvider.RollbackTransaction();
                result = false;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public override int Delete(object instanceId)
        {
            int         sonuc    = 0;
            SqlProvider provider = new SqlProvider("Pr_ProductDelete", true);

            provider.AddParameter("@ProductID", instanceId);
            sonuc = provider.ExecuteNonQuery();
            return(sonuc);
        }
Ejemplo n.º 3
0
        public override int Save(Category instance)
        {
            int         sonuc    = 0;
            SqlProvider provider = new SqlProvider("Pr_CategoryInsert", true);

            provider.AddParameter("@CategoryName", instance.CategoryName);
            provider.AddParameter("@Description", instance.Description);

            sonuc = provider.ExecuteNonQuery();
            return(sonuc);
        }
Ejemplo n.º 4
0
        public override int Save(Product instance)
        {
            int         sonuc    = 0;
            SqlProvider provider = new SqlProvider("Pr_ProductInsert", true);

            provider.AddParameter("@ProductName", instance.ProductName);
            provider.AddParameter("@CategoryID", instance.CategoryID);
            provider.AddParameter("@UnitPrice", instance.UnitPrice);
            provider.AddParameter("@UnitsInStock", instance.UnitsInStock);

            sonuc = provider.ExecuteNonQuery();
            return(sonuc);
        }
Ejemplo n.º 5
0
        public int Insert()
        {
            UretimTalepid = SiraNo.SiraNoVer("URETIMTALEP");

            _sqlProvider = new SqlProvider("INSERT INTO URETIMTALEP (URETIMTALEPID,DURUM,TARIH,TESLIMTARIHI,DEPOID,YETKILI,ACIKLAMA)  VALUES (@URETIMTALEPID,@DURUM,@TARIH,@TESLIMTARIHI,@DEPOID,@YETKILI,@ACIKLAMA) ", false);
            _sqlProvider.AddParameter("URETIMTALEPID", UretimTalepid);
            _sqlProvider.AddParameter("DURUM", Durum);
            _sqlProvider.AddParameter("TARIH", Tarih);
            _sqlProvider.AddParameter("TESLIMTARIHI", TeslimTarihi);
            _sqlProvider.AddParameter("DEPOID", Depoid);
            _sqlProvider.AddParameter("YETKILI", Yetkili);
            _sqlProvider.AddParameter("ACIKLAMA", Aciklama);
            _sqlProvider.ExecuteNonQuery();
            return(UretimTalepid);
        }
Ejemplo n.º 6
0
        internal SmcsContext(string conStr) : base(conStr)
        {
            if (!Database.Exists())
            {
                this.Configuration.AutoDetectChangesEnabled = false;

                try
                {
                    this.Database.Create();
                    new access.DbSupplier(this).SeedDbWithInitalData();
                    SqlProvider.ExecuteNonQuery("ALTER DATABASE " + this.Database.Connection.Database +
                                                " COLLATE Persian_100_CI_AI");
                }
                catch (Exception e)
                {
                    e.Log();
                }
            }

            this.Configuration.AutoDetectChangesEnabled = true;
        }
Ejemplo n.º 7
0
 public string Insert()
 {
     try
     {
         _sqlProvider = new SqlProvider("INSERT INTO URETIMTALEPISL (URETIMTALEPID,STOKID,BIRIM,MIKTAR,DEPOMIKTAR,MINMIKTAR,TAVMIKTAR,PRCMIKTAR,KULMIKTAR,ACIKLAMA,BARKOD)  VALUES (@URETIMTALEPID,@STOKID,@BIRIM,@MIKTAR,@DEPOMIKTAR,@MINMIKTAR,@TAVMIKTAR,@PRCMIKTAR,@KULMIKTAR,@ACIKLAMA,@BARKOD) ", false);
         _sqlProvider.AddParameter("URETIMTALEPID", UretimTalepid);
         _sqlProvider.AddParameter("STOKID", Stokid);
         _sqlProvider.AddParameter("BIRIM", Birim);
         _sqlProvider.AddParameter("MIKTAR", Miktar);
         _sqlProvider.AddParameter("DEPOMIKTAR", DepoMiktar);
         _sqlProvider.AddParameter("MINMIKTAR", MinMiktar);
         _sqlProvider.AddParameter("TAVMIKTAR", TavMiktar);
         _sqlProvider.AddParameter("PRCMIKTAR", PrcMiktar);
         _sqlProvider.AddParameter("KULMIKTAR", KulMiktar);
         _sqlProvider.AddParameter("ACIKLAMA", Aciklama);
         _sqlProvider.AddParameter("BARKOD", Barkod);
         _sqlProvider.ExecuteNonQuery();
         return("OK");
     }
     catch (Exception e)
     {
         return(e.InnerException.Message);
     }
 }
Ejemplo n.º 8
0
        public void UpdateSql(Entity target)
        {
            var type  = target.LogicalName;
            var table = type; // + "ExtensionBase";

            var fieldsToUpdate = new List <KeyValuePair <string, string> >();

            foreach (var field in target.GetFieldsInEntity())
            {
                var fieldType = XrmService.GetFieldType(field, type);
                var value     = target.GetField(field);
                if (value == null)
                {
                    if (fieldType == AttributeTypeCode.Money)
                    {
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field + "_base", "null"));
                    }
                    fieldsToUpdate.Add(new KeyValuePair <string, string>(field, "null"));
                }
                else
                {
                    switch (fieldType)
                    {
                    case AttributeTypeCode.DateTime:
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field,
                                                                             SqlProvider.ToSqlDateString((DateTime)value)));
                        break;

                    case AttributeTypeCode.Money:
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field,
                                                                             XrmEntity.GetMoneyValue(value).ToString(CultureInfo.InvariantCulture)));
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field + "_base",
                                                                             XrmEntity.GetMoneyValue(value).ToString(CultureInfo.InvariantCulture)));
                        break;

                    case AttributeTypeCode.Lookup:
                        var id = XrmEntity.GetLookupGuid(value);
                        if (!id.HasValue)
                        {
                            throw new NullReferenceException("error no id in " + field);
                        }
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field,
                                                                             WrapSqlString(id.Value.ToString())));
                        break;

                    case AttributeTypeCode.Picklist:
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field,
                                                                             XrmEntity.GetOptionSetValue(value).ToString(CultureInfo.InvariantCulture)));
                        break;

                    case AttributeTypeCode.Status:
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field,
                                                                             XrmEntity.GetOptionSetValue(value).ToString(CultureInfo.InvariantCulture)));
                        break;

                    case AttributeTypeCode.Integer:
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field, value.ToString()));
                        break;

                    case AttributeTypeCode.Decimal:
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field, value.ToString()));
                        break;

                    case AttributeTypeCode.Boolean:
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field,
                                                                             XrmEntity.GetBoolean(value) ? "1" : "0"));
                        break;

                    case AttributeTypeCode.String:
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field,
                                                                             SqlProvider.ToSqlString((string)value)));
                        break;

                    case AttributeTypeCode.Memo:
                        fieldsToUpdate.Add(new KeyValuePair <string, string>(field,
                                                                             SqlProvider.ToSqlString((string)value)));
                        break;

                    case AttributeTypeCode.Uniqueidentifier:
                        break;

                    default:
                        throw new NotImplementedException("No update logic implemented for field type " + fieldType);
                    }
                }
            }
            var setStrings = string.Join(",",
                                         fieldsToUpdate.Select(kv => string.Format("{0} = {1}", kv.Key, kv.Value)));
            var primaryKey    = XrmService.GetPrimaryKeyField(target.LogicalName);
            var primaryKeySql = SqlProvider.ToSqlString(target.Id);
            var sql           = string.Format("update {0} set {1} where {2} = {3}", table, setStrings, primaryKey, primaryKeySql);

            SqlProvider.ExecuteNonQuery(sql);
        }
Ejemplo n.º 9
0
 public void ExecuteSql(string sql, SqlProvider service, SqlTransaction transaction)
 {
     service.ExecuteNonQuery(sql, transaction);
 }