系列化和反系列化使用(维修信息)

public MessageContract GetFaultByNo(MessageContract Msg)
        {

            using (var context = new BizServiceContext())
            {
                SFC_REPAIR result = new SFC_REPAIR();//创建返回对象
                OracleCommand cmd = (OracleCommand)context.Database.Connection.CreateCommand();
                try
                {

                    if (cmd.Connection.State == ConnectionState.Closed)
                    {
                        cmd.Connection.Open();
                    }
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "sfc_dc_re_pub.validate_sn_info";
                    OracleCommandBuilder.DeriveParameters(cmd);//自动调用存储过程获取其所有参数
                    cmd.Parameters["p_inv_org"].Value = Msg.Context["p_inv_org"];//赋值Input类参数
                    cmd.Parameters["p_sn"].Value = Msg.Context["p_sn"];
                    cmd.Parameters["p_workcenter_id"].Value = Msg.Context["p_workcenter_id"];
                    cmd.Parameters["p_user_code"].Value = Msg.Context["p_user_code"];
                    OracleDataAdapter oda = new OracleDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    oda.Fill(ds);//获取所有游标表
                    if (string.IsNullOrEmpty(cmd.Parameters["x_ret_code"].Value.ToString()) || cmd.Parameters["x_ret_code"].Value.ToString() == "0")//没有错误即赋值返回对象
                    {
                        DataRow dr = ds.Tables[0].Rows[0];
                        result.INV_ORG_ID = int.Parse(dr["INV_ORG_ID"].ToString());
                        result.MO_ID = dr["MO_ID"].ToString();
                        result.MO_CODE = dr["MO_CODE"].ToString();
                        result.MO_NAME = dr["MO_NAME"].ToString();
                        result.PRODUCT_DESC = dr["PRODUCT_DESC"].ToString();
                        result.SN = dr["SN"].ToString();
                        result.SRC_WORKCENTER = dr["SRC_WORKCENTER"].ToString();
                        //result.workcenter_property = dr["workcenter_property"].ToString();
                        result.workcenter_curr = dr["src_workcenter_curr"].ToString();
                        result.Faults = new ObservableCollection<CheckBoxModel>();
                        if (ds.Tables.Count > 1)
                        {
                            foreach (DataRow row in ds.Tables[1].Rows)
                            {
                                CheckBoxModel cm = new CheckBoxModel();
                                cm.USE_LEVEL = row["USE_LEVEL"].ToString();
                                if (!string.IsNullOrWhiteSpace(cm.SECOND_DEFECT_CODE_ID))
                                {
                                    cm.Value = cm.SECOND_DEFECT_CODE_ID;
                                    cm.Text = cm.FIRST_DEFECT_LEVEL_DESC + "->" + cm.SECOND_DEFECT_LEVEL_DESC;
                                }
                                else
                                {
                                    cm.Value = cm.FIRST_DEFECT_CODE_ID;
                                    cm.Text = cm.FIRST_DEFECT_LEVEL_DESC;
                                }
                                result.Faults.Add(cm);
                            }
                        }
                        Msg.IsSucess = true;
                        Msg.SetMessageDataModel(JsonConvert.SerializeObject(result));
                    }
                    else//有错误抛出异常
                    {
                        Msg.IsSucess = false;
                        Msg.ErrorCode = cmd.Parameters["x_ret_code"].Value.ToString();
                        Msg.ErrorMessage = cmd.Parameters["x_ret_msg"].Value.ToString();
                    }
                }
                catch (Exception ex)
                {
                    Msg.ErrorMessage = string.Format("{0}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace);
                    Msg.IsSucess = false;
                }
                finally
                {
                    if (cmd.Connection.State != ConnectionState.Closed)
                    {
                        cmd.Connection.Close();
                    }
                }
            }

            return Msg;
        }


public void GetFaultByNo()
        {
            ClearData();
            try
            {
                //当前登陆系统人员包含的所有工作中心,权限可能实时变动,不用全局变量
                List<string> ListUserWorkCenter = new List<string>();
                ListUserWorkCenter = GetUserInWorkCenter();

                var contract = new MessageContract();
                contract.InvokeMethod = "GetFaultByNo";
                contract.MessageToken = Assembly.GetExecutingAssembly().GetName().Name;
                contract.Context["p_inv_org"] = Convert.ToInt32(this.Framework.FrameworkContext[Midea.MES.Platform.Common.FrameworkSymbol.SYS_INFO_KEY_INV_ORG_ID]);
                contract.Context["p_sn"] = BarCode;               
                contract.Context["p_workcenter_id"] = WorkCenter.ID;     
                contract.Context["p_user_code"] = this.Framework.FrameworkContext[Midea.MES.Platform.Common.FrameworkSymbol.SYS_INFO_KEY_USER_CODE];
                var msgContract = this.Framework.DataService.DoRequest(contract);
                if (msgContract.IsSucess)
                {
                    var result = msgContract.GetMessageDataModelClass<string>();
                    _model = JsonConvert.DeserializeObject<SFC_REPAIR>(result);
                    if (_model != null)
                    {
                        if (IsToUpper)
                        {
                            CurrSN = _model.SN.ToUpper();
                        }
                        else
                        {
                            CurrSN = _model.SN;
                        }
                        WorkNo = _model.MO_NAME;
                        PDesc = _model.PRODUCT_DESC;
                        if (_model.Faults.Count > 0)
                        {
                            FaultInfo = _model.Faults;
                            FaultInfo.FirstOrDefault().IsCheck = true;
                            //当前登陆人不包含录入的那个工作中心,进一步确认是否有检查工序
                            if (!ListUserWorkCenter.Contains(_model.workcenter_curr))
                            {
                                //获取当前工作中心是否含有[检查工序]
                                string workcenter_property;
                                workcenter_property = Getworkcenter_property(_model.workcenter_curr);
                                workcenter_property = string.IsNullOrEmpty(workcenter_property) ? "0" : workcenter_property;
                                g_bCanModified = this.CheckFromPQC(Convert.ToInt32(workcenter_property)); //是否含有[检查工序]

                            }
                            else
                            {
                                g_bCanModified = true;
                            }

                            //加载QC过来的所有问题点
                            g_PQCListProblem.Clear();
                            foreach (var fault in FaultInfo)
                            {
                                GetProblemsByIds(fault);
                            }

                            GetProblemsByIds(FaultInfo.FirstOrDefault());
                        }
                        MessageInvoker.ShowSuccess(string.Format("条码【" + BarCode + "】信息加载成功!"));
                        BarCode = string.Empty;
                    }
                    else
                    {
                        save_log("1", string.Format("条码[{0}]提交失败!错误信息:" + msgContract.ErrorMessage, BarCode));
                        MessageInvoker.ShowError(string.Format("未找到该条码记录"));
                    }

                }
                else
                {
                    save_log("1", string.Format("条码[{0}]提交失败!错误信息:" + msgContract.ErrorMessage, BarCode));
                    MessageInvoker.ShowError(string.Format("载入维修信息时发生错误:{0},错误代码:{1}", msgContract.ErrorMessage, msgContract.ErrorCode));
                }
            }
            catch
            {
                save_log("1", string.Format("条码[{0}]提交失败!错误信息:" + "载入返修信息时发生未知错误", BarCode));
                MessageInvoker.ShowError(string.Format("维修信息时发生未知错误"));
            }
        }


你可能感兴趣的:(序列化,系列化)