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


C# Database.Save方法代码示例

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


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

示例1: btnOK_Click

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!dxValidationProvider1.Validate())
                return;
            var odrs = gcOrder.GetDataSource<t_order>();
            if (odrs == null || odrs.Count < 1) {
                MsgBox.ShowMessage("提示", "没有添加商品不能保存!");
                return;
            }
            if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.New) {
                var trdnew = new t_trade() {
                    Guid = GuidKey,
                    ReceiverName = memgcEdt.GetSelectedValue().ReceiverName,
                    ReceiverMobile = memgcEdt.GetSelectedValue().ReceiverMobile,
                    ReceiverAddress = memgcEdt.GetSelectedValue().ReceiverAddress,
                    MemberGuid = memgcEdt.GetSelectedValue().Guid,
                    DeliveryDate = dateDeliveryDate.DateTime,
                    CreateDate = TimeSync.Default.CurrentSyncTime,
                    Creator = this.CurUser,
                };

                using (var db = new Database()) {
                    try {
                        db.BeginTransaction();
                        db.Save(trdnew);
                        odrs.ForEach(k => db.Save(k));
                        db.CompleteTransaction();
                    } catch (Exception) {
                        db.AbortTransaction();
                        throw;
                    }
                }
            } else if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.Edit) {
                using (var db = new Database()) {
                    var trd = db.FirstOrDefault<t_trade>(" where [email protected]", GuidKey);
                    trd.ReceiverName = memgcEdt.GetSelectedValue().ReceiverName;
                    trd.ReceiverMobile = txtMobile.Text;
                    trd.ReceiverAddress = txtReceiverAddress.Text;
                    trd.MemberGuid = memgcEdt.GetSelectedValue().Guid;
                    trd.DeliveryDate = TimeSync.Default.CurrentSyncTime;
                    trd.DeliveryDate = dateDeliveryDate.DateTime;
                    try {
                        db.BeginTransaction();
                        db.Save(trd);
                        db.Execute("delete t_order where [email protected]", trd.Guid);
                        odrs.ForEach(k => {
                            k.Id = 0;
                            db.Save(k);
                        });
                        db.CompleteTransaction();
                    } catch (Exception) {
                        db.AbortTransaction();
                        throw;
                    }
                }
            }
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
开发者ID:flyeven,项目名称:YongERP,代码行数:59,代码来源:NewView.cs

示例2: 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

示例3: save

        //public static Payment recordPayment(Rider rider, double amount, string branch, string username, string account)
        //{
        //    Payment payment = new Payment();

        //    payment.rider = rider.name;
        //    payment.amount = amount;
        //    payment.paid_date = DateTime.Now;
        //    payment.bank_branch = branch;
        //    payment.bank_username = username;
        //    payment.bank_account = account;

        //    Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes"));
        //    db.Insert(payment);

        //    return payment;
        //}

        //public static void deletePayment(int id)
        //{
        //    Database db = new PetaPoco.Database("bikes-clunie");
        //    db.Execute("DELETE FROM payment WHERE id = @0", id);
        //}

        internal void save()
        {
            using (Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes")))
            {
                db.Save(this);
            }
        }
开发者ID:catflinger,项目名称:bikes,代码行数:30,代码来源:payment.cs

示例4: save

 public void save()
 {
     using (Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes")))
     {
         if (id == Bike.DefaultId)
         {
             //cannot change name for the default bike
             name = DefaultName;
         }
         db.Save(this);
     }
 }
开发者ID:catflinger,项目名称:bikes,代码行数:12,代码来源:bike.cs

示例5: 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

示例6: 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

示例7: 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

示例8: btnOK_Click

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (MsgBox.ShowYesNoMessage(null, "确定要保存吗?") == System.Windows.Forms.DialogResult.No)
                return;
            var usr = GetCurUser<t_user>();
            for (int i = 0; i < memedt.Lines.Length; i++)
            {
                memedt.Lines[i] = memedt.Lines[i].Replace("-", string.Empty);
            }
            var exp = memedt.Lines.ToList().Where(k=>!string.IsNullOrEmpty(k.Trim().Replace("\r",string.Empty).Replace("\n",string.Empty))).Except(LstMac.Select(k => k.Mac).ToList()).ToList();
            var ndel = LstMac.Select(k => k.Mac).ToList().Except(memedt.Lines.ToList().Where(k => !string.IsNullOrEmpty(k.Trim().Replace("\r", string.Empty).Replace("\n", string.Empty))).ToList()).ToList();
            if (null != exp && exp.Count > 0)
            {
                using (var db = new Database())
                {
                    exp.ForEach(k =>
                    {

                        db.Save(new t_mac
                        {
                            Guid = Guid.NewGuid(),
                            IsUsing = true,
                            Mac = k,
                            Creator = usr.UserName,
                            CreateDate=TimeSync.Default.CurrentSyncTime
                        });
                    });
                }
            }
            if (null != ndel && ndel.Count > 0)
            {
                var ins = ndel.Select(k=>"'"+k+"'").Aggregate((s1,s2)=>  s1+","+s2).ToString();
                SqlHelper.ExecuteNonQuery(ConnString,CommandType.Text,
                    string.Format("delete from t_mac where mac in ({0})", ins));
            }
            //MsgBox.ShowMessage(null, "保存成功!");
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
开发者ID:MasterGao,项目名称:DevWinFormFrame,代码行数:39,代码来源:EditView.cs

示例9: btnOK_Click

        private void btnOK_Click(object sender, EventArgs e)
        {
            var items = gcItem.GetDataSource<t_instockitem>();
            if (items == null || items.Count < 1) {
                MsgBox.ShowMessage("", "没有商品信息,不能保存!");
                return;
            }
            if (items.Any(K => string.IsNullOrEmpty(K.ItemNo))) {
                MsgBox.ShowMessage("", "商品信息不完整!");
                return;
            }

            if (EditMode == Web.Core.Enums.EnViewEditMode.Edit) {
                using (var db = new Database()) {
                    try {
                        db.BeginTransaction();
                        db.Execute("delete t_instockitem where [email protected]", InStockNo);
                        InStock.Remark = txtRemark.Text;
                        InStock.Num = items.Sum(k => k.Num);
                        InStock.OuterNo = txtOuterNo.Text;
                        db.Save(InStock);
                        items.ForEach(k => { k.Id = 0; db.Save(k); });

                        db.CompleteTransaction();
                    } catch (Exception) {
                        db.AbortTransaction();
                        throw;
                    }
                }
            } else {

                InStock = new t_instock();
                InStock.Remark = txtRemark.Text;
                InStock.Guid = GuidKey;
                InStock.InStockNo = InStockNo;
                InStock.OuterNo = txtOuterNo.Text;
                InStock.Creator = this.CurUser;
                InStock.AuditDate = InStock.CreateDate = TimeSync.Default.CurrentSyncTime;
                InStock.Num = items.Sum(k => k.Num);

                using (var db = new Database()) {
                    try {
                        db.BeginTransaction();
                        db.Save(InStock);
                        items.ForEach(k => db.Save(k));

                        db.CompleteTransaction();
                    } catch (Exception) {
                        db.AbortTransaction();
                        throw;
                    }
                }

            }

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

示例10: CrearCiudad

        public static string CrearCiudad(Ciudad ciudad)
        {
            try {
                using (var db = new Database("riesgos")) {
                    var cuenta = db.SingleOrDefault<int>("select count(id) from ciudad where nombre = @0", ciudad.Nombre);
                    if (cuenta > 0) return "Ya existe una ciudad con el mismo nombre";
                    db.Save("ciudad", "id", ciudad);
                    return "";
                }

            } catch (Exception ex) {
                return "Error de ejecución: " + ex.Message;
            }
        }
开发者ID:sergiosuarez,项目名称:Vulcano,代码行数:14,代码来源:Repositorios.cs

示例11: setAsPaid

 public void setAsPaid(int paymentId)
 {
     payment_id = paymentId;
     paid = true;
     using (Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes")))
     {
         db.Save(this);
     }
 }
开发者ID:catflinger,项目名称:bikes,代码行数:9,代码来源:ride.cs

示例12: btnSaveToSvr_Click

 private void btnSaveToSvr_Click(object sender, EventArgs e)
 {
     if (MsgBox.ShowYesNoMessage("", "确定要保存菜单至服务器?") == System.Windows.Forms.DialogResult.No)
         return;
     using (var db = new Database()) {
         var mnu = db.FirstOrDefault<t_menu>("select * from t_menu");
         if (mnu == null)
         {
             mnu = new t_menu
             {
                 Guid = Guid.NewGuid(),
                 Version = "1.0",
                 MenuXml = BuildMenuXml(),
                 CreateDate = TimeSync.Default.CurrentSyncTime
             };
         }
         else {
             mnu.MenuXml = BuildMenuXml();
         }
         db.Save(mnu);
     }
     MsgBox.ShowMessage("", "保存成功!");
 }
开发者ID:MasterGao,项目名称:DevWinFormFrame,代码行数:23,代码来源:MenuView.cs

示例13: 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


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