温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么防止下拉列表控件的EditvalueChanged事件进入死循环

发布时间:2021-11-15 16:03:00 来源:亿速云 阅读:224 作者:iii 栏目:大数据

本篇内容主要讲解“怎么防止下拉列表控件的EditvalueChanged事件进入死循环”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么防止下拉列表控件的EditvalueChanged事件进入死循环”吧!

当 下拉列表控件选中后判定另一个为空,return之前需要将该下拉列表清空,就又会触发Changed事件,解决方案就是将空值的判断放置最外层,代码如下:

 private void gluCOATemplate_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                if (gluCOATemplate.Text != "")
                {
                    string sCoaId = gluCOATemplate.Text;
                    string sBacthId = txtLotID.Text;
                    if (txtLotID.Text == "")
                    {
                        CommonFunction.ShowMsgBox("检查批号不能为空");
                        InitgdvCoaItem();
                        gluCOATemplate.Text = "";
                        txtLotID.Focus();
                        return;
                    }
                    if (gluCOATemplate.Text == "")
                    {
                        CommonFunction.ShowMsgBox("请选择模板ID");
                        gluCOATemplate.Focus();
                        return;
                    }

                    if (txtLotID.Text != "" && sCoaId != "")
                    {
                        DataTable dt = new DataTable();
                        dt = QCMLIST.QCM_View_COA_Detail(sCoaId, sBacthId);

                        if (dt != null)
                        {
                            udcGVNewDelCtrl1.RecordCount = dt.Rows.Count;
                            //DevGridControlHelper.BindData(gdcCOAItem, dt);
                            DevGridControlHelper.BindData(gdcCOAItem, dt, new int[] { 1, 1, 1, 1, 1, 1 });
                        }
                        else
                        {
                            InitgdvCoaItem();
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                CommonFunction.ShowMsgBox(ex.Message);
                return;
            }
        }

===============

防止添加的数据主键冲突:

一开始没有主键就取查到的最大值+1,

int iSeq = InTag.coa_list[i].item_seq;
                            if (iSeq == 0)//传入的Seq为空(0)时,取数据库中最大的+1,否则直接保存
                            {
                                List<UQcmcoaitem> uQcmcoaitemlist = ctx.UQcmcoaitem.Where(t => t.PkgNoticeNo == sPkgId && t.Factory == sFactory).OrderByDescending(t=>t.ItemSeq).ToList();
                                if (uQcmcoaitemlist != null)
                                {
                                    iSeq = uQcmcoaitemlist[0].ItemSeq + 1;
                                }
                                else
                                {
                                    iSeq = 1;
                                }
                            }
                            UQcmcoaitem uQcmcoaItem = new UQcmcoaitem
                            {
                                PkgNoticeNo = sPkgId,
                                Factory = sFactory,
                                ItemSeq = iSeq,
                                TestingResult =InTag.coa_list[i].testing_result,

                                TestingItem = InTag.coa_list[i].testing_item,
                                TestingSpec = InTag.coa_list[i].testing_specification,
                                TestingMethod = InTag.coa_list[i].testing_method,
                                Dimens = InTag.coa_list[i].dimens,
                                CreateTime = DBGV._dbc.DB_GetSysTime(),
                                CreateUserId = InTag._cmn_in._user_id
                            };
                            ctx.UQcmcoaitem.Add(uQcmcoaItem);

但是当添加多条Seq=0的数据时,从数据库查出的最大值+1就会使得要添加的这几天数据的主键冲突,因为事务还没提交,Seq都是Max+1

解决方法:在循环外面加一个int变量(count=0),每次Max+1后,再加上count:

 int count = 0;
for (int i = 0; i < InTag.coa_list.Length; i++)
{
                      if (InTag.coa_list[i].step == 'I')
                        {
                            int iSeq = InTag.coa_list[i].item_seq;
                            if (iSeq == 0)
                            {
                                List<UQcmcoaitem> uQcmcoaitemlist = ctx.UQcmcoaitem.Where(t => t.PkgNoticeNo == sPkgId && t.Factory == sFactory).OrderByDescending(t=>t.ItemSeq).ToList();
                                if (uQcmcoaitemlist != null)
                                {
                                    iSeq = uQcmcoaitemlist[0].ItemSeq + 1+count;
                                    count++;
                                }
                                else
                                {
                                    iSeq = 1;
                                }
                            }
                            UQcmcoaitem uQcmcoaItem = new UQcmcoaitem
                            {
                                PkgNoticeNo = sPkgId,
                                Factory = sFactory,
                                ItemSeq = iSeq,
                                TestingResult =InTag.coa_list[i].testing_result,

                                TestingItem = InTag.coa_list[i].testing_item,
                                TestingSpec = InTag.coa_list[i].testing_specification,
                                TestingMethod = InTag.coa_list[i].testing_method,
                                Dimens = InTag.coa_list[i].dimens,
                                CreateTime = DBGV._dbc.DB_GetSysTime(),
                                CreateUserId = InTag._cmn_in._user_id
                            };
                            ctx.UQcmcoaitem.Add(uQcmcoaItem);
                        }
                        else
                        {
                            sMsgCode = "QCM-0004";
                            return GlobalConstant.FAIL;
                        }
                    }
                    ctx.SaveChanges();
                    transaction.Commit();

GridLookUpEdit下拉列表的高度设置:

将properties中的AutoHeight设置为false,再设置size的值

怎么防止下拉列表控件的EditvalueChanged事件进入死循环

到此,相信大家对“怎么防止下拉列表控件的EditvalueChanged事件进入死循环”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI