Beispiel #1
0
        private int AddManyTestRecordsByLinq()
        {
            #region add many records to test
            int rValue = 0;
            int ix     = 5;
            var rnd    = (new Random()).Next(1000, 9999).ToString();
            AddAndShowMessages(rnd.ToString());
            using (var ldb = GetLinqContext())
            {
                var ui = new LDB.UserInfor();
                ui.FirstName = string.Format("{0}_{1}", "Fs", rnd);
                ui.LastName  = string.Format("{0}_{1}", "Ls", rnd);
                ui.Password  = string.Format("{0}_{1}", "Pw", rnd);
                ui.UserName  = string.Format("{0}_{1}", "Us", rnd);
                ldb.UserInfors.InsertOnSubmit(ui);
                ldb.SubmitChanges();
                rValue = ui.id;
                List <LDB.Address> addrList = new List <LDB.Address>();
                for (int i = 0; i < ix; i++)
                {
                    var addr = new LDB.Address();
                    addr.addr   = string.Format("{0}_{1}", "Addr", rnd);
                    addr.Email  = string.Format("{0}_{1}", "Email", rnd);
                    addr.phone  = string.Format("{0}_{1}", "Phone", rnd);
                    addr.UserID = ui.id;
                    addrList.Add(addr);
                }
                ldb.Addresses.InsertAllOnSubmit(addrList);
                ldb.SubmitChanges();
            }
            return(rValue);

            #endregion
        }
Beispiel #2
0
        private void dgvList_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int id;

            if (int.TryParse(dgvList.Rows[e.RowIndex].Cells["ID"].Value.ToString(), out id))
            {
                if (isEFRun)
                {
                    EFClassLib.TableModel.UserInfor usInfor = null;
                    using (DBCTxt db = GetEFContext())
                    {
                        usInfor = db.UserInfor.Where(x => x.id == id).FirstOrDefault();

                        if (usInfor != null)
                        {
                            EFAddOrModifyUser(usInfor);
                        }
                        else
                        {
                            txtInfors.Text = "The User is not exists.";
                        }
                    }
                }
                else
                {
                    LDB.UserInfor usInfor = null;
                    using (var ldb = GetLinqContext())
                    {
                        usInfor = ldb.UserInfors.Where(x => x.id == id).FirstOrDefault();
                        if (usInfor != null)
                        {
                            LinqAddOrModifyUser(usInfor);
                        }
                        else
                        {
                            txtInfors.Text = "The User is not exists.";
                        }
                    }
                }
            }
        }
Beispiel #3
0
        private void LinqAddOrModifyUser(LDB.UserInfor UserInf)
        {
            isEFRun = false;
            AddUser addusFrm = new AddUser();

            addusFrm.SetLinqModiInfor(UserInf);
            if (UserInf == null)
            {
                if (addusFrm.ShowDialog() == DialogResult.OK)
                {
                    var usInfor = addusFrm.GetLinqUserInfor();

                    usInfor.Addresses = new EntitySet <LDB.Address>();
                    usInfor.Addresses.Add(new LDB.Address {
                        addr = "xxx", Email = "*****@*****.**", phone = "000000"
                    });
                    usInfor.Addresses.Add(new LDB.Address {
                        addr = "xxx", Email = "*****@*****.**", phone = "000000"
                    });
                    usInfor.Addresses.Add(new LDB.Address {
                        addr = "xxx", Email = "*****@*****.**", phone = "000000"
                    });

                    if (usInfor != null)
                    {
                        using (LDB.LDBContextDataContext db = GetLinqContext())
                        {
                            db.UserInfors.InsertOnSubmit(usInfor);
                            db.SubmitChanges();
                        }
                        RefreshDataByLinq();
                    }
                    else
                    {
                        AddAndShowMessages("Nothing is Add");
                    }
                }
            }
            else
            {
                //addusFrm.SetLinqModiInfor(UserInf);
                switch (addusFrm.ShowDialog())
                {
                case DialogResult.OK:
                    var uinf = addusFrm.GetLinqUserInfor();
                    using (var ldb = GetLinqContext())
                    {
                        var uif = ldb.UserInfors.Where(x => x.id == UserInf.id).FirstOrDefault();
                        if (uif != null)
                        {
                            uif.FirstName = uinf.FirstName;
                            uif.LastName  = uinf.LastName;
                            uif.Password  = uinf.Password;
                            uif.UserName  = uinf.UserName;
                            foreach (var addr in uif.Addresses)
                            {
                                addr.Email = "*****@*****.**";
                            }
                            try
                            {
                                ldb.SubmitChanges();
                            }
                            catch (ChangeConflictException e)
                            {
                                AddAndShowMessages(e.Message);
                            }
                            catch
                            { }
                        }
                    }
                    RefreshDataByLinq();
                    break;

                case DialogResult.No:
                    using (var db = GetLinqContext())
                    {
                        db.ExecuteCommand("delete from UserInfors where id={0}"
                                          , UserInf.id.ToString()
                                          );
                    }
                    RefreshDataByLinq();
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #4
0
 partial void DeleteUserInfor(UserInfor instance);
Beispiel #5
0
 partial void UpdateUserInfor(UserInfor instance);
Beispiel #6
0
 partial void InsertUserInfor(UserInfor instance);