Exemplo n.º 1
0
        protected void btnMakeBom_Click(object sender, EventArgs e)
        {
            try
            {
                if (Grid2.SelectedRowIndexArray.Length <= 0)
                {
                    Alert.Show("请选择产品");
                    return;
                }
                SQLHelper.DbHelperSQL.SetConnectionString("");
                string sql = "select count(*) from  Instruction where orderno='" + txtOrderNo.Text + "' and prono='" + Grid2.Rows[Grid2.SelectedRowIndex].Values[2] + "' ";
                if (int.Parse(SQLHelper.DbHelperSQL.GetSingle(sql, 30)) > 0)
                {
                    Alert.Show("已进行了备货确认无法再次生成生产BOM");
                    return;
                }
                string odtSN = Grid2.DataKeys[Grid2.SelectedRowIndex][0].ToString();
                sql = "select sn from dbo.BomHeader where OdtSN=" + odtSN + "";
                string    bomSN = SQLHelper.DbHelperSQL.GetSingle(sql, 30).ToString();
                ArrayList al    = new ArrayList();
                if (!string.IsNullOrEmpty(bomSN))
                {
                    //删除旧BOM
                    sql = "delete BomHeader where sn=" + bomSN;
                    log.Info("copy bom:::" + sql);
                    al.Add(sql);
                    sql = "delete BomDetail where fsn=" + bomSN;
                    log.Info("copy bom:::" + sql);
                    al.Add(sql);
                }

                //sql = "select count(*) from dbo.proBomHeader where ver=(select max(ver) from proBomHeader where prono='" + Grid2.Rows[Grid2.SelectedRowIndex].Values[2] + "') and  prono='" + Grid2.Rows[Grid2.SelectedRowIndex].Values[2] + "'";
                if (Grid2.Rows[Grid2.SelectedRowIndex].Values[2].ToString() != txtCurProno.Text)
                {
                    //复制BOM给当前产品
                    sql = "INSERT INTO proBomHeader(AllitemSN,ProName,ProNo,Ver,ClientProNo,ClientCode,Inputer,InputeDate,BomDate,fileno,BomExcel,QuoteProNo,QuoteBomVer,QuoteBomSN) select AllitemSN, '" + Grid2.Rows[Grid2.SelectedRowIndex].Values[3] + "', '" + Grid2.Rows[Grid2.SelectedRowIndex].Values[2] + "', (select ISNULL(max(ver)+1,1) from proBomHeader where prono='" + Grid2.Rows[Grid2.SelectedRowIndex].Values[2] + "'), ClientProNo, ClientCode, Inputer, InputeDate, BomDate, fileno, BomExcel,ProNo,Ver,sn from dbo.proBomHeader where sn =" + txtBomSn.Text;
                    log.Info("copy bom:::" + sql);
                    al.Add(sql);
                    sql = "INSERT INTO proBomDetail(subsn,ParentSN,Seq,FSN,AllitemSN,ItemNo,ItemName,Spec,Material,SurfaceDeal,ProUsingQuantity,Sclass,MakeMethod,Inputer,InputeDate,Updater,UpdateDate,WorkShop,ZuHe,Remark,ZongCheng,BaseNum,MainFrom,StoreHouse) select b.subsn,(case when CHARINDEX('.',seq)!= 0 then(select(a.SN) from ProBomDetail a  where a.fsn = " + txtBomSn.Text + " and a.Seq = REVERSE(SUBSTRING(REVERSE(b.seq), CHARINDEX('.', REVERSE(b.seq)) + 1, LEN(b.seq) - CHARINDEX('.', REVERSE(b.seq))))) else null end) ParentSN,Seq,(select sn from proBomHeader where ProNo='" + Grid2.Rows[Grid2.SelectedRowIndex].Values[2] + "' and ver=(select max(ver) from proBomHeader where prono='" + Grid2.Rows[Grid2.SelectedRowIndex].Values[2] + "')),AllitemSN,ItemNo,ItemName,Spec,Material,SurfaceDeal,ProUsingQuantity,Sclass,MakeMethod,Inputer,InputeDate,Updater,UpdateDate,WorkShop,ZuHe,Remark,ZongCheng,BaseNum,MainFrom,StoreHouse  from proBomDetail b   where fsn =" + txtBomSn.Text;
                    al.Add(sql);
                    log.Info("copy bom:::" + sql);
                }


                if (al.Count > 0 && SQLHelper.DbHelperSQL.ExecuteSqlTran(al))
                {
                }
                else
                {
                    Alert.Show("复制BOM失败");
                    return;
                }

                sql = "select max(ver) from proBomHeader where prono='" + Grid2.Rows[Grid2.SelectedRowIndex].Values[2] + "'";
                string ver = SQLHelper.DbHelperSQL.GetSingle(sql, 30).ToString();
                string fsn = "";
                if (CommFunction.reMakeBom(odtSN, Grid2.Rows[Grid2.SelectedRowIndex].Values[2].ToString(), Grid2.Rows[Grid2.SelectedRowIndex].Values[1].ToString(), ver, Grid2.Rows[Grid2.SelectedRowIndex].Values[4].ToString(), User.Identity.Name, out fsn))
                {
                    Alert.Show("生成成功");
                }
                else
                {
                    Alert.Show("生成失败");
                }
            }
            catch (Exception ee)
            {
                Alert.Show(ee.ToString());
            }
        }