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;
                }
            }
        }
        private void DoUpgrade()
        {
            if (this.ucLabelEditRCard.Value.Trim().Length == 0)
            {
                this.ucLabelEditRCard.TextFocus(true, true);
                return;
            }

            if (this.ucLabelEditSoftVersion.Value.Trim().Length == 0)
            {
                ApplicationRun.GetInfoForm().Add(new UserControl.Message(MessageType.Normal, "$CS_PleaseChooseSoftVersion"));
                this.ucLabelEditSoftVersion.TextFocus(false, true);
                return;
            }

            if (this.m_MaterialList.Rows.Count == 0)
            {
                this.ucLabelEditRCard.Value = "";
                ApplicationRun.GetInfoForm().Add(new UserControl.Message(MessageType.Normal, "$CS_PleaseInputFGRcard"));
                this.ucLabelEditRCardFG.TextFocus(false, true);
                return;
            }

            DataView dv = this.m_MaterialList.Copy().DefaultView;

            dv.RowFilter = "Checked='True'";
            if (dv.Count == 0)
            {
                this.ucLabelEditRCard.Value = "";
                ApplicationRun.GetInfoForm().Add(new UserControl.Message(MessageType.Normal, "$CS_MustChooseOneMItem"));
                return;
            }

            string newVersion = FormatHelper.PKCapitalFormat(FormatHelper.CleanString(this.ucLabelEditSoftVersion.Value));
            string mItemCode  = dv[0].Row["ItemCode"].ToString();
            string rcard      = FormatHelper.PKCapitalFormat(this.ucLabelEditRCard.Value.Trim());

            Messages messages = 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);

                // Get Product Info
                messages = this.GetProduct(sourceRCard);
                if (!messages.IsSuccess() || product == null || product.LastSimulation == null)
                {
                    ApplicationRun.GetInfoForm().Add(new UserControl.Message(MessageType.Error, "$NoProductInfo"));
                    this.ucLabelEditRCard.TextFocus(false, true);
                    return;
                }
                DataCollectFacade    dcf        = new DataCollectFacade(this.DataProvider);
                OnWipSoftVer4Upgrade oldVersion = dcf.GetOnWipSoftVersion2Upgrade(sourceRCard, mItemCode);
                if (oldVersion == null)
                {
                    ApplicationRun.GetInfoForm().Add(new UserControl.Message(MessageType.Error, "$Error_CanNotFindItemSoftVer"));
                    this.ucLabelEditRCard.TextFocus(false, true);
                    return;
                }

                if (string.Compare(oldVersion.SoftwareVersion, newVersion, true) == 0)
                {
                    ApplicationRun.GetInfoForm().Add(new UserControl.Message(MessageType.Normal, "$CS_AlreadyUpgraded"));
                    this.ucLabelEditRCard.TextFocus(false, true);
                    return;
                }

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

                messages.AddMessages(dcf.UpgradeNewSoftVer(oldVersion, resource, ApplicationService.Current().UserCode, newVersion));
                if (!messages.IsSuccess())
                {
                    ApplicationRun.GetInfoForm().Add(messages);
                    this.ucLabelEditRCard.TextFocus(false, true);
                    return;
                }

                DataRow rowNew = this.m_UpgradeLog.NewRow();
                rowNew["RCard"]           = rcard;
                rowNew["ItemDescription"] = oldVersion.ItemDescription;
                rowNew["SemiGoodRCard"]   = oldVersion.RunningCard;
                rowNew["OldVersion"]      = oldVersion.SoftwareVersion;
                rowNew["NewVersion"]      = newVersion;
                this.m_UpgradeLog.Rows.Add(rowNew);
                this.m_UpgradeLog.AcceptChanges();
                this.ucLabelEditCount.Value = this.m_UpgradeLog.Rows.Count.ToString();

                ApplicationRun.GetInfoForm().Add(new UserControl.Message(MessageType.Success, "$CS_UpgradeSuccess"));
                this.ucLabelEditRCard.TextFocus(false, true);
            }
            catch (Exception ex)
            {
                ApplicationRun.GetInfoForm().Add(ex.Message);
                this.ucLabelEditRCard.TextFocus(false, true);
            }
            finally
            {
                ((SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                ((SQLDomainDataProvider)DataProvider).PersistBroker.AutoCloseConnection = true;
            }
        }