Example #1
0
        private void ucLabelRcard_TxtboxKeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                if (this.ucLabelSoftVersion.Value.Trim().Length == 0)
                {
                    this.ucLabelSoftVersion.TextFocus(false, true);
                    ApplicationRun.GetInfoForm().Add(new UserControl.Message(MessageType.Normal, "$CS_PleaseChooseSoftVersion"));
                    return;
                }

                if (this.ucLabelRcard.Value == string.Empty)
                {
                    this.ucLabelRcard.TextFocus(false, true);
                    return;
                }
                string   newVersion = FormatHelper.PKCapitalFormat(FormatHelper.CleanString(this.ucLabelSoftVersion.Value));
                string   rcard      = FormatHelper.PKCapitalFormat(FormatHelper.CleanString(this.ucLabelRcard.Value));
                Messages msg        = new Messages();
                ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = false;
                ((SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();

                try
                {
                    DataCollectFacade dataCollectFacade = new DataCollectFacade(this.DataProvider);
                    string            sourceRCard       = dataCollectFacade.GetSourceCard(rcard.Trim().ToUpper(), string.Empty);

                    // 获取要升级的产品序列号信息
                    OnWipSoftVer4Upgrade oldVersion = dataCollectFacade.GetOldSoftVersion(sourceRCard);

                    if (oldVersion == null)
                    {
                        ApplicationRun.GetInfoForm().Add(new UserControl.Message(MessageType.Error, "$Error_Rcard_Or_NOSoftInfo"));
                        this.ucLabelRcard.TextFocus(false, true);
                        return;
                    }
                    // 判断软件版本是否相同,相同就不需要升级了
                    if (string.Compare(oldVersion.SoftwareVersion, newVersion, true) == 0)
                    {
                        ApplicationRun.GetInfoForm().Add(new UserControl.Message(MessageType.Normal, "$CS_AlreadyUpgraded"));
                        this.ucLabelRcard.TextFocus(false, true);
                        return;
                    }

                    BenQGuru.eMES.BaseSetting.BaseModelFacade dataModel = new BenQGuru.eMES.BaseSetting.BaseModelFacade(this.DataProvider);
                    Resource resource = (Domain.BaseSetting.Resource)dataModel.GetResource(ApplicationService.Current().ResourceCode);

                    string userCode = ApplicationService.Current().UserCode;

                    // 升级
                    msg.AddMessages(dataCollectFacade.UpgradeNewSoftVer(oldVersion, resource, userCode, newVersion));

                    if (!msg.IsSuccess())
                    {
                        ApplicationRun.GetInfoForm().Add(msg);
                        this.ucLabelRcard.TextFocus(false, true);
                        return;
                    }

                    dtSoftWareVersion.Rows.Add(new object[] { oldVersion.RunningCard, oldVersion.ItemDescription,
                                                              oldVersion.SoftwareVersion, newVersion });
                    dtSoftWareVersion.AcceptChanges();
                    this.ucLabelEditCount.Value = this.dtSoftWareVersion.Rows.Count.ToString();

                    this.ucLabelRcard.TextFocus(false, true);
                }
                catch (Exception ex)
                {
                    ApplicationRun.GetInfoForm().Add(ex.Message);
                    this.ucLabelRcard.TextFocus(false, true);
                }
                finally
                {
                    ((SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                    ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
                }
            }
        }