当前位置: 首页>>代码示例>>C#>>正文


C# Database.FirstOrDefault方法代码示例

本文整理汇总了C#中PetaPoco.Database.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Database.FirstOrDefault方法的具体用法?C# Database.FirstOrDefault怎么用?C# Database.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PetaPoco.Database的用法示例。


在下文中一共展示了Database.FirstOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnOK_Click

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!dxValidationProvider1.Validate())
                return;

            using (var db = new Database()) {
                if (EditMode == Web.Core.Enums.EnViewEditMode.Edit) {
                    var kt = db.FirstOrDefault<t_location>("where [email protected] and guid <> @1", txtName.Text,GuidKey);
                    if (null != kt) {
                        MsgBox.ShowMessage("提示", "库位名称已存在!");
                        txtName.Select();
                        return;
                    }

                    var et = db.FirstOrDefault<t_location>(" where [email protected]", this.GuidKey);
                    et.WareName = wareGridEdit1.GetSelectedValue().WareName;
                    et.WareCode = wareGridEdit1.GetSelectedValue().WareCode;
                    et.AreaName = areaGridEdit1.GetSelectedValue().AreaName;
                    et.AreaCode = areaGridEdit1.GetSelectedValue().AreaCode;
                    et.LocName = txtName.Text;
                    et.LocCode = txtCode.Text;
                    et.IsUsing = chk.Checked;
                    db.Save(et);
                } else {
                    var kt = db.FirstOrDefault<t_location>("where [email protected]", txtName.Text);
                    if (null != kt) {
                        MsgBox.ShowMessage("提示", "库位名称已存在!");
                        txtName.Select();
                        return;
                    }
                    var et = new t_location {
                        Guid= Guid.NewGuid(),
                        WareName = wareGridEdit1.GetSelectedValue().WareName,
                        WareCode = wareGridEdit1.GetSelectedValue().WareCode,
                        AreaName = areaGridEdit1.GetSelectedValue().AreaName,
                        AreaCode = areaGridEdit1.GetSelectedValue().AreaCode,
                        LocCode = txtCode.Text,
                        LocName = txtName.Text,
                        IsUsing = chk.Checked,
                        Creator=this.CurUser,
                        CreateDate=TimeSync.Default.CurrentSyncTime
                    };
                    db.Save(et);
                }
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
开发者ID:ZixiangBoy,项目名称:YongERP,代码行数:49,代码来源:LocEditView.cs

示例2: btnOK_Click

        private void btnOK_Click(object sender, EventArgs ea)
        {
            var k = roleGridEdit1.GetSelectedValue();
            if (null == k) return;
            List<MenuCtlData> lst = new List<MenuCtlData>(100);
            foreach (TreeListNode td in treeCtl1.Nodes)
            {
                var mnugrp = td.GetValue(0).ToString();
                foreach (TreeListNode tds in td.Nodes)
                {
                    var mnuname = tds.GetValue(0).ToString();
                    foreach (TreeListNode tmd in tds.Nodes)
                    {
                        var mcd = tmd.Tag as MenuCtlData;
                        if (null != mcd)
                        {
                            mcd.IsEnabled = tmd.Checked;
                            mcd.MenuGrpName = mnugrp;
                            mcd.MenuName = mnuname;
                            lst.Add(mcd);
                        }
                        foreach (TreeListNode tkd in tmd.Nodes)
                        {
                            var md = tkd.Tag as MenuCtlData;
                            if (null == md) continue;
                            md.IsEnabled = tkd.Checked;
                            md.MenuGrpName = mnugrp; md.MenuName = mnuname;
                            lst.Add(md);
                        }
                    }
                }
            }
            var usr = GetCurUser<t_user>();
            using (var db = new Database())
            {

                var et = db.FirstOrDefault<t_roleset>("select * from t_roleset where [email protected]", k.Id);

                var roleset = et;
                if (et != null)
                {
                    roleset.RoleSetTree = Ultra.Web.Core.Common.ObjectHelper.SerializeJson(lst);
                }
                else
                {
                    roleset = new t_roleset
                    {
                        RoleSetTree = Ultra.Web.Core.Common.ObjectHelper.SerializeJson(lst),
                        RoleId = k.Id,
                        IsUsing = true,
                        RoleName = k.Name,
                        Guid = Guid.NewGuid(),
                        Creator =this.CurUser,
                        CreateDate = TimeSync.Default.CurrentSyncTime
                    };
                }
                db.Save(roleset);
            }
            MsgBox.ShowMessage(null, "保存成功!");
        }
开发者ID:MasterGao,项目名称:DevWinFormFrame,代码行数:60,代码来源:PermitView.cs

示例3: getRoute

 public static Route getRoute(int id)
 {
     using (Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes")))
     {
         return db.FirstOrDefault<Route>("WHERE id = @0", id);
     }
 }
开发者ID:catflinger,项目名称:bikes,代码行数:7,代码来源:route.cs

示例4: getRider

 public static Rider getRider(int id)
 {
     using (Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes")))
     {
         Rider rider = db.FirstOrDefault<Rider>("WHERE id = @0", id);
         return rider;
     }
 }
开发者ID:catflinger,项目名称:bikes,代码行数:8,代码来源:rider.cs

示例5: getPwd

 public static string getPwd(int id)
 {
     using (Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes")))
     {
         PwdPoco poco = db.FirstOrDefault<PwdPoco>("WHERE id = @0", id);
         return poco.pwd;
     }
 }
开发者ID:catflinger,项目名称:bikes,代码行数:8,代码来源:rider.cs

示例6: findRiderByName

 public static Rider findRiderByName(string name)
 {
     using (Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes")))
     {
         Rider rider = db.FirstOrDefault<Rider>("WHERE name = @0", name);
         return rider;
     }
 }
开发者ID:catflinger,项目名称:bikes,代码行数:8,代码来源:rider.cs

示例7: WareEditView_Load

 private void WareEditView_Load(object sender, EventArgs e)
 {
     if (EditMode == Web.Core.Enums.EnViewEditMode.Edit) {
         using (var db = new Database()) {
             var ware = db.FirstOrDefault<t_ware>(" where [email protected]",this.GuidKey);
             txtName.Text = ware.WareName;
             txtCode.Text = ware.WareCode;
             chk.Checked = ware.IsUsing;
         }
     }
 }
开发者ID:ZixiangBoy,项目名称:YongERP,代码行数:11,代码来源:WareEditView.cs

示例8: btnOK_Click

        private void btnOK_Click(object sender, EventArgs e)
        {
            using (var db = new Database()) {
                if (EditMode == Web.Core.Enums.EnViewEditMode.Edit) {
                    var kt = db.FirstOrDefault<t_ware>("where [email protected] and guid <> @1", txtName.Text,GuidKey);
                    if (null != kt) {
                        MsgBox.ShowMessage("提示", "仓库名称已存在!");
                        txtName.Select();
                        return;
                    }

                    var et = db.FirstOrDefault<t_ware>(" where [email protected]", this.GuidKey);
                    et.WareName = txtName.Text;
                    et.WareCode = txtCode.Text;
                    et.IsUsing = chk.Checked;
                    db.Save(et);
                } else {
                    var kt = db.FirstOrDefault<t_ware>("where [email protected]", txtName.Text);
                    if (null != kt) {
                        MsgBox.ShowMessage("提示", "仓库名称已存在!");
                        txtName.Select();
                        return;
                    }
                    var et = new t_ware {
                        Guid= Guid.NewGuid(),
                        WareCode = txtCode.Text,
                        WareName = txtName.Text,
                        IsUsing = chk.Checked,
                        Creator=this.CurUser,
                        CreateDate=TimeSync.Default.CurrentSyncTime
                    };
                    db.Save(et);
                }
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
开发者ID:ZixiangBoy,项目名称:YongERP,代码行数:38,代码来源:WareEditView.cs

示例9: btnOK_Click

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!dxValidationProvider1.Validate())
                return;

            if (MsgBox.ShowYesNoMessage(null, "确定要保存修改吗?") == System.Windows.Forms.DialogResult.No)
                return;
            if (txtpwd.Text != txtrepwd.Text) {
                MsgBox.ShowMessage("", "两次输入的密码不一致!");
                txtpwd.Select();
                return;
            }
            var pwd = string.IsNullOrEmpty(txtpwd.Text) ? "888" : txtpwd.Text;
            var pwde = Util.EncryptPwd(pwd);
            if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.New) {
                using (var db = new Database()) {
                    //检查用户名唯一性
                    var kt = db.FirstOrDefault<t_user>("select * from t_user where [email protected]", txtusr.Text);
                    if (null != kt) {
                        MsgBox.ShowMessage("用户已存在", "用户已存在!");
                        txtusr.Select();
                        return;
                    }
                    db.Save(new t_user() {
                        Guid = Guid.NewGuid(),
                        UserName = txtusr.Text,
                        Pwd = pwde,
                        CreateDate = TimeSync.Default.CurrentSyncTime,
                        Creator=this.CurUser,
                        IsUsing=chk.Checked,
                        Remark=string.Empty
                    });
                }
            } else if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.Edit) {
                using (var db = new Database()) {
                    var et = db.FirstOrDefault<t_user>("where [email protected]", GuidKey);
                    if (null != et) {
                        et.Guid = Guid.NewGuid();
                        et.UserName = txtusr.Text;
                        et.Pwd = pwde;
                        et.CreateDate = TimeSync.Default.CurrentSyncTime;
                        et.Creator=this.CurUser;
                        et.IsUsing=chk.Checked;
                        et.Remark = string.Empty;
                    }
                }
            }
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
开发者ID:MasterGao,项目名称:DevWinFormFrame,代码行数:50,代码来源:NewView.cs

示例10: NewView_Load

 private void NewView_Load(object sender, EventArgs e)
 {
     if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.Edit)
     {
         txtname.Properties.ReadOnly = true;
         using (var db = new Database())
         {
             var et = db.FirstOrDefault<t_role>(" where [email protected]", GuidKey);
             if (null != et)
             {
                 txtname.Text = et.Name;
                 txtdesc.Text = et.Desc;
                 chk.Checked = et.IsUsing;
             }
         }
     }
 }
开发者ID:MasterGao,项目名称:DevWinFormFrame,代码行数:17,代码来源:NewView.cs

示例11: NewView_Load

 private void NewView_Load(object sender, EventArgs e)
 {
     if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.Edit) {
         using (var db = new Database()) {
             try {
                 var et = db.FirstOrDefault<t_item>("where [email protected]", GuidKey);
                 if (null != et) {
                     txtItemName.Text = et.ItemName;
                     txtItemNo.Text = et.ItemNo;
                     spnPrice.Value = et.Price;
                     chk.Checked = et.IsUsing;
                 }
             } catch (Exception ex) {
                 throw ex;
             }
         }
         txtItemName.Properties.ReadOnly = true;
     }
 }
开发者ID:ZixiangBoy,项目名称:YongERP,代码行数:19,代码来源:NewView.cs

示例12: btnOK_Click

 private void btnOK_Click(object sender, EventArgs e)
 {
     if (!dxValidationProvider1.Validate())
         return;
     if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.New) {
         using (var db = new Database()) {
             var kt = db.FirstOrDefault<t_item>("select * from t_item where [email protected]", txtItemNo.Text);
             if (null != kt) {
                 MsgBox.ShowMessage("编码已存在", "编码已存在!");
                 txtItemNo.Select();
                 return;
             }
             db.Save(new t_item() {
                 Guid = Guid.NewGuid(),
                 ItemName  = txtItemName.Text,
                 ItemNo = txtItemNo.Text,
                 Price=spnPrice.Value,
                 CostPrice=spnCostPrice.Value,
                 CreateDate = TimeSync.Default.CurrentSyncTime,
                 Creator=this.CurUser,
                 IsUsing=chk.Checked,
                 Remark=string.Empty
             });
         }
     } else if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.Edit) {
         using (var db = new Database()) {
             var et = db.FirstOrDefault<t_item>("where [email protected]", GuidKey);
             if (null != et) {
                 et.ItemName = txtItemName.Text;
                 et.ItemNo = txtItemNo.Text;
                 et.Price=spnPrice.Value;
                 et.CostPrice = spnCostPrice.Value;
                 et.IsUsing=chk.Checked;
                 et.Remark = string.Empty;
             }
             db.Save(et);
         }
     }
     DialogResult = System.Windows.Forms.DialogResult.OK;
     Close();
 }
开发者ID:ZixiangBoy,项目名称:YongERP,代码行数:41,代码来源:NewView.cs

示例13: LocEditView_Load

        private void LocEditView_Load(object sender, EventArgs e)
        {
            wareGridEdit1.LoadData();
            areaGridEdit1.LoadData();

            if (EditMode == Web.Core.Enums.EnViewEditMode.Edit) {
                using (var db = new Database()) {
                    var loc = db.FirstOrDefault<t_location>(" where [email protected]",this.GuidKey);

                    wareGridEdit1.SetSelectedValue(db.FirstOrDefault<t_ware>(" where warename = @0", loc.WareName));
                    areaGridEdit1.SetSelectedValue(db.FirstOrDefault<t_area>(" where areaname = @0", loc.AreaName));
                    txtName.Text = loc.LocName;
                    txtCode.Text = loc.LocCode;
                    chk.Checked = loc.IsUsing;
                }
            }
        }
开发者ID:ZixiangBoy,项目名称:YongERP,代码行数:17,代码来源:LocEditView.cs

示例14: GetSingle

        public MixERP.Net.Entities.CRM.LeadSource GetSingle(int id)
        {
            ApiAccessPolicy policy = new ApiAccessPolicy(typeof(MixERP.Net.Entities.CRM.LeadSource), "GET");
            policy.Authorize();

            if (!policy.IsAuthorized)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            try
            {
                using (Database db = new Database(Factory.GetConnectionString(), "Npgsql"))
                {
                    return db.FirstOrDefault<MixERP.Net.Entities.CRM.LeadSource>("SELECT * FROM crm.lead_sources WHERE [email protected]", id);
                }
            }
            catch
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
开发者ID:JonathanValle,项目名称:mixerp,代码行数:22,代码来源:CRM.cs

示例15: GetSingle

        public MixERP.Net.Entities.Core.TaxRateType GetSingle(string id)
        {
            ApiAccessPolicy policy = new ApiAccessPolicy(typeof(MixERP.Net.Entities.Core.TaxRateType), "GET");
            policy.Authorize();

            if (!policy.IsAuthorized)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            try
            {
                using (Database db = new Database(Factory.GetConnectionString(), "Npgsql"))
                {
                    return db.FirstOrDefault<MixERP.Net.Entities.Core.TaxRateType>("SELECT * FROM core.tax_rate_types WHERE [email protected]", id);
                }
            }
            catch
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
开发者ID:JonathanValle,项目名称:mixerp,代码行数:22,代码来源:Core.cs


注:本文中的PetaPoco.Database.FirstOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。