public override void Initialize() { base.Initialize(); Login.User user = (Login.User)Session["user"]; Context["socketurl"] = IOUtils.SocketIOUrl; Context["uid"] = Cuid.NewCuid().ToString(); }
public void CuidsAreSlowerThanNativeGuids() { var toGen = Math.Pow(36, 4) + 1; var sw = new Stopwatch(); sw.Start(); for (double i = 0; i < toGen; i++) { Cuid.Generate(); } sw.Stop(); var elapsedCuid = sw.ElapsedTicks; sw.Reset(); sw.Start(); for (double i = 0; i < toGen; i++) { Guid.NewGuid(); } sw.Stop(); var elapsedGuid = sw.ElapsedTicks; Assert.False(elapsedGuid > elapsedCuid); }
public void Save(IHashObject data) { using (DbHelper db = AppUtils.CreateDbHelper()) { IHashObject section = db.SelectFirstRow(string.Format("select id, paytotal from backsection where month='{0}-1'", data["tmonth"])); if (section == null) { throw new Exception(string.Format("{0}月不存在回款金额", data["tmonth"])); } data["datetime"] = DateTime.Now; data["id"] = Cuid.NewCuid(); data["uid"] = ((Login.User)Session["user"]).Id; data.Remove("tmonth"); section["paytotal"] = section.GetValue <decimal>("paytotal") + data.GetValue <decimal>("total"); try { db.BeginTransaction(); db.Insert("backsectionDetail", data); db.Update("backsection", "id", section);//更新金额 db.CommitTransaction(); } catch (Exception e) { if (db.HasBegunTransaction) { db.RollbackTransaction(); } } } }
public void PopulateDictionary() { SQLiteDatabase db = new SQLiteDatabase("c:\\temp", "EnglishDictionary"); db.TryEnsureSchema <Word>(); string urlTemplate = "http://www.mso.anu.edu.au/~ralph/OPTED/v003/wb1913_{0}.html"; Parallel.ForEach(Bam.Net.Extensions.LowerCaseLetters, (letter) => { Console.WriteLine("Getting letter: {0}", letter); string html = Http.Get(string.Format(urlTemplate, letter)); CQ cq = CQ.Create(html); var paragraphs = cq["p", cq]; Parallel.ForEach(paragraphs, (p) => { string word = cq["b", p].Text(); string wordType = cq["i", p].Text(); string definition = p.InnerText.TrimNonLetters(); Word wordEntry = GetWordEntry(word, db); Definition definitionEntry = wordEntry.DefinitionsByWordId.AddNew(); definitionEntry.Cuid = Cuid.Generate(); definitionEntry.WordType = wordType; definitionEntry.Value = definition; definitionEntry.Save(db); Console.WriteLine("Saved definition for {0} {1}", word, wordType); Console.WriteLine("*** {0}", definition); }); }); Thread.Sleep(5000); }
public static void Init() { JavaScriptSerializer serializer = JavaScriptSerializer.CreateInstance(); socket.On(Socket.EVENT_CONNECT, () => { IsConnected = true; Data data = new Data("server"); data.comefrom = "net"; socket.Emit("login", serializer.Serialize(data)); }); socket.On("postDataRequest", (data) => { HashObject hash = serializer.Deserialize <HashObject>(data.ToString()); SendMsg nmsg = new SendMsg("server"); nmsg.comefrom = "net"; nmsg.touid = hash.GetValue <string>("fuid"); ulong key = Cuid.NewCuid(); Counter counter = new Counter(); counter.All = hash.GetValue <ulong>("msg"); counter.Doned = 0; PostDataRequestList.Add(key, counter); nmsg.msg = key.ToString();//回传一个唯一标记 socket.Emit("postDataSure", serializer.Serialize(nmsg)); }); IsConnected = false; }
static TranslationProvider() { Action <Dao> setCuid = (dao) => dao.Property("Cuid", Cuid.Generate()); Dao.PostConstructActions.AddMissing(typeof(Language), setCuid); Dao.PostConstructActions.AddMissing(typeof(LanguageDetection), setCuid); Dao.PostConstructActions.AddMissing(typeof(Text), setCuid); Dao.PostConstructActions.AddMissing(typeof(OtherName), setCuid); Dao.PostConstructActions.AddMissing(typeof(Translation), setCuid); }
private Word GetWordEntry(string word, SQLiteDatabase db) { Word wordEntry = Word.FirstOneWhere(w => w.Value == word, db); if (wordEntry == null) { wordEntry = new Word { Value = word, Cuid = Cuid.Generate() }; wordEntry.Save(db); } return(wordEntry); }
public void SlugTest() { var slug = Cuid.Slug(); var slugSecure = Cuid.Slug(RandomSource.Secure); Debug.WriteLine(slug); Debug.WriteLine(slugSecure); Assert.InRange(slug.Length, 7, 10); Assert.InRange(slugSecure.Length, 7, 10); Assert.Throws <IndexOutOfRangeException>(() => Cuid.Slug((RandomSource)3)); }
public void GenerateTest() { var cuid = Cuid.Generate(); var cuidSecure = Cuid.Generate(RandomSource.Secure); Debug.WriteLine(cuid); Debug.WriteLine(cuidSecure); Assert.Equal(25, cuid.Length); Assert.Equal(25, cuidSecure.Length); Assert.Throws <IndexOutOfRangeException>(() => Cuid.Generate((RandomSource)3)); }
private void Init() { _dynamicResponders = new Dictionary <string, Func <string, bool, string> >(); _dynamicResponders.Add("proxies", Proxies); _dynamicResponders.Add("ctors", Ctors); _dynamicResponders.Add("templates", Templates); Dao.BeforeWriteCommitAny += (db, dao) => { dao.PropertyIfNullOrBlank("Created", DateTime.UtcNow, false); dao.PropertyIfNullOrBlank("Uuid", Guid.NewGuid().ToString(), false); dao.PropertyIfNullOrBlank("Cuid", Cuid.Generate(), false); dao.Property("Modified", DateTime.UtcNow, false); }; }
public void Save(string user, object[] grid) { using (DbHelper db = AppUtils.CreateDbHelper()) { StringBuilder sbuilder = new StringBuilder("insert into commissionrate (crid,color,size,sourceTitle,rate,uname) values"); foreach (HashObject hash in grid) { sbuilder.AppendFormat("({0},'{1}','{2}','{3}',{4},'{5}'),", Cuid.NewCuid(), hash["color"], hash["size"], hash["sourceTitle"], hash["rate"], hash["uname"]); } db.BatchExecute(sbuilder.ToString().Substring(0, sbuilder.Length - 1)); DataCatchSave.ClearUserGoodsCache(user); Login login = new Login(); login.ReBillCatch(user); } }
private static List <string> DeleteOldData(Plug plug, DbHelper db, HashObject hash) { List <string> rtlist = new List <string>(); if (plug.PId == 0) { plug.PId = Cuid.NewCuid(); return(rtlist); } db.AddParameter("pid", plug.PId); IHashObject item = db.SelectSingleRow("select pdownpath,pvideo,picon,ppics,pcreatedate,ptotal from plugs where pid=@pid"); foreach (string key in item.Keys) { string path = item.GetValue <string>(key); if (string.IsNullOrEmpty(path)) { continue; } if (key == "ppics") { foreach (string item1 in path.Split(',')) { if (string.IsNullOrEmpty(item1) || item1.StartsWith(saveFileFolder)) { continue; } rtlist.Add(string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, item1)); } } else { if (hash.GetValue <string>(key) == item.GetValue <string>(key)) { continue; } if (string.IsNullOrEmpty(hash.GetValue <string>(key))) { hash[key] = item[key]; } rtlist.Add(string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, item[key])); } } hash["pcreatedate"] = item["pcreatedate"]; hash["ptotal"] = item["ptotal"]; db.Delete("plugs", "pid", plug.PId); return(rtlist); }
public void Save(IHashObject data) { using (DbHelper db = AppUtils.CreateDbHelper()) { data["datetime"] = DateTime.Now; data["id"] = Cuid.NewCuid(); data["uid"] = ((Login.User)Session["user"]).Id; IHashObject section = db.SelectFirstRow(string.Format("select id from backsectionDetail where month='{0}'", data["month"])); if (section != null) { throw new Exception(string.Format("{0}月已设置回款金额,如需继续,请联系管理员", data["month"])); } db.Insert("backsection", data); } }
private void button3_Click(object sender, EventArgs e) { var data = dataGridView1.DataSource as DataTable; if (data.Rows.Count == 0) { return; } using (DbHelper db = new DbHelper(Utils.Connect, true)) { if (isAdd) { StringBuilder sbuilder = new StringBuilder("insert into commissionrate (crid,color,size,sourceTitle,rate,uname) values"); foreach (DataRow row in data.Rows) { sbuilder.AppendFormat("({0},'{1}','{2}','{3}',{4},'{5}'),", Cuid.NewCuid(), row["color"], row["size"], row["sourceTitle"], row["rate"], row["uname"]); } db.BatchExecute(sbuilder.ToString().Substring(0, sbuilder.Length - 1)); } else { try { db.BeginTransaction(); string sql = "update commissionrate set rate=@rate where crid=@crid"; foreach (DataRow row in data.Rows) { db.AddParameter("rate", row["rate"]); db.AddParameter("crid", row["crid"]); db.ExecuteIntSQL(sql); } db.CommitTransaction(); } catch (Exception t) { if (db.HasBegunTransaction) { db.RollbackTransaction(); } } } } MessageBox.Show("数据操作成功"); }
public void NoSlugReasonableCollisionTest() { var l = new HashSet <string>(); for (var i = 0; i <= 1200000; i++) { var gen = Cuid.Slug(); Assert.False(l.Contains(gen)); Assert.True(l.Add(gen)); } l.Clear(); for (var i = 0; i <= 1200000; i++) { var gen = Cuid.Slug(RandomSource.Secure); Assert.False(l.Contains(gen)); Assert.True(l.Add(gen)); } }
public void BillCatchDemo(string user, ulong key, IList dataList) { if (!IOUtils.IsPostDataRequest(key, (ulong)dataList.Count)) { throw new Exception("抓取数据未被验证,非法请求"); } IList list = GetAllList(key, dataList); if (IOUtils.HasKey(key)) { dataList.Clear(); return;//还有未传完的数据 } backDemoDataList.Remove(key);//清除备份,做一次性数据处理 string comefrom = string.Format("数据分析_{0}", DateTime.Now.GetHashCode()); Data data = new Data(user); data.comefrom = comefrom; IOUtils.Emit("login", JavaScriptSerializer.CreateInstance().Serialize(data)); HashObject hash = DataCatchSave.AnalysisData(user, list, (text) => { IOUtils.Emit("sendMsg", GetMessage(user, comefrom, text)); }); if (hash == null) { return; } string id = Cuid.NewCuid().ToString(); DataCatchFromTBExample.SetTempData(id, hash); IOUtils.Emit("sendMsg", GetMessage(user, comefrom, string.Format("OK:url:{0}", id))); }
public static void Init() { JavaScriptSerializer serializer = JavaScriptSerializer.CreateInstance(); socket.On(Socket.EVENT_CONNECT, () => { IsConnected = true; Data data = new Data("server"); data.comefrom = "net"; socket.Emit("login", serializer.Serialize(data)); }); socket.On("postDataRequest", (data) => { HashObject hash = serializer.Deserialize <HashObject>(data.ToString()); SendMsg nmsg = new SendMsg("server"); nmsg.comefrom = "net"; nmsg.touid = hash.GetValue <string>("fuid"); ulong key = Cuid.NewCuid(); Counter counter = new Counter(); counter.All = hash.GetValue <ulong>("msg"); counter.Doned = 0; PostDataRequestList.Add(key, counter); nmsg.msg = key.ToString();//回传一个唯一标记 socket.Emit("postDataSure", serializer.Serialize(nmsg)); }); socket.On("consultationEnabledUpdate", (data) =>//咨询是否允许更新 { HashObject hash = serializer.Deserialize <HashObject>(data.ToString()); SendMsg nmsg = new SendMsg("server"); nmsg.comefrom = "net"; nmsg.touid = hash.GetValue <string>("fuid"); string key = hash.GetValue <string>("msg"); nmsg.msg = WebInterface.SureUpdateIds.Contains(key) ? "1" : "0"; WebInterface.SureUpdateIds.Remove(key); socket.Emit("sureEnabledUpdate", serializer.Serialize(nmsg)); //确认可以做什么操作 }); socket.On("getLoginToken", (data) => //客户端登录 { HashObject hash = serializer.Deserialize <HashObject>(data.ToString()); SendMsg nmsg = new SendMsg("server"); nmsg.comefrom = "net"; nmsg.touid = hash.GetValue <string>("fuid"); try { string key = Guid.NewGuid().ToString().Replace("-", ""); nmsg.msg = key; using (DbHelper db = AppUtils.CreateDbHelper()) { string sql = "insert into logintoken (`user`, `token`,updatedate) values(@user, @token,@updatedate) on duplicate key update `token` = values(`token`),`updatedate` = values(`updatedate`);"; db.AddParameter("user", hash.GetValue <string>("msg")); db.AddParameter("token", key); db.AddParameter("updatedate", DateTime.Now); db.ExecuteIntSQL(sql); } socket.Emit("sendLoginToken", serializer.Serialize(nmsg));//确认可以做什么操作 } catch (Exception e) { nmsg.msg = string.Format("Exception:{0}", e.Message); socket.Emit("sendLoginToken", serializer.Serialize(nmsg));//确认可以做什么操作 } }); socket.On("getDownDataToken", (data) => { HashObject hash = serializer.Deserialize <HashObject>(data.ToString()); SendMsg nmsg = new SendMsg("server"); nmsg.comefrom = "net"; nmsg.touid = hash.GetValue <string>("fuid"); try { string key = Guid.NewGuid().ToString().Replace("-", ""); nmsg.msg = key; string conditionMsg = hash.GetValue <string>("msg"); HashObject condition = serializer.Deserialize <HashObject>(conditionMsg); using (DbHelper db = AppUtils.CreateDbHelper()) { string sql = "insert into downtoken (`user`, `token`,getDate, `condition`) values(@user, @token,@getDate, @condition) on duplicate key update `token` = values(`token`),`getDate` = values(`getDate`),`condition` = values(`condition`);"; db.AddParameter("user", condition.GetValue <string>("user")); db.AddParameter("token", key); db.AddParameter("getDate", DateTime.Now); db.AddParameter("condition", conditionMsg); db.ExecuteIntSQL(sql); } socket.Emit("sendDownDataToken", serializer.Serialize(nmsg));//确认可以做什么操作 } catch (Exception e) { nmsg.msg = string.Format("Exception:{0}", e.Message); socket.Emit("sendLoginToken", serializer.Serialize(nmsg));//确认可以做什么操作 } }); IsConnected = false; }
private static void BuildBillDataFromTable(string suser, bool onlyAdd, DataTable table, HashObjectList billList, HashObjectList detailList, DbHelper db = null, string ids = null, bool sureRate = true) { Dictionary <string, string> dic = GetExistBills(db, ids); List <string> dicDetail = GetExistBillDetails(db, ids); JavaScriptSerializer serializer = JavaScriptSerializer.CreateInstance(); foreach (DataRow row in table.Rows) { var ddid = row["订单ID"].ToString(); string id = Cuid.NewCuid().GetHashCode().ToString(); string oldid; if (dic.TryGetValue(ddid, out oldid)) { if (onlyAdd) { continue; } id = oldid; } string user = row["所属用户"].ToString(); if (user != suser) { throw new Exception("分析用户和数据保存用户不匹配,无法做数据保存"); } object sendDate = row["发货时间"]; object successDate = row["成交时间"]; Dictionary <string, decimal> goodsRate = GetGoodsRate(db, user); GoodsInfo[] ginfos = serializer.Deserialize <GoodsInfo[]>(row["货物信息"].ToString()); var sendWay = TaobaoDataHelper.GetLogisticsInfo(row["快递公司"]).IsEmptyObject() ? null : "快递"; string remark = GetRemark(row); decimal pall = Decimal.Parse(row["拍下总金额"].ToString()); decimal total = Decimal.Parse(row["支付金额"].ToString()); decimal ltotal = 0; decimal btotal = 0; decimal allPrice = 0; string address = TaobaoDataHelper.ReplaceHtmlText(row["具体地址"].ToString()); if (!dicDetail.Contains(ddid)) { for (int j = ginfos.Length - 1; j >= 0; j--) { GoodsInfo ginfo = ginfos[j]; string goodKey = GetGoodsKey(ginfo.Color, ginfo.Size, ginfo.Title); decimal rate = 0; if (db != null && (goodsRate == null || !goodsRate.ContainsKey(goodKey))) { if (!sureRate) { rate = 0; } else { throw new Exception(string.Format("【{3}】 color:{0} size:{1} title:{2}没有设置比例goodMatchRate", ginfo.Color, ginfo.Size, ginfo.Title, user)); } } else { if (db != null) { rate = goodsRate[goodKey]; } } decimal price = ginfo.PriceInfo / pall * total; if (j == 0) { price = total - allPrice; } allPrice += price; decimal tbtotal = (price * rate) * (decimal)(0.01); btotal += tbtotal; decimal tltotal = price - tbtotal; HashObject detailHash = new HashObject(); detailList.Add(detailHash); detailHash.Add("id", Cuid.NewCuid().GetHashCode()); detailHash.Add("bid", id); detailHash.Add("code", ddid); detailHash.Add("size", ginfo.Size); detailHash.Add("amount", ginfo.Amount); detailHash.Add("color", ginfo.Color); detailHash.Add("address", address); detailHash.Add("area", row["区域"]); detailHash.Add("total", price); detailHash.Add("remark", remark); detailHash.Add("ltotal", tltotal); detailHash.Add("sourceTitle", ginfo.Title); detailHash.Add("goodsstatus", int.Parse(row["发货状态status"].ToString()) >= 1 ? 2 : 1); detailHash.Add("sendway", sendWay); detailHash.Add("btotal", tbtotal); } ltotal = total - btotal; } if (IsNullDate(row["付款时间"])) { continue; } HashObject billHash = new HashObject(); billHash.Add("id", id); billHash.Add("date", row["付款时间"]); billHash.Add("taobaocode", row["旺旺名称"]); billHash.Add("cname", row["收货客户"]); billHash.Add("ctel", row["联系电话"]); billHash.Add("caddress", address); billHash.Add("carea", row["区域"]); billHash.Add("cremark", remark); billHash.Add("ltotal", ltotal); billHash.Add("status", row["发货状态status"]); billHash.Add("scode", TaobaoDataHelper.GetLogisticsInfo(row["物流单号"])); billHash.Add("sname", TaobaoDataHelper.GetLogisticsInfo(row["快递公司"])); billHash.Add("uid", GetUser(row["所属用户"], db == null)); billHash.Add("goodsstatus", 1); billHash.Add("billfrom", "抓取"); billHash.Add("createdate", row["创建时间"]); billHash.Add("zfbpaycode", row["支付宝交易号"]); billHash.Add("tbcode", ddid); billHash.Add("total", total); billHash.Add("btotal", btotal); billHash.Add("senddate", GetDate(sendDate)); billHash.Add("successdate", GetDate(successDate)); billList.Add(billHash); } }
public void CuidsAreShorterThanGuids() { Assert.True( Guid.NewGuid().ToString().Replace("-", string.Empty).Length > Cuid.Generate().Length ); }
public static IEnumerable <ModelEvent> Get(int?take = null) { var project1 = Cuid.Generate(RandomSource.Secure); var player1 = Cuid.Generate(RandomSource.Secure); var player2 = Cuid.Generate(RandomSource.Secure); var player3 = Cuid.Generate(RandomSource.Secure); var player4 = Cuid.Generate(RandomSource.Secure); var feature1 = Cuid.Generate(RandomSource.Secure); var estimate1 = Cuid.Generate(RandomSource.Secure); var estimate2 = Cuid.Generate(RandomSource.Secure); var estimate3 = Cuid.Generate(RandomSource.Secure); var estimate4 = Cuid.Generate(RandomSource.Secure); var estimate5 = Cuid.Generate(RandomSource.Secure); var events = new[] { new ModelEvent { route = new [] { "projects", project1 }, payload = new Payload { values = new { Name = "Project A" }.ToDictionary() } }, new ModelEvent { route = new [] { "projects", project1, "players" }, payload = new Payload { values = new Dictionary <string, object> { { player1, new { Name = "Player 1" }.ToDictionary() }, { player2, new { Name = "Player 2" }.ToDictionary() }, { player3, new { Name = "Player 3" }.ToDictionary() }, { player4, new { Name = "Player 4" }.ToDictionary() } } } }, new ModelEvent { route = new [] { "projects", project1, "features", feature1 }, payload = new Payload { values = new { Description = "New feature for project" }.ToDictionary() } }, new ModelEvent { route = new [] { "projects", project1, "features", feature1, "estimates", estimate1 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player1 }, Card = StoryPoints.Points008 }.ToDictionary() } }, new ModelEvent { route = new [] { "projects", project1, "features", feature1, "estimates", estimate2 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player2 }, Card = StoryPoints.Points005 }.ToDictionary() } }, new ModelEvent { route = new [] { "projects", project1, "features", feature1, "estimates", estimate3 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player3 }, Card = StoryPoints.Points003 }.ToDictionary() } }, new ModelEvent { route = new [] { "projects", project1, "features", feature1, "estimates", estimate4 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player3 }, Card = StoryPoints.Break }.ToDictionary() } }, new ModelEvent { route = new [] { "projects", project1, "features", feature1, "estimates", estimate5 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player4 }, Card = StoryPoints.DontKnow }.ToDictionary() } }, new ModelEvent { route = new [] { "projects", project1, "features", feature1, "estimates", estimate2 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player2 }, Card = StoryPoints.Break, }.ToDictionary() } }, new ModelEvent { route = new [] { "projects", project1, "features", feature1, "estimates" }, payload = new Payload { delete = new [] { estimate2 } } }, new ModelEvent { route = new [] { "projects", project1, "features", feature1, "estimates", estimate2 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player2 }, Card = StoryPoints.Points013, }.ToDictionary() } }, }; if (take == null) { return(events); } return(events.Take(take.Value)); }
public static void SaveDataToTBill(string user, string connection, IList data) { DateTime date = DateTime.Now; using (DbHelper db = new DbHelper(connection)) { IHashObjectList bidList = db.Select(string.Format("select * from tbill where bid in {0}", GetAllIdString(data))); //根据单号获取对应的字典信息 Dictionary <string, HashObject> bidDictionary = new Dictionary <string, HashObject>(); foreach (HashObject item in bidList) { bidDictionary.Add(item.GetValue <string>("bid"), item); } //筛选数据,对于已插入的数据做数据对比,当数据没有变化时,不做数据修改,反之则修改数据。没有的数据直接插入 StringBuilder insertbuilder = new StringBuilder("insert into tbill(tbid,bid,content, cdate, status, `user`, downeddetail, udate, hasUpdate) values"); StringBuilder insertDetailbuilder = new StringBuilder("insert into tbilldetail(tbdid,tbid,content,user) values"); string updateSql = "update tbill set content = @content, udate = @udate, status=@status, downeddetail=@downeddetail, hasUpdate = @hasUpdate where tbid=@tbid"; bool hasInsert = false; bool hasDetail = false; foreach (HashObject row in data) { var id = row.GetValue <string>("bid"); string content = ReplaceHtmlText(row.GetValue <string>("content")); string status = row.GetValue <string>("status"); HashObject item; ulong tbid = Cuid.NewCuid(); if (bidDictionary.TryGetValue(id, out item)) { tbid = item.GetValue <ulong>("tbid"); if (SpliteContentUrl(item.GetValue <string>("content")).Equals(SpliteContentUrl(content)) && item.GetValue <string>("status").Equals(status)) { //数据相同直接返回 continue; } db.AddParameter("content", content); db.AddParameter("udate", date);//更新时间 db.AddParameter("status", status); db.AddParameter("tbid", tbid); //存在不同的,标记全部更新明细 db.AddParameter("downeddetail", 0); db.AddParameter("hasUpdate", 1); db.ExecuteIntSQL(updateSql);//更新已下载数据 continue; } else { hasDetail = true; HashObject detail = row.GetValue <HashObject>("detail"); string str = ReplaceHtmlText(detail.GetValue <string>("content")); insertDetailbuilder.AppendFormat("({0},{1},'{2}', '{3}'),", Cuid.NewCuid(), tbid, str, detail.GetValue <string>("user")); } hasInsert = true; insertbuilder.AppendFormat("({0},'{1}','{2}', '{3}', '{4}', '{5}', 0, '{6}', 1),", tbid, id, content, date, status, user, date); } if (!hasInsert) { return; } try { db.BeginTransaction(); string insertData = insertbuilder.ToString(); db.BatchExecute(insertData.Substring(0, insertData.Length - 1)); if (hasDetail) { string insertDetailData = insertDetailbuilder.ToString(); db.BatchExecute(insertDetailData.Substring(0, insertDetailData.Length - 1)); } db.CommitTransaction(); } catch (Exception t) { db.RollbackTransaction(); throw t; } } }