/// <summary>
        /// 多项更改
        /// 使用SubmitChanges将对检索到的进行的更新保持回数据库
        /// </summary>
        /// <param name="dictionary">Dictionary实体对象</param>
        /// <returns></returns>
        public static bool UpdateMore(Dictionary dictionary)
        {
            bool rbool = true;

            try
            {
                using (DCCarManagementDataContext db = new DCCarManagementDataContext())
                {
                    var q = from p in db.Dictionary
                            where p.Dictionary_ID == dictionary.Dictionary_ID
                            select p;
                    foreach (var p in q)
                    {
                        p.Dictionary_Name    = dictionary.Dictionary_Name;
                        p.Dictionary_OtherID = dictionary.Dictionary_OtherID;
                        p.Dictionary_Remark  = dictionary.Dictionary_Remark;
                        p.Dictionary_State   = dictionary.Dictionary_State;
                        p.Dictionary_Value   = dictionary.Dictionary_Value;
                    }
                    db.SubmitChanges();
                }
            }
            catch
            {
                rbool = false;
            }
            return(rbool);
        }
示例#2
0
        /// <summary>
        /// 执行多操作
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="dc"></param>
        /// <param name="intindex">0:添加操作 1:修改操作 2:删除操作 3:添加多条记录 4:删除多条记录</param>
        /// <param name="tentity">要添加的实体</param>
        /// <param name="fun">修改或删除的条件</param>
        /// <param name="action">修改的值</param>
        /// <param name="rbool">ture:执行操作 FALSE:不执行</param>
        /// <param name="tentitys">要添加或都要删除的实体集合</param>
        /// <returns></returns>
        public static bool ADD_Delete_UpdateMethod <T>(DCCarManagementDataContext dc, int intindex, T tentity, Expression <Func <T, bool> > fun, Action <T> action, bool rbool, IEnumerable <T> tentitys) where T : class
        {
            bool falg = true;

            if (intindex == 0)//添加
            {
                var table = dc.GetTable <T>();
                table.InsertOnSubmit(tentity);
            }
            if (intindex == 3)//添加多条记录
            {
                var table = dc.GetTable <T>();
                table.InsertAllOnSubmit(tentitys);
            }
            if (intindex == 1)//修改
            {
                var table = dc.GetTable <T>().Single <T>(fun);
                action(table);
            }
            if (intindex == 2)//删除
            {
                var table  = dc.GetTable <T>();
                var result = table.Where <T>(fun).AsEnumerable <T>();

                table.DeleteAllOnSubmit <T>(result);
            }
            if (intindex == 4)//删除多条记录
            {
                var table = dc.GetTable <T>();
                table.InsertAllOnSubmit(tentitys);
            }
            if (rbool)
            {
                try
                {
                    dc.SubmitChanges();
                }
                catch (ChangeConflictException err)
                {
                    dc.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues);
                    dc.SubmitChanges();
                    falg = false;
                }
            }
            return(falg);
        }
示例#3
0
        /// <summary>
        /// 添加多条记录
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dc"></param>
        /// <param name="tentitys"></param>
        public static bool InsertToMany <T>(DCCarManagementDataContext dc, IEnumerable <T> tentitys) where T : class
        {
            //var table = dc.GetTable<T>();
            //table.InsertAllOnSubmit(tentitys);
            //dc.SubmitChanges();
            bool rbool = true;

            try
            {
                var table = dc.GetTable <T>();
                table.InsertAllOnSubmit(tentitys);
                dc.SubmitChanges();
            }
            catch (ChangeConflictException)
            {
                dc.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues);
                dc.SubmitChanges();
                rbool = false;
            }
            return(rbool);
        }
示例#4
0
        /// <summary>
        /// LINQ更新方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dc"></param>
        /// <param name="fun"></param>
        /// <param name="tentity"></param>
        /// <param name="action"></param>
        public static bool Update <T>(DCCarManagementDataContext dc, Expression <Func <T, bool> > fun, Action <T> action) where T : class
        {
            //var table = dc.GetTable<T>().Single<T>(fun);
            //action(table);
            //dc.SubmitChanges();
            bool rbool = true;

            try
            {
                var table = dc.GetTable <T>().Single <T>(fun);
                action(table);

                dc.SubmitChanges();
            }
            catch (ChangeConflictException)
            {
                dc.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues);
                dc.SubmitChanges();
                rbool = false;
            }
            return(rbool);
        }
