/// <summary> /// /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> public void dataBind(int pageIndex = 1, int pageSize = 10, string startTime = null, string endTime = null) { PetaPoco.Sql sql = new PetaPoco.Sql(); sql.Select("m.[description] as name,a.*").From("t_MachineStop_rd a"); sql.LeftJoin("Point_Machine_Map m").On("m.pointname=a.pointname"); if (!String.IsNullOrEmpty(startTime)) { sql.Where("a.starttime>@0", startTime); } if (!String.IsNullOrEmpty(endTime)) { sql.Where("a.starttime<@0", endTime); } List<int> machineids = new List<int>(); for (int i = 0; i < chkboxlist.Items.Count; i++) { if (chkboxlist.Items[i].Selected) { machineids.Add(int.Parse(chkboxlist.Items[i].Value)); } } if (machineids.Count > 1) sql.Where("m.machineid in (@0)", machineids); else if (machineids.Count == 1) sql.Where("m.machineid=@0", machineids[0]); sql.OrderBy("a.starttime desc"); var db = new PetaPoco.Database("dbconn"); PetaPoco.Page<BootRecordSelect> pageitems = db.Page<BootRecordSelect>(pageIndex, pageSize, sql); rpt_RulelogS_Des.DataSource = pageitems.Items; rpt_RulelogS_Des.DataBind(); AspNetPager1.RecordCount = (int)pageitems.TotalItems; }
public PartialViewResult RelationFieldSelectPanelMulti(int fieldid, string value = "", int id = 0, string filter = "", int height = 310, string page = "list") { ViewBag.ID = id; ViewBag.Value = value; ViewBag.WhereSql = filter; ViewBag.SelectValue = new List <RelationEntityField>(); Repository <RelationEntityField> crmRepository = new Repository <RelationEntityField>(); var entity = fieldService.Get(fieldid).Data; ViewBag.Field = entity.Name; var RelationEntityID = SystemSetService.Entity.GetEntityID(entity.RelationEntity); ViewBag.EntityID = RelationEntityID; ViewBag.RelationEntity = entity.RelationEntity; var ViewObj = SystemSetService.View.GetViewByTypeEntityID(RelationEntityID, ViewTypeEnum.弹框视图.ToString()); ViewBag.Columns = ViewObj.FieldList; ViewBag.ViewID = ViewObj.ID; ViewBag.page = page; ViewBag.SearchField = SystemSetService.Search.GetDialogSearchFields(RelationEntityID); if (!string.IsNullOrEmpty(value)) { var sql = new PetaPoco.Sql("SELECT ID,Name FROM " + entity.RelationEntity); sql.Where("ID IN(" + value + ")"); ViewBag.SelectValue = crmRepository.GetList <RelationEntityField>(sql); } ViewBag.height = height; return(PartialView()); }
public void Sql_CacheShouldBeResetAfterAdditionalChanges() { _sql.Select("field"); var sqlCapture1 = _sql.SQL; _sql.From("myTable"); var sqlCapture2 = _sql.SQL; _sql.Where("id = @0", 1); var sqlCapture3 = _sql.SQL; Assert.Equal("SELECT field", sqlCapture1.Replace("\r\n", " ")); Assert.Equal("SELECT field FROM myTable", sqlCapture2.Replace("\r\n", " ")); Assert.Equal("SELECT field FROM myTable WHERE (id = @0)", sqlCapture3.Replace("\r\n", " ")); }
public void Clone() { var where = PetaPoco.Sql.Builder .Where("emp_no = @0", 10023) .Where("birth_date >= @0 AND birth_date <= @1", DateTime.Parse("1953/01/01"), DateTime.Parse("1953/12/31")) .Where("first_name = @0", "Bojan"); _sql = where.Clone(); _sql.Where("last_name = @0", "Montemayor"); _output.WriteLine(_sql.SQL); Assert.Equal(4, where.Arguments.Count); Assert.Equal(5, _sql.Arguments.Count); }
// POST api/<controller> public BootRecord Post(EditBootRecord editbootRecord) { string tbname = ""; if (editbootRecord.typeid== 1) tbname = "t_MachineStop_rd"; else if(editbootRecord.typeid == 0) tbname = "t_AsyncSCR_rd"; PetaPoco.Sql sql = new PetaPoco.Sql(); sql.Select("*").From(tbname); sql.Where("id=@0", editbootRecord.id); BootRecord BootRecords = db.Fetch<BootRecord>(sql).FirstOrDefault(); if (editbootRecord != null && BootRecords != null) { PetaPoco.Sql updateSql = new PetaPoco.Sql(); BootRecords.description = editbootRecord.description; db.Update(tbname, "id", BootRecords); } return BootRecords; }
public int ExecuteUpdate(string tableName, string setString, Dictionary <string, object> updateSets, string strWhere, params object[] p) { var sql = new PetaPoco.Sql("UPDATE " + tableName + " SET "); var values = new List <object>(); var list = new List <string>(); if (!string.IsNullOrEmpty(setString)) { list.Add(setString); } var n = 0; foreach (var kv in updateSets) { list.Add(string.Format("{0}=@{1} ", kv.Key, n)); n++; values.Add(kv.Value); } sql.Append(string.Join(",", list.ToArray()), values.ToArray()); sql.Where(strWhere, p); return(this.Execute(sql)); }