Exemple #1
0
        private void BtnItemSave_Click(object sender, RoutedEventArgs e)
        {
            FmsActionFormulaMain main = tvMain.SelectedItem as FmsActionFormulaMain;

            if ((main == null) || (string.IsNullOrEmpty(main.PKNO)))
            {
                return;
            }
            FmsActionFormulaDetail detail = gbItem.DataContext as FmsActionFormulaDetail;

            if (detail == null)
            {
                return;
            }

            #region  校验

            if (string.IsNullOrEmpty(detail.FORMULA_CODE))
            {
                WPFMessageBox.ShowWarring("请选择配方主信息。", "保存");
                return;
            }

            if (string.IsNullOrEmpty(detail.FORMULA_DETAIL_NAME))
            {
                WPFMessageBox.ShowWarring("请输入配方明细名称。", "保存");
                return;
            }

            #endregion

            if (string.IsNullOrEmpty(detail.PKNO)) //新增
            {
                detail.PKNO = CBaseData.NewGuid();

                ws.UseService(s => s.AddFmsActionFormulaDetail(detail));

                //重新刷新数据
                List <FmsActionFormulaDetail> details =
                    ws.UseService(s => s.GetFmsActionFormulaDetails($"FORMULA_CODE = {main.FORMULA_CODE} AND USE_FLAG >= 0"))
                    .OrderBy(c => c.PROCESS_INDEX)
                    .ToList();
                gridItem.ItemsSource = details;
            }
            else  //修改
            {
                ws.UseService(s => s.UpdateFmsActionFormulaDetail(detail));
            }
            //提示保存成功

            gbItem.IsCollapsed = true;
            gbItem.Visibility  = Visibility.Collapsed;
            BindHelper.SetDictDataBindingGridItem(gbItem, gridItem);
        }
Exemple #2
0
        private void BtnItemSave_Click(object sender, RoutedEventArgs e)
        {
            FmsActionFormulaMain main = tvMain.SelectedItem as FmsActionFormulaMain;

            if ((main == null) || (string.IsNullOrEmpty(main.PKNO)))
            {
                return;
            }
            FmsActionFormulaDetail detail = gbItem.DataContext as FmsActionFormulaDetail;

            if (detail == null)
            {
                return;
            }

            #region  校验

            if (string.IsNullOrEmpty(detail.FORMULA_CODE))
            {
                WPFMessageBox.ShowWarring("请选择配方主信息。", "保存");
                return;
            }

            if (string.IsNullOrEmpty(detail.FORMULA_DETAIL_NAME))
            {
                WPFMessageBox.ShowWarring("请输入配方明细名称。", "保存");
                return;
            }

            #endregion

            if (string.IsNullOrEmpty(detail.PKNO)) //新增
            {
                detail.PKNO = CBaseData.NewGuid();

                FmsActionControl action = new FmsActionControl()
                {
                    PKNO        = CBaseData.NewGuid(),
                    ACTION_NAME = detail.FORMULA_DETAIL_NAME,
                    ACTION_TYPE = detail.PROCESS_ACTION_TYPE.ToString(),
                    START_CONDITION_TAG_PKNO  = string.IsNullOrEmpty(cmbCondition.Text)? "": cmbCondition.SelectedValue.ToString(),
                    START_CONDITION_VALUE     = tbConditionValue.Text,
                    EXECUTE_TAG_PKNO          = string.IsNullOrEmpty(cmbExecute.Text) ? "" : cmbExecute.SelectedValue.ToString(),
                    EXECUTE_WRITE_VALUE       = tbExecuteValue.Text,
                    EXECUTE_PARAM1_TAG_PKNO   = string.IsNullOrEmpty(cmbParam1.Text) ? "" : cmbParam1.SelectedValue.ToString(),
                    EXECUTE_PARAM2_TAG_PKNO   = string.IsNullOrEmpty(cmbParam2.Text) ? "" : cmbParam2.SelectedValue.ToString(),
                    FINISH_CONDITION_TAG_PKNO = string.IsNullOrEmpty(cmbFinish.Text) ? "" : cmbFinish.SelectedValue.ToString(),
                    FINISH_CONDITION_VALUE    = tbFinishValue.Text,
                };

                detail.PROCESS_ACTION_PKNO = action.PKNO;

                ws.UseService(s => s.AddFmsActionControl(action));

                ws.UseService(s => s.AddFmsActionFormulaDetail(detail));

                //重新刷新数据
                List <FmsActionFormulaDetail> details =
                    ws.UseService(s => s.GetFmsActionFormulaDetails($"FORMULA_CODE = {main.FORMULA_CODE} AND USE_FLAG >= 0"))
                    .OrderBy(c => c.PROCESS_INDEX)
                    .ToList();
                gridItem.ItemsSource = details;
            }
            else  //修改
            {
                FmsActionControl action = ws.UseService(s => s.GetFmsActionControlById(detail.PROCESS_ACTION_PKNO));
                if (action == null)
                {
                    action = new FmsActionControl()
                    {
                        PKNO        = CBaseData.NewGuid(),
                        ACTION_NAME = detail.FORMULA_DETAIL_NAME,
                        ACTION_TYPE = detail.PROCESS_ACTION_TYPE.ToString(),
                        START_CONDITION_TAG_PKNO  = string.IsNullOrEmpty(cmbCondition.Text) ? "" : cmbCondition.SelectedValue.ToString(),
                        START_CONDITION_VALUE     = tbConditionValue.Text,
                        EXECUTE_TAG_PKNO          = string.IsNullOrEmpty(cmbExecute.Text) ? "" : cmbExecute.SelectedValue.ToString(),
                        EXECUTE_WRITE_VALUE       = tbExecuteValue.Text,
                        EXECUTE_PARAM1_TAG_PKNO   = string.IsNullOrEmpty(cmbParam1.Text) ? "" : cmbParam1.SelectedValue.ToString(),
                        EXECUTE_PARAM2_TAG_PKNO   = string.IsNullOrEmpty(cmbParam2.Text) ? "" : cmbParam2.SelectedValue.ToString(),
                        FINISH_CONDITION_TAG_PKNO = string.IsNullOrEmpty(cmbFinish.Text) ? "" : cmbFinish.SelectedValue.ToString(),
                        FINISH_CONDITION_VALUE    = tbFinishValue.Text,
                    };

                    detail.PROCESS_ACTION_PKNO = action.PKNO;

                    ws.UseService(s => s.AddFmsActionControl(action));
                }
                else //修改控制
                {
                    action.ACTION_NAME = detail.FORMULA_DETAIL_NAME;
                    action.ACTION_TYPE = detail.PROCESS_ACTION_TYPE.ToString();
                    action.START_CONDITION_TAG_PKNO = string.IsNullOrEmpty(cmbCondition.Text)
                        ? ""
                        : cmbCondition.SelectedValue.ToString();
                    action.START_CONDITION_VALUE = tbConditionValue.Text;
                    action.EXECUTE_TAG_PKNO      =
                        string.IsNullOrEmpty(cmbExecute.Text) ? "" : cmbExecute.SelectedValue.ToString();
                    action.EXECUTE_WRITE_VALUE     = tbExecuteValue.Text;
                    action.EXECUTE_PARAM1_TAG_PKNO =
                        string.IsNullOrEmpty(cmbParam1.Text) ? "" : cmbParam1.SelectedValue.ToString();
                    action.EXECUTE_PARAM2_TAG_PKNO =
                        string.IsNullOrEmpty(cmbParam2.Text) ? "" : cmbParam2.SelectedValue.ToString();
                    action.FINISH_CONDITION_TAG_PKNO =
                        string.IsNullOrEmpty(cmbFinish.Text) ? "" : cmbFinish.SelectedValue.ToString();
                    action.FINISH_CONDITION_VALUE = tbFinishValue.Text;

                    ws.UseService(s => s.UpdateFmsActionControl(action));
                }

                ws.UseService(s => s.UpdateFmsActionFormulaDetail(detail));
            }

            //保存成功
            gbItem.IsCollapsed = true;
            gbItem.Visibility  = Visibility.Collapsed;
            BindHelper.SetDictDataBindingGridItem(gbItem, gridItem);
        }
Exemple #3
0
        /// <summary>
        /// 后台自动升级程序
        /// <param name="bFisrtCheck">是否首次检测</param>
        /// </summary>
        public static void UpdateAppVersion(bool bFisrtCheck)
        {
            try
            {
                if (File.Exists(UpgradeBatFile))
                {
                    File.Delete(UpgradeBatFile);
                } //删除升级文件

                string updateCmd    = "";
                int    iUpdateIndex = 0;   //升级文件的序号

                bool bForceUpdate = false; //强制升级
                foreach (SysAppInfo appInfo in AllModels)
                {
                    string        error;
                    List <string> value = VersionProcess.GetDBVersionNO(appInfo.MODEL_CODE, out error); //获取服务器的新版本

                    if (!string.IsNullOrEmpty(error))                                                   //错误
                    {
                        if (bFisrtCheck)                                                                //第一次检验失败
                        {
                            WPFMessageBox.ShowError(error + "请检查连接!", "系统启动失败");

                            App.AppExit(5); //系统退出
                        }
                        continue;
                    }

                    int    dbVersion  = -1;
                    string newAppPKNO = "";
                    if (value.Count >= 2)
                    {
                        newAppPKNO = value[0];
                        dbVersion  = SafeConverter.SafeToInt(value[1]);
                    }

                    if (dbVersion < appInfo.MODEL_INNER_VERSION) //服务器版本 < 当前版本 => 上传
                    {
                        string filename = Environment.CurrentDirectory + "\\" +
                                          (String.IsNullOrEmpty(appInfo.APP_RELATIVE_PATH)
                                              ? ""
                                              : appInfo.APP_RELATIVE_PATH + "\\") +
                                          appInfo.APP_NAME;

                        if (!File.Exists(filename))
                        {
                            continue;
                        }

                        #region   版本

                        SysAppInfo newApp = new SysAppInfo()
                        {
                            PKNO                = CBaseData.NewGuid(),
                            MODEL_CODE          = appInfo.MODEL_CODE,
                            MODEL_NAME          = appInfo.MODEL_NAME,
                            MODEL_INNER_VERSION = appInfo.MODEL_INNER_VERSION,
                            MODEL_VERSION       = appInfo.MODEL_VERSION,
                            APP_NAME            = appInfo.APP_NAME,
                            APP_RELATIVE_PATH   = appInfo.APP_RELATIVE_PATH,
                            VERSION_INTROD      = appInfo.VERSION_INTROD,
                            MODEL_CONTENT       = FileHelper.FileToBytes(filename), //上传文档
                            CREATED_BY          = CBaseData.LoginName,
                            CREATION_DATE       = DateTime.Now,
                            VERSION_TYPE        = appInfo.VERSION_TYPE,
                            REMARK              = appInfo.REMARK,
                        };

                        bool ret = VersionProcess.UploadApp(newApp); //上传到数据库

                        if (ret)
                        {
                            EventLogger.Log($"上传最新版本 {newApp.MODEL_VERSION} 的程序【{newApp.MODEL_NAME}】到服务器。");
                        }
                        #endregion
                    }
                    else if (dbVersion > appInfo.MODEL_INNER_VERSION) //服务器版本 > 当前版本 => 升级
                    {
                        #region  载最新版本

                        SysAppInfo newApp = VersionProcess.GetNewApp(newAppPKNO); //下载

                        #endregion

                        if (string.IsNullOrEmpty(newApp?.PKNO)) //下载失败
                        {
                            continue;
                        }

                        bool updateResult = false; //强制升级

                        #region 保存到本地,并升级

                        string newfilename = Environment.CurrentDirectory + "\\Temp\\" +
                                             (String.IsNullOrEmpty(newApp.APP_RELATIVE_PATH)
                                                 ? ""
                                                 : newApp.APP_RELATIVE_PATH + "\\") +
                                             newApp.APP_NAME;

                        string directory = Path.GetDirectoryName(newfilename);
                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }

                        FileHelper.BytesToFile(newApp.MODEL_CONTENT, newfilename);

                        string oldfilename = Environment.CurrentDirectory + "\\" +
                                             (String.IsNullOrEmpty(newApp.APP_RELATIVE_PATH)
                                                 ? ""
                                                 : newApp.APP_RELATIVE_PATH + "\\") +
                                             newApp.APP_NAME;

                        string filename = (String.IsNullOrEmpty(newApp.APP_RELATIVE_PATH)
                            ? ""
                            : newApp.APP_RELATIVE_PATH + "\\") +
                                          newApp.APP_NAME;
                        try
                        {
                            File.Copy(newfilename, oldfilename);
                            updateResult = true; //升级成功
                            EventLogger.Log($"【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 完成自动升级。");
                        }
                        catch (Exception)   //升级失败
                        {
                            iUpdateIndex++; //索引号

                            #region 形成升级Bat

                            updateCmd +=
                                $"echo {iUpdateIndex}. 正在升级 【{appInfo.MODEL_NAME}】 到 {appInfo.MODEL_VERSION} ..." +
                                Environment.NewLine;                                                    //显示提示信息
                            updateCmd += "ping 127.0.0.1 -n 2 > nul " + Environment.NewLine;            //暂停2s

                            updateCmd += "if not exist Temp\\" + filename + " (" + Environment.NewLine; //检验是否已经下载了文件
                            updateCmd += $"  echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} ... 尚未下载,升级失败!" +
                                         Environment.NewLine;                                           //
                            updateCmd += $")" + Environment.NewLine;                                    //

                            updateCmd += "copy /y " + "Temp\\" + filename + " " + filename + Environment.NewLine;
                            //复制 => 升级文件

                            updateCmd += "if %ERRORLEVEL% == 0 (" + Environment.NewLine; //复制成功
                            updateCmd += $"  echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级成功。" +
                                         Environment.NewLine;                            //
                            updateCmd +=
                                $"  echo %DATE% %TIME% 完成【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 的升级 >>log\\AutoUpdate.txt" +
                                Environment.NewLine;                                                                                                        //

                            updateCmd += ") else (" + Environment.NewLine;                                                                                  //复制失败

                            updateCmd += "  copy /y " + "Temp\\" + filename + " " + filename + Environment.NewLine;                                         //二次复制 => 升级文件

                            updateCmd += "  if %ERRORLEVEL% == 0 (" + Environment.NewLine;                                                                  //复制成功
                            updateCmd += $"    echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级成功。" + Environment.NewLine;                            //
                            updateCmd +=
                                $"    echo %DATE% %TIME% 完成【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 的升级 >>log\\AutoUpdate.txt" + Environment.NewLine; //
                            updateCmd += "  ) else (" + Environment.NewLine;
                            updateCmd +=
                                $"    echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级失败,请退出系统后,运行【{UpgradeBatFile}】。" +
                                Environment.NewLine; //
                            updateCmd +=
                                $"   echo %DATE% %TIME% 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级失败,错误代码为 %ERRORLEVEL% >>log\\AutoUpdate.txt" +
                                Environment.NewLine; //
                            updateCmd += "    pause" + Environment.NewLine;
                            updateCmd += "    exit" + Environment.NewLine;
                            updateCmd += "  )" + Environment.NewLine;
                            updateCmd += ")" + Environment.NewLine;

                            #endregion

                            updateResult = false;
                        }

                        #endregion

                        if ((!updateResult) && (!bForceUpdate)) //升级失败,检验是否强制升级
                        {
                            if (bFisrtCheck)
                            {
                                bForceUpdate = true; //强制升级
                            }
                            else  //不是第一次检测,则需要检测是否强制升级
                            {
                                int updateType = VersionProcess.CheckUpdateVersion(appInfo.MODEL_CODE,
                                                                                   appInfo.MODEL_INNER_VERSION.Value); //获取版本升级信息,是否强制升级

                                #region 强制升级

                                if (updateType == 2)     //强制升级
                                {
                                    bForceUpdate = true; //强制升级
                                }

                                #endregion
                            }
                        }
                    }
                } //end foreach

                if (!string.IsNullOrEmpty(updateCmd)) //有升级
                {
                    if (!Directory.Exists("log"))
                    {
                        Directory.CreateDirectory("log");
                    }
                    updateCmd = "@echo off " + Environment.NewLine +
                                " color fc " + Environment.NewLine +
                                " title ******** 客户端自动升级程序 ******* " + Environment.NewLine +
                                " echo *****************客户端自动升级程序(共" + iUpdateIndex + "个) ************* " +
                                Environment.NewLine + updateCmd;
                    updateCmd += "echo 系统升级成功!" + (bFisrtCheck ? "请重新打开程序。": "") + Environment.NewLine; //升级成功
                    updateCmd += "del /f /q " + UpgradeBatFile + Environment.NewLine;                   //删除本身
                    FileHelper.SaveStrToFile(updateCmd, UpgradeBatFile, true);                          //保存升级文件
                }

                if (bForceUpdate) //强制升级
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        WPFMessageBox.ShowWarring(
                            $"检测到系统有强制升级的新版本,系统自动升级失败,需要强制升级。" + Environment.NewLine +
                            "***!系统将退出!***", "自动升级程序");
                    }));

                    App.AppExit(5);
                }
            }
            catch (Exception ex)
            {
                NetLog.Error("自动升级程序失败,", ex);
                Console.WriteLine("自动升级程序失败,错误为:" + ex.Message);
            }
        }
Exemple #4
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            AmAssetMasterN asset = cmbDeviceInfo.SelectedItem as AmAssetMasterN;

            if (asset == null)
            {
                return;
            }
            //保存
            TmsDeviceToolsPos m_TmsDeviceToolsPos = dictInfo.DataContext as TmsDeviceToolsPos;

            if (m_TmsDeviceToolsPos == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(m_TmsDeviceToolsPos.TOOLS_POS_NO))
            {
                WPFMessageBox.ShowWarring("请输入刀号!", "保存");
                return;
            }

            if (string.IsNullOrEmpty(m_TmsDeviceToolsPos.PKNO)) //新增
            {
                TmsDeviceToolsPos check =
                    ws.UseService(s => s.GetTmsDeviceToolsPoss($"TOOLS_POS_NO = '{m_TmsDeviceToolsPos.TOOLS_POS_NO}' AND DEVICE_PKNO = '{asset.PKNO}' AND USE_FLAG > 0 "))
                    .FirstOrDefault();
                if (check != null)
                {
                    WPFMessageBox.ShowWarring("该设备的刀位号已经存在,不能新增相同的刀位号!", "保存");
                    return;
                }

                m_TmsDeviceToolsPos.PKNO             = Guid.NewGuid().ToString("N");
                m_TmsDeviceToolsPos.CREATION_DATE    = DateTime.Now;
                m_TmsDeviceToolsPos.CREATED_BY       = CBaseData.LoginName;
                m_TmsDeviceToolsPos.LAST_UPDATE_DATE = DateTime.Now;

                ws.UseService(s => s.AddTmsDeviceToolsPos(m_TmsDeviceToolsPos));
            }
            else  //修改
            {
                TmsDeviceToolsPos check =
                    ws.UseService(
                        s =>
                        s.GetTmsDeviceToolsPoss(
                            $"TOOLS_POS_NO = '{m_TmsDeviceToolsPos.TOOLS_POS_NO}' AND PKNO <> '{m_TmsDeviceToolsPos.PKNO}' AND DEVICE_PKNO = '{asset.PKNO}' AND USE_FLAG > 0 "))
                    .FirstOrDefault();
                if (check != null)
                {
                    WPFMessageBox.ShowWarring("该设备的刀位号已经存在,不能修改为该刀位号!", "保存");
                    return;
                }
                m_TmsDeviceToolsPos.LAST_UPDATE_DATE = DateTime.Now;
                m_TmsDeviceToolsPos.UPDATED_BY       = CBaseData.LoginName;
                ws.UseService(s => s.UpdateTmsDeviceToolsPos(m_TmsDeviceToolsPos));
            }

            GetPage();  //重新加载

            gbItem.IsCollapsed = true;

            dictInfo.Visibility = Visibility.Collapsed;
        }
Exemple #5
0
 private void bTestMessageBoxWarring_Click(object sender, RoutedEventArgs e)
 {
     WPFMessageBox.ShowWarring((sender as Button).Content.ToString(), "测试");
 }
Exemple #6
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            //保存
            AmAssetMasterN     asset    = cmbAssetInfo.SelectedItem as AmAssetMasterN;
            FmsAssetTagSetting assetTag = gbItem.DataContext as FmsAssetTagSetting;

            if (assetTag == null)
            {
                return;
            }

            #region 校验

            if (asset == null)
            {
                MessageBox.Show("请选择设备!", "保存", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            if (!string.IsNullOrEmpty(assetTag.TAG_CODE)) //标签编码
            {
                List <FmsAssetTagSetting> existTags = _fmsClient.UseService(s =>
                                                                            s.GetFmsAssetTagSettings(
                                                                                $"USE_FLAG = 1 AND TAG_CODE = '{assetTag.TAG_CODE}'"));
                if (!string.IsNullOrEmpty(assetTag.PKNO))  //修改
                {
                    existTags = existTags.Where(c => c.PKNO != assetTag.PKNO).ToList();
                }

                if (existTags.Any())
                {
                    WPFMessageBox.ShowWarring(
                        $"该标签编码【{assetTag.TAG_CODE}】已存在不能" + (string.IsNullOrEmpty(assetTag.PKNO) ? "添加" : "修改") + "为这个编码!",
                        "保存");
                    return;
                }
            }

            #endregion

            #region 保存

            if (string.IsNullOrEmpty(assetTag.PKNO))
            {
                assetTag.PKNO             = CBaseData.NewGuid();
                assetTag.CREATED_BY       = CBaseData.LoginName;
                assetTag.CREATION_DATE    = DateTime.Now;
                assetTag.LAST_UPDATE_DATE = DateTime.Now; //最后修改日期
                _fmsClient.UseService(s => s.AddFmsAssetTagSetting(assetTag));
            }
            else
            {
                assetTag.UPDATED_BY       = CBaseData.LoginName;
                assetTag.LAST_UPDATE_DATE = DateTime.Now;
                _fmsClient.UseService(s => s.UpdateFmsAssetTagSetting(assetTag));
            }
            NotificationInvoke.NewNotification("保存", "设备通讯标签配置信息已保存。");

            #endregion

            GetPage();  //重新刷新数据,根据需求是否进行刷新数据

            //保存成功
            gbItem.IsCollapsed = true;
            gbItem.Visibility  = Visibility.Collapsed;
            BindHelper.SetDictDataBindingGridItem(gbItem, gridItem);
        }