Пример #1
0
        //添加退料单单身到框框内(并未插入到数据库)
        protected void Return_Line_Commit(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(invoice_no.Value))
                {
                    PageUtil.showToast(this, "请生成单据号或填写单据号再操作");
                    return;
                }
                string Invoice_no = invoice_no.Value;


                if (invoiceDC.getReturnHeaderBySome(Invoice_no, "", "") == null)
                {
                    PageUtil.showToast(this, "请确定单据号存在");
                    return;
                }
                DataSet ds = invoiceDC.getReturnHeaderBySome(invoice_no.Value, "", "");

                //工单退料时
                if (ds.Tables[0].Rows[0]["return_type"].ToString() == "工单退料")
                {
                    string Return_wo_no = DropDownList_return_wo_no.SelectedValue.ToString();
                    string Item_name    = DropDownList_item_name.SelectedValue.ToString();

                    //检查信息
                    if (DropDownList_return_wo_no.SelectedValue.ToString() == "--选择工单--" || DropDownList_item_name.SelectedValue.ToString() == "--选择料号--")
                    {
                        PageUtil.showToast(this, "请检查信息是否填写完整和无误");
                        return;
                    }

                    if (DropDownList_operation_seq_num.SelectedValue.ToString() == "--选择制程--" || DropDownList_return_sub_key.SelectedValue.ToString() == "--选择库别--")
                    {
                        PageUtil.showToast(this, "请将信息填写完全");
                        return;
                    }
                    int Operation_seq_num = int.Parse(DropDownList_operation_seq_num.SelectedValue.ToString());
                    int Return_sub_key    = int.Parse(DropDownList_return_sub_key.SelectedValue.ToString());
                    //string Frame_key = DropDownList_frame_key.SelectedValue.ToString();

                    if (return_qty.Value == "")
                    {
                        PageUtil.showToast(this, "请填写退料量并保证大于0");
                        return;
                    }

                    int Return_qty = int.Parse(return_qty.Value);
                    if (Return_qty <= 0)
                    {
                        PageUtil.showToast(this, "请填写退料量并保证大于0");
                        return;
                    }

                    if (Return_qty > int.Parse(return_limit.Value))
                    {
                        PageUtil.showToast(this, "当前为工单退料,退料量不能大于退料上限");
                        return;
                    }


                    //从数据库中获取该单据对应的line_num值
                    int Line_num = invoiceDC.getLine_numByInvoice_no(Invoice_no);
                    //Line_num生成失败
                    if (Line_num == -1)
                    {
                        PageUtil.showToast(this, "添加单身失败");
                        return;
                    }

                    //退回量不能超过该工单领料的量未实现

                    DataTable table = new DataTable();

                    table = GetGridViewData(table);

                    //当框框中已经有一条数据及以上时,需要对line_num做处理
                    if (table.Rows.Count >= 1)
                    {
                        Line_num = Line_num + table.Rows.Count;
                    }


                    //检验数据库中相同工单+料号的情况下,退料量有没有超过临界值
                    int db_return_qty = invoiceDC.getReturn_qty(Return_wo_no, Item_name);
                    if (Return_qty + db_return_qty > int.Parse(return_limit.Value))
                    {
                        PageUtil.showToast(this, "该料号退料量超过退料上限(发料量+领料量)了,不能再申请退料,请去查看相关信息再申请");
                        return;
                    }


                    //当框框中已经有多条数据时,需要检验此时添加的新单身是否与在框框中的单身信息一样(工单号+料号),需要对料号数量进行管控
                    int qty = 0;
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        if (Return_wo_no == table.Rows[i].ItemArray[1].ToString() && Item_name == table.Rows[i].ItemArray[2].ToString())
                        {
                            //累加已经退的料
                            qty += int.Parse(table.Rows[i].ItemArray[4].ToString());

                            //判断该工单下的该料号退料量是否超过退料上限(发料量+领料量)
                            if (Return_qty + qty > int.Parse(return_limit.Value))
                            {
                                PageUtil.showToast(this, "该料号退料量超过退料上限(发料量+领料量)了,不能再申请领料");
                                return;
                            }
                        }
                    }



                    DataRow sourseRow = table.NewRow();
                    sourseRow["line_num"]          = Line_num;
                    sourseRow["return_wo_no"]      = Return_wo_no;
                    sourseRow["item_name"]         = Item_name;
                    sourseRow["operation_seq_num"] = Operation_seq_num;
                    sourseRow["return_qty"]        = Return_qty;
                    sourseRow["return_sub_key"]    = Return_sub_key;
                    //sourseRow["frame_key"] = Frame_key;
                    sourseRow["create_man"]  = user;
                    sourseRow["create_time"] = DateTime.Now;

                    table.Rows.Add(sourseRow);

                    GridView1.DataSource = table;

                    GridView1.DataBind();

                    //提交单个单身数据成功时,清除用户已填写的单身数据,方便用户填写下一个单身
                    DropDownList_return_wo_no.SelectedValue      = "--选择工单--";
                    DropDownList_item_name.SelectedValue         = "--选择料号--";
                    DropDownList_operation_seq_num.SelectedValue = "--选择制程--";
                    //DropDownList_frame_key.SelectedValue = "--选择料架--";
                    DropDownList_return_sub_key.SelectedValue = "--选择库别--";

                    return_qty.Value   = "";
                    return_limit.Value = "";
                }


                //非工单退料时
                else
                {
                    string Item_name2 = item_name2.Value;
                    int    Subinventory2;
                    try
                    {
                        Subinventory2 = int.Parse(invoiceDC.getSubinventory_Key(subinventory2.Value).Tables[0].Rows[0]["subinventory_key"].ToString());
                    }
                    catch (Exception e2)
                    {
                        PageUtil.showToast(this, "请检查库别是否填写正确,库别表中没有对应数据");
                        return;
                    }
                    //string Frame2 = frame2.Value;
                    int Route_id;
                    int Return_qty2;

                    if (String.IsNullOrWhiteSpace(Item_name2) == true)
                    {
                        PageUtil.showToast(this, "请将非工单退料部分数据填写完整");
                        return;
                    }

                    if (invoiceDC.getItem_name(Item_name2) == null)
                    {
                        PageUtil.showToast(this, "请重新输入料号,该料号不存在于料号表");
                        return;
                    }

                    //if (invoiceDC.getFrame_name(Frame2) == null)
                    //{
                    //    PageUtil.showToast(this, "请重新输入料架,该料架不存在于料架表");
                    //    return;
                    //}

                    //if (invoiceDC.getSubinventoryByFrame(Frame2) == null)
                    //{
                    //    PageUtil.showToast(this, "请重新输入库别,该料架不属于该库别下");
                    //    return;
                    //}

                    try
                    {
                        Route_id = int.Parse(invoiceDC.getRoute(operation_seq_num2.Value).Tables[0].Rows[0]["route_id"].ToString());
                    }
                    catch (Exception e2)
                    {
                        PageUtil.showToast(this, "请检查制程代号是否填写正确,制程表中没有对应数据");
                        return;
                    }

                    try
                    {
                        Return_qty2 = int.Parse(return_qty2.Value);
                    }
                    catch (Exception e2)
                    {
                        PageUtil.showToast(this, "请规范填写退料量");
                        return;
                    }

                    if (Return_qty2 <= 0)
                    {
                        PageUtil.showToast(this, "请填写退料量并保证大于0");
                        return;
                    }

                    //从数据库中获取该单据对应的line_num值
                    int Line_num = invoiceDC.getLine_numByInvoice_no(Invoice_no);
                    //Line_num生成失败
                    if (Line_num == -1)
                    {
                        PageUtil.showToast(this, "添加单身失败");
                        return;
                    }

                    //退回量不能超过该工单领料的量未实现

                    DataTable table = new DataTable();

                    table = GetGridViewData(table);

                    //当框框中已经有一条数据及以上时,需要对line_num做处理
                    if (table.Rows.Count >= 1)
                    {
                        Line_num = Line_num + table.Rows.Count;
                    }

                    DataRow sourseRow = table.NewRow();
                    sourseRow["line_num"]          = Line_num;
                    sourseRow["return_wo_no"]      = "none";
                    sourseRow["item_name"]         = Item_name2;
                    sourseRow["operation_seq_num"] = Route_id;
                    sourseRow["return_qty"]        = Return_qty2;
                    sourseRow["return_sub_key"]    = Subinventory2;
                    //sourseRow["frame_key"] = Frame2;
                    sourseRow["create_man"]  = user;
                    sourseRow["create_time"] = DateTime.Now;

                    table.Rows.Add(sourseRow);

                    GridView1.DataSource = table;

                    GridView1.DataBind();

                    //提交单个单身数据成功时,清除用户已填写的单身数据,方便用户填写下一个单身
                    item_name2.Value    = "";
                    subinventory2.Value = "";
                    //frame2.Value = "";
                    operation_seq_num2.Value = "";
                    return_qty2.Value        = "";
                }
            }
            catch (Exception e2)
            {
                PageUtil.showToast(this, "添加单身失败");
            }
        }