示例#1
0
        /// <summary>
        /// 工序调整(返工)
        /// </summary>
        /// <param name="context"></param>
        void ProcessAdjustion(HttpContext context)
        {
            string       _service = "ProcessHandler/OperationAdjustion";
            Result       rs       = new Result();
            ResultHelper rh       = new ResultHelper();
            DbHelper     db       = new DbHelper();
            Log          log      = new Log();

            string strUserName   = HttpContext.Current.Request["user_name"];
            string strSubOrders  = HttpContext.Current.Request["sub_orders"];
            string strReworkNote = HttpContext.Current.Request["rwk_note"];

            string strReceiver   = HttpContext.Current.Request["receiver"];
            string strReworkUser = HttpContext.Current.Request["rwk_user"];
            string strIssProcess = HttpContext.Current.Request["issue_process"];
            string strToProcess  = HttpContext.Current.Request["to_process"];
            string strReasonCate = HttpContext.Current.Request["reason_cate"];

            var json     = HttpContext.Current.Request["json"];
            var jsetting = new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            };
            Rework rework = (Rework)JsonConvert.DeserializeObject <Rework>(json, jsetting);//反序列化

            string sql_insert_rework = @"insert into hrework
                                   (wo_number,
                                   from_process,
                                   to_process,
                                   issue_process,
                                   receiver,
                                   rwk_user,
                                   reason_cate,
                                   reason_sub_cate,
                                   branch_type,
                                   rwk_note,
                                   creation_date,
                                   created_by)
                             values(
			                        '#wo_number',
			                        (select cur_process from horder where sub_order='#wo_number'),
			                        '{0}',
			                        '{1}',
			                        '{2}',
			                        '{3}',
			                        '{4}',
			                        '{5}',
			                        '{6}',
			                        '{7}',
			                        getdate(),
			                        '{8}');"            ;

            sql_insert_rework = string.Format(sql_insert_rework,
                                              rework.to_process,
                                              rework.issue_process,
                                              rework.receiver,
                                              rework.rwk_user,
                                              rework.reason_cate,
                                              rework.reason_sub_cate,
                                              rework.branch_type,
                                              rework.rwk_note,
                                              strUserName);
            sql_insert_rework = sql_insert_rework.Replace("#wo_number", "{0}");

            //string sql_update_order = @"updade horder
            //                                set next_process=(select cur_process from horder where sub_order='{0}')
            //                                where sub_order='{0}';";
            string sql_update_order    = @"update horder set cur_process='',next_process=(select process_name from hprocess where process_id={0}),
                                            status='WAIT' where sub_order='{1}';";
            string sql_insert_prdroute = @"insert into hprdroute
                                              (wo_number,
                                               process_id,
                                               process_name,
                                               sequence,
                                               creation_date,
                                               created_by)
                                              select '{0}',
                                                     process_id,
                                                     process_name,
                                                     (select sequence + 0.1
                                                        from dbo.hprdroute
                                                       where wo_number = '{0}'
                                                         and process_name = (select case cur_process when null then next_process when '' then next_process else cur_process end
                                                                               from horder
                                                                              where sub_order = '{0}')),
                                                     Getdate(),
                                                     'ProcessHandler/ProcessAdjustion'
                                                from hprocess
                                               where process_id = '{1}';";
            //而然要求按需作业(条码采集、检验等),暂时注释代码
            //string sql_insert_task = @"insert into htasks
            //                               (wo_number
            //                               ,parts_no
            //                               ,process_name
            //                               ,process_step
            //                               ,task_type
            //                               ,task
            //                               ,perform_type
            //                               ,creation_date
            //                               ,created_by)
            //                         select
            //                               {0},
            //                               '-1',
            //                               '{1}',
            //                               '',
            //                               'NOTE',
            //                               '{2}',
            //                               'MANUAL',
            //                               getdate(),
            //                               'ProcessHandler/OperationAdjustion'
            //                            from htasks where wo_number='{0}' and process_name in (
            //                                select process_name from hprdroute where wo_number='{0}' and sequence>=(
            //                                  select sequence from  hprdroute where wo_number='{0}' and process_name='{1}')
            //                                );";


            StringReader sr = new StringReader(strSubOrders);

            string strSubOrder           = string.Empty;
            string sql_insert_rework_t   = string.Empty;
            string sql_update_order_t    = string.Empty;
            string sql_insert_task_t     = string.Empty;
            string sql_insert_prdroute_t = string.Empty;

            while ((strSubOrder = sr.ReadLine()) != null)
            {
                //查看目标工序是否在订单的工艺路线中
                DataTable dt = db.ExecuteDataTable("select 1 from hprdroute where wo_number='" + strSubOrder + "' and process_id=" + rework.to_process + ";");
                if (dt.Rows.Count == 0)
                {
                    sql_insert_prdroute_t += string.Format(sql_insert_prdroute, strSubOrder, rework.to_process);
                    db.ExecuteNonQuery(sql_insert_prdroute_t);
                }

                sql_insert_rework_t += string.Format(sql_insert_rework, strSubOrder) + "\r\n";
                sql_update_order_t  += string.Format(sql_update_order, rework.to_process, strSubOrder) + "\r\n";
                //sql_insert_task_t += string.Format(sql_insert_task, strSubOrder, rework.to_process, strReworkNote);
            }

            //if (db.ExecuteNonQuery(sql_insert_prdroute_t) == -1) {
            //    rs.status = 0;
            //    rs.msg = rh.GenMsg(_service, rs.msg, sql_insert_rework_t);
            //    rs.item = rh.GenItem(strSubOrder);

            //    //rh.Response(context, rs);
            //} else
            if (db.ExecuteNonQuery(sql_update_order_t) == -1)
            {
                rs.status = 0;
                rs.msg    = rh.GenMsg(_service, rs.msg, sql_update_order_t);
                rs.item   = rh.GenItem(strSubOrder);

                //rh.Response(context, rs);
            }
            else if (db.ExecuteNonQuery(sql_insert_rework_t) == -1)
            {
                rs.status = 0;
                rs.msg    = rh.GenMsg(_service, rs.msg, sql_insert_task_t);
                rs.item   = rh.GenItem(strSubOrder);

                //rh.Response(context, rs);
            }
            else
            {
                rs.status = 1;
                rs.msg    = "";

                rh.Response(context, rs);
            }


            string strJson = JsonConvert.SerializeObject(rs);

            strJson = JsonConvert.SerializeObject(rs);
            context.Response.Clear();
            context.Response.ContentEncoding = Encoding.UTF8;
            context.Response.ContentType     = "application/json";
            context.Response.Write(strJson);
            context.Response.Flush();
            context.Response.End();
        }