public string InsertReturnInBillDetail(string billNo)
        {
            DataSet        ds     = this.GenerateEmptyTables();
            DataTable      dt     = this.ReturnInBill();
            DownOutBillBll bll    = new DownOutBillBll();
            string         idList = "";

            foreach (DataRow d in dt.Rows)
            {
                idList += d["ID"].ToString() + ",";
            }

            DataRow[] row = dt.Select("1=1");
            for (int i = 0; i < row.Length; i++)
            {
                if (row[i].RowState != DataRowState.Deleted)
                {
                    decimal   quantity = Convert.ToDecimal(row[i]["QUANTITY"].ToString());
                    DataTable prodt    = bll.DownProductRate(row[i]["CIGARETTECODE"].ToString()); //
                    decimal   rate     = Convert.ToDecimal(prodt.Rows[0]["JIANRATE"].ToString()); //bll.Quantity(row[i]["CIGARETTECODE"].ToString());
                    DataRow[] dr       = dt.Select("CIGARETTECODE ='" + row[i]["CIGARETTECODE"] + "' and ID <>'" + row[i]["ID"] + "'");

                    if (dr.Length < 1)
                    {
                        DataRow detailrow = ds.Tables["WMS_IN_BILLDETAIL"].NewRow();
                        detailrow["BILLNO"]        = billNo;
                        detailrow["PRODUCTCODE"]   = row[i]["CIGARETTECODE"];
                        detailrow["PRICE"]         = 0;
                        detailrow["QUANTITY"]      = Convert.ToDecimal(row[i]["QUANTITY"].ToString()) / rate;
                        detailrow["INPUTQUANTITY"] = Convert.ToDecimal(row[i]["QUANTITY"].ToString()) / rate;
                        detailrow["UNITCODE"]      = prodt.Rows[0]["JIANCODE"];//
                        ds.Tables["WMS_IN_BILLDETAIL"].Rows.Add(detailrow);
                    }
                    else
                    {
                        DataRow drow = ds.Tables["WMS_IN_BILLDETAIL"].NewRow();
                        foreach (DataRow r in dr)
                        {
                            quantity          += Convert.ToDecimal(r["QUANTITY"].ToString());
                            row[i]["QUANTITY"] = quantity;
                            r.Delete();
                        }
                        drow["BILLNO"]        = billNo;
                        drow["PRODUCTCODE"]   = row[i]["CIGARETTECODE"];
                        drow["PRICE"]         = 0;
                        drow["QUANTITY"]      = Convert.ToDecimal(row[i]["QUANTITY"].ToString()) / rate;
                        drow["INPUTQUANTITY"] = Convert.ToDecimal(row[i]["QUANTITY"].ToString()) / rate;
                        drow["UNITCODE"]      = prodt.Rows[0]["JIANCODE"]; // "002";
                        ds.Tables["WMS_IN_BILLDETAIL"].Rows.Add(drow);
                    }
                }
            }

            this.InsertReturnInBillDetail(ds);
            idList = idList.Substring(0, idList.Length - 1);
            return(idList);
        }