示例#5
0
        /// <summary>
        /// 按条件删除多条数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dc"></param>
        /// <param name="tentitys"></param>
        /// <param name="fun"></param>
        public static bool DeleteToMany <T>(DCCarManagementDataContext dc, Expression <Func <T, bool> > fun) where T : class
        {
            //var table = dc.GetTable<T>();
            //var result = table.Where<T>(fun).AsEnumerable<T>();
            //table.DeleteAllOnSubmit<T>(result);
            //dc.SubmitChanges();
            bool rbool = true;

            try
            {
                var table  = dc.GetTable <T>();
                var result = table.Where <T>(fun).AsEnumerable <T>();
                table.DeleteAllOnSubmit <T>(result);
                dc.SubmitChanges();
            }
            catch (ChangeConflictException)
            {
                dc.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues);
                dc.SubmitChanges();
                rbool = false;
            }
            return(rbool);
        }
示例#6
0
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dc"></param>
        /// <param name="tentity"></param>
        public static bool InsertOne <T>(DCCarManagementDataContext dc, T tentity) where T : class
        {
            bool rbool = true;

            try
            {
                var table = dc.GetTable <T>();
                table.InsertOnSubmit(tentity);
                dc.SubmitChanges();
            }
            catch
            {
                rbool = false;
            }
            return(rbool);
        }
        /// <summary>
        /// 新增一条记录
        /// </summary>
        /// <param name="qcRecord">质检实体</param>
        /// <returns></returns>
        public static bool InsertOne(CarInOutInfoRecord carInOutInfoRecord)
        {
            bool rbool = true;

            using (DCCarManagementDataContext db = new DCCarManagementDataContext())
            {
                try
                {
                    db.CarInOutInfoRecord.InsertOnSubmit(carInOutInfoRecord);
                    db.SubmitChanges();
                    rbool = true;
                }
                catch
                {
                    rbool = false;
                }
                finally { db.Connection.Close(); }
            }
            return(rbool);
        }
        /// <summary>
        /// 单项更改
        /// 检索到的一个Dictionary对象做出的更新保持回数据库
        /// </summary>
        /// <param name="dictionary">Dictionary实体</param>
        /// <returns></returns>
        public static bool Update(Dictionary dictionary)
        {
            bool rbool = true;

            try
            {
                using (DCCarManagementDataContext db = new DCCarManagementDataContext())
                {
                    Dictionary dic = db.Dictionary.First(c => c.Dictionary_ID == dictionary.Dictionary_ID);
                    dic.Dictionary_Name    = dictionary.Dictionary_Name;
                    dic.Dictionary_Value   = dictionary.Dictionary_Value;
                    dic.Dictionary_OtherID = dictionary.Dictionary_OtherID;
                    dic.Dictionary_State   = dictionary.Dictionary_State;
                    dic.Dictionary_Remark  = dictionary.Dictionary_Remark;
                    db.SubmitChanges();
                }
            }
            catch
            {
                rbool = false;
            }
            return(rbool);
        }
示例#9
0
        /// <summary>
        /// 保存,如果有同样车牌号的通行策略则把之前的状态注销
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            IList <DrivewayStrategyRecord> iedsr = null;

            try
            {
                if (string.IsNullOrEmpty(txt_carState.Text))
                {
                    PublicClass.ShowToolTip(ToolTipIcon.Info, "提示", "请选择状态!", txt_carState, this);
                    return;
                }
                string strsort = "";
                if (SortYesOrNo)
                {
                    strsort = "有序";
                }
                else
                {
                    strsort = "无序";
                }
                if (SetSortList.Count != Driveway_IDList.Count)
                {
                    SortYesOrNo = false;
                }
                else
                {
                    SortYesOrNo = true;
                }
                //得到车辆对象
                Expression <Func <CarInfo, bool> > fn = n => n.CarInfo_ID == Convert.ToInt32(CommonalityEntity.CarInfo_ID);
                CarInfo car = CarInfoDAL.Single(fn);


                LinQBaseDao.Query("delete ManagementStrategyRecord where ManagementStrategyRecord_CarInfo_ID=" + car.CarInfo_ID);
                LinQBaseDao.Query("delete DrivewayStrategyRecord where DrivewayStrategyRecord_CarInfo_ID=" + car.CarInfo_ID);

                //循环选择的通道
                iedsr = new List <DrivewayStrategyRecord>();

                if (SetSortList.Count == Driveway_IDList.Count)
                {
                    for (int i = 0; i < SetSortList.Count; i++)
                    {
                        DataTable tablesDrisn = LinQBaseDao.Query("select Position_Name,Driveway_Name,Driveway_type from View_DrivewayPosition where driveway_warrantystate='正常' and driveway_state='启动' and Driveway_ID=" + SetSortList[i].id + "  order by Position_Name asc, Driveway_Name asc").Tables[0];

                        DrivewayStrategyRecord Newdsr = new DrivewayStrategyRecord();
                        Newdsr.DrivewayStrategyRecord_Name        = txtDrivewayStrategy.Text.Trim();
                        Newdsr.DrivewayStrategyRecord_Driveway_ID = SetSortList[i].id;//通道编号
                        Newdsr.DrivewayStrategyRecord_State       = txt_carState.Text;
                        Newdsr.DrivewayStrategyRecord_Remark      = txt_DrivewayStrategyRecord_Remark.Text.Trim();
                        Newdsr.DrivewayStrategyRecord_OffReason   = txt_DrivewayStrategyRecord_OffReason.Text.Trim();
                        Newdsr.DrivewayStrategyRecord_OffTime     = CommonalityEntity.GetServersTime();
                        Newdsr.DrivewayStrategyRecord_OffName     = HelpClass.common.USERNAME;
                        Newdsr.DrivewayStrategyRecord_CarInfo_ID  = car.CarInfo_ID;
                        Newdsr.DrivewayStrategyRecord_Sort        = SortYesOrNo == true ? SetSortList[i].sort : 1;
                        Newdsr.DrivewayStrategyRecord_Record      = "【" + txt_carInfo_Name.Text.ToString().Trim() + "】 " + tablesDrisn.Rows[0]["Position_Name"] + tablesDrisn.Rows[0]["Driveway_Name"];
                        iedsr.Add(Newdsr);
                    }

                    try
                    {
                        dc.DrivewayStrategyRecord.InsertAllOnSubmit(iedsr);
                        dc.SubmitChanges();



                        DialogResult dr = MessageBox.Show("操作已完成!请继续修改相应的管控策略否则修改无效", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                        if (dr == DialogResult.Yes)
                        {
                            string sids = "";

                            DataTable dt = LinQBaseDao.Query("select DrivewayStrategyRecord_ID, DrivewayStrategyRecord_Driveway_ID from DrivewayStrategyRecord where DrivewayStrategyRecord_CarInfo_ID=" + car.CarInfo_ID + " and DrivewayStrategyRecord_State='启动' order by DrivewayStrategyRecord_Sort ").Tables[0];
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                sids += dt.Rows[i][0].ToString() + ",";
                            }
                            int driid = Convert.ToInt32(dt.Rows[0][1].ToString());
                            sids = sids.TrimEnd(',');
                            string SmallID = LinQBaseDao.GetSingle("select SmallTicket_ID from SmallTicket where SmallTicket_CarInfo_ID=" + car.CarInfo_ID).ToString();

                            DataTable dtpd = LinQBaseDao.Query("select Position_ID, Position_Value,Driveway_Value from View_FVN_Driveway_Position where Driveway_ID=" + driid).Tables[0];
                            if (dtpd.Rows.Count > 0)
                            {
                                string str = "update CarInOutRecord set CarInOutRecord_DrivewayStrategyS='" + sids + "',CarInOutRecord_Update=1,CarInOutRecord_Driveway_ID=" + driid + ",CarInOutRecord_Remark='" + txtDrivewayStrategy.Text.Trim() + "',CarInOutRecord_Sort='" + strsort + "' where CarInOutRecord_CarInfo_ID=" + car.CarInfo_ID;
                                str += " update SortNumberInfo set  SortNumberInfo_PositionValue='" + dtpd.Rows[0][1].ToString() + "',SortNumberInfo_DrivewayValue='" + dtpd.Rows[0][2].ToString() + "' where  SortNumberInfo_SmallTicket_ID in (select SmallTicket_ID from SmallTicket where SmallTicket_CarInfo_ID=" + car.CarInfo_ID + ")";
                                LinQBaseDao.Query(str);

                                sids = "";
                                CommonalityEntity.boolCepyManagementStrategy = false;
                                UpdateManagementStrategyForm up = new UpdateManagementStrategyForm(carname);
                                up.Show();
                            }
                        }
                        BingMethod();
                    }
                    catch
                    {
                        MessageBox.Show("操作失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            catch
            {
                CommonalityEntity.WriteTextLog("DrivewayStrategyRecordForm.btnUpdate_Click()" + "".ToString());
            }
            finally
            {
                SetSortList.Clear();
                Driveway_IDList.Clear();
            }
        }