Beispiel #1
0
        private void btnSplit_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                string sBarCode = lBarCodeScaned.Text.Trim();

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string   sSQL     = "select getdate()";
                    DateTime dNow     = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd"));

                    sSQL = @"
select * 
from _BarCodeLabel 
where 1=1 
order by BarCode desc
";
                    sSQL = sSQL.Replace("1=1", "1=1 and BarCode = '" + sBarCode + "'");
                    sSQL = sSQL.Replace("1=1", "1=1 and  iSOsID = '" + txtiSOsID.Text.Trim() + "'");

                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Please scan barcode");
                    }

                    if (BaseFunction.ReturnDecimal(txtLotQTY.Text.Trim()) != BaseFunction.ReturnDecimal(dt.Rows[0]["LOTQTY"]))
                    {
                        throw new Exception("Please scan the bar code again");
                    }

                    if (BaseFunction.ReturnDecimal(txtLotQTY.Text.Trim()) != BaseFunction.ReturnDecimal(gridView1.Columns["LOTQTY"].SummaryItem.SummaryValue))
                    {
                        throw new Exception("Qty err");
                    }

                    sSQL = @"
update [_BarCodeLabel] set LOTQTY = 0,[Status] = '调整' where BarCode = '{0}' and iSOsID = '{1}' 
";
                    sSQL = string.Format(sSQL, lBarCodeScaned.Text.Trim(), txtiSOsID.Text.Trim());
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    Model.BarStatus models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                    models.BarCode     = lBarCodeScaned.Text.Trim();
                    models.Type        = "调整";
                    models.QTY         = 0;
                    models.UpdateTime  = dNow;
                    models.CreateDate  = dNowDate;
                    models.CreateUid   = sUserID;
                    models.iSOsID      = BaseFunction.ReturnLong(txtiSOsID.Text);
                    models.RoutingFrom = dt.Rows[0]["Process"].ToString().Trim();
                    models.RoutingTo   = dt.Rows[0]["Process"].ToString().Trim();
                    DAL.BarStatus dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus();
                    sSQL = dals.Add(models);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                    //回写上一道工序的结束时间
                    sSQL = @"
declare @iID int 
select @iID = max(iID)
from _BarStatus
where [BarCode] = '{0}' and iSOsID = '{1}'
    and iID < (
        select max(iID) as maxID
        from _BarStatus
        where [BarCode] = '{0}' and iSOsID = '{1}'
    )

update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}'
";
                    sSQL = string.Format(sSQL, models.BarCode, models.iSOsID, dNow);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        string  sBarCodeNew = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim();
                        decimal dQty        = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY));

                        if (sBarCodeNew == "")
                        {
                            continue;
                        }

                        DAL._BarCodeLabel   dal   = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._BarCodeLabel();
                        Model._BarCodeLabel model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._BarCodeLabel();
                        model = dal.DataRowToModel(dt.Rows[0]);

                        model.oldBarCode = sBarCode;
                        model.BarCode    = sBarCodeNew;
                        model.LOTQTY     = dQty;
                        model.Status     = "调整";

                        if (sBarCode == sBarCodeNew)
                        {
                            sSQL = dal.Update(model, model.BarCode, model.iSOsID);
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        else
                        {
                            sSQL = dal.Add(model);
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }

                        models             = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                        models.BarCode     = model.BarCode;
                        models.Type        = "调整";
                        models.QTY         = dQty;
                        models.UpdateTime  = dNow;
                        models.CreateDate  = dNowDate;
                        models.CreateUid   = sUserID;
                        models.iSOsID      = BaseFunction.ReturnLong(txtiSOsID.Text);
                        models.RoutingFrom = model.Process;
                        models.RoutingTo   = model.Process;
                        dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus();
                        sSQL = dals.Add(models);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                        //回写上一道工序的结束时间
                        sSQL = @"
declare @iID int 
select @iID = max(iID)
from _BarStatus
where [BarCode] = '{0}' and iSOsID = '{1}'
    and iID < (
        select max(iID) as maxID
        from _BarStatus
        where [BarCode] = '{0}' and iSOsID = '{1}'
    )

update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}'
";
                        sSQL = string.Format(sSQL, models.BarCode, models.iSOsID, dNow);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        sSQL = @"
update _BarCodeLabel set IQCStatus = 'IQC-Sort'
where BarCode = '{0}' and iSOsID = {1}
";
                        sSQL = string.Format(sSQL, model.BarCode, model.iSOsID);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }
                    tran.Commit();

                    MessageBox.Show("Split is ok");
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox frm = new FrmMsgBox();
                frm.richTextBox1.Text = ee.Message;
                frm.ShowDialog();
            }
        }
Beispiel #2
0
        private void btnSplit_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                string sBarCode = btnTxtBarCode.Text.Trim();
                GetBarCodeStatus(sBarCode);

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string   sSOsID   = "";
                    string   sSQL     = "select getdate()";
                    DateTime dNow     = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd"));

                    sSQL = @"
select * 
from _BarCodeLabel 
where 1=1 
    and iSOsID = 'aaaaaaaa'
order by BarCode desc
";
                    sSQL = sSQL.Replace("1=1", "1=1 and BarCode = '" + sBarCode + "'");
                    sSQL = sSQL.Replace("aaaaaaaa", liSOsID.Text.Trim());

                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Please scan barcode");
                    }
                    sSOsID = dt.Rows[0]["iSOsID"].ToString().Trim();

                    sSQL = @"
update [_BarCodeLabel] set LOTQTY = 0,[Status] = '调整' where BarCode = '{0}' and iSOsID = '{1}' 
";
                    sSQL = string.Format(sSQL, sBarCode, sSOsID);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    Model.BarStatus models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                    models.BarCode     = sBarCode;
                    models.Type        = "调整";
                    models.QTY         = 0;
                    models.UpdateTime  = dNow;
                    models.CreateDate  = dNowDate;
                    models.CreateUid   = sUserID;
                    models.iSOsID      = BaseFunction.ReturnLong(sSOsID);
                    models.RoutingFrom = dt.Rows[0]["Process"].ToString().Trim();
                    models.RoutingTo   = dt.Rows[0]["Process"].ToString().Trim();
                    DAL.BarStatus dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus();
                    sSQL = dals.Add(models);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                    //回写上一道工序的结束时间
                    sSQL = @"
declare @iID int 
select @iID = max(iID)
from _BarStatus
where [BarCode] = '{0}' and iSOsID = '{1}'
    and iID < (
        select max(iID) as maxID
        from _BarStatus
        where [BarCode] = '{0}' and iSOsID = '{1}'
    )

update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}'
";
                    sSQL = string.Format(sSQL, models.BarCode, models.iSOsID, dNow);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        string  sBarCodeNew = gridView1.GetRowCellValue(i, gridColLOTNO).ToString().Trim();
                        decimal dQty        = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColPrintQTY));

                        if (sBarCodeNew == "")
                        {
                            continue;
                        }

                        sSQL = @"
select * from [dbo].[_BarCodeLabel] where BarCode = '{0}' and iSOsID = '{1}'
";
                        sSQL = string.Format(sSQL, sBarCodeNew, sSOsID);
                        DataTable dtExist = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dtExist != null && dtExist.Rows.Count > 0)
                        {
                            throw new Exception("Barcode " + sBarCodeNew + " is exists");
                        }

                        DAL._BarCodeLabel   dal   = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._BarCodeLabel();
                        Model._BarCodeLabel model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._BarCodeLabel();
                        model = dal.DataRowToModel(dt.Rows[0]);

                        model.oldBarCode = sBarCode;
                        model.BarCode    = sBarCodeNew;
                        model.LOTQTY     = dQty;
                        model.Status     = "调整";

                        if (sBarCode == sBarCodeNew)
                        {
                            sSQL = dal.Update(model, model.BarCode, model.iSOsID);
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        else
                        {
                            sSQL = dal.Add(model);
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }

                        models             = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                        models.BarCode     = model.BarCode;
                        models.Type        = "调整";
                        models.QTY         = dQty;
                        models.UpdateTime  = dNow;
                        models.CreateDate  = dNowDate;
                        models.CreateUid   = sUserID;
                        models.iSOsID      = BaseFunction.ReturnLong(sSOsID);
                        models.RoutingFrom = model.Process;
                        models.RoutingTo   = model.Process;
                        dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus();
                        sSQL = dals.Add(models);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                        //回写上一道工序的结束时间
                        sSQL = @"
declare @iID int 
select @iID = max(iID)
from _BarStatus
where [BarCode] = '{0}' and iSOsID = '{1}'
    and iID < (
        select max(iID) as maxID
        from _BarStatus
        where [BarCode] = '{0}' and iSOsID = '{1}'
    )

update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}'
";
                        sSQL = string.Format(sSQL, models.BarCode, models.iSOsID, dNow);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

//                        sSQL = @"
//update _BarCodeLabel set IQCStatus = 'IQC-Sort'
//where BarCode = '{0}' and iSOsID = {1}
//";
//                        sSQL = string.Format(sSQL, model.BarCode, model.iSOsID);
//                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }
                    tran.Commit();

                    MessageBox.Show("OK");
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }