Ejemplo n.º 1
0
        private void CommitStationMesService()
        {
            bool IsSuccess = true;

            try
            {
                //将数据提交
                if (this.cb_processItem.Text == "")
                {
                    MessageBox.Show("请选择需要修改的工艺!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                //MesService.Station[] stationList = new MesService.Station[this.radGridView1.RowCount];
                List <MesService.Station> stationsList = new List <MesService.Station>();
                var currentProcess = serviceClientTest.SelectCurrentTProcess();
                int processState   = 0;
                if (currentProcess == this.cb_processItem.Text)
                {
                    processState = 1;
                }
                int i = 0;
                foreach (var rowInfo in this.radGridView1.Rows)
                {
                    MesService.Station station = new MesService.Station();
                    station.ProcessName = this.cb_processItem.Text;
                    station.StationID   = rowInfo.Cells[0].Value.ToString();
                    station.StationName = rowInfo.Cells[1].Value.ToString();
                    if (station.StationName == "")
                    {
                        continue;
                    }
                    var userName = rowInfo.Cells[2].Value.ToString();
                    if (userName == "")
                    {
                        userName = MESMainForm.currentUser;
                    }
                    station.UserName     = userName;
                    station.ProcessState = processState;
                    var processDate = rowInfo.Cells[3].Value.ToString();
                    if (processDate == "")
                    {
                        processDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//新增
                    }
                    else
                    {
                        //修改
                        DataRow[] dataRows = stationDataTemp.Select($"{DATA_STATION_NAME} = '{station.StationName}'");
                        if (dataRows.Length < 1)
                        {
                            processDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                    }
                    station.UpdateDate = processDate;
                    stationsList.Add(station);
                    i++;
                }
                int delRow = serviceClient.DeleteAllStation(this.cb_processItem.Text);
                MesService.Station[] updateResult = serviceClient.InsertStation(stationsList.ToArray());
                foreach (var station in updateResult)
                {
                    if (station.Result < 1)
                    {
                        IsSuccess = false;
                        MessageBox.Show($"【{station.StationName}】更新失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                if (IsSuccess)
                {
                    MessageBox.Show("更新成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                InitCurrentProcessItem();
                SelectStationList(this.cb_processItem.Text);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Error(ex.Message + "\r\n" + ex.StackTrace);
                MessageBox.Show($"{ex.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }