コード例 #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();
            }
        }
コード例 #2
0
        private void btnSplit_Click(object sender, EventArgs e)
        {
            btnTxtBarCode.Focus();
            txtSplitQty.Focus();
            string sErr   = "";
            int    iCount = 0;

            try
            {
                GetBarCodeStatus(btnTxtBarCode.Text.Trim());

                if (BaseFunction.ReturnDecimal(txtSplitQty.Text) <= 0 || BaseFunction.ReturnDecimal(txtSplitQty.Text) > BaseFunction.ReturnDecimal(txtLotQTY.Text))
                {
                    throw new Exception("Split Qty is err");
                }

                string sBarCodeNew = "";

                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 = '" + btnTxtBarCode.Text.Trim() + "'");
                    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");
                    }

                    string sStatus = BaseFunction.ReturnStatus(dt.Rows[0]["status"].ToString().Trim());
                    if (sStatus.ToLower() == "pending")
                    {
                        throw new Exception("Lot no is pending err\n");
                    }


                    sProcess1 = dt.Rows[0]["Process"].ToString().Trim();

                    sSQL = @"
select *
FROM _BarStatus
where  1=1
order by iID desc
";
                    sSQL = sSQL.Replace("1=1", "1=1 and BarCode like '" + btnTxtBarCode.Text.Trim() + "%'");
                    sSQL = sSQL.Replace("1=1", "1=1 and  iSOsID = '" + txtiSOsID.Text.Trim() + "'");
                    DataTable dtBarStatus = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    decimal dLotQtyOld = BaseFunction.ReturnDecimal(dt.Rows[0]["LotQTY"], 2);

                    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]);

                    if (btnTxtBarCode2.Text.Trim() == "")
                    {
                        string[] sBarCodeList = btnTxtBarCode.Text.Split('-');

                        sSQL = @"
select BarCode as BarCodeNew 
from _BarCodeLabel 
where 1=1 
order by iID desc
";
                        sSQL = sSQL.Replace("1=1", "1=1 and BarCode like '" + sBarCodeList[0].Trim() + "%'");
                        sSQL = sSQL.Replace("1=1", "1=1 and  iSOsID = '" + txtiSOsID.Text.Trim() + "'");

                        DataTable dtBarCodeNew = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        sBarCodeList = dtBarCodeNew.Rows[0]["BarCodeNew"].ToString().Trim().Split('-');
                        sBarCodeNew  = sBarCodeList[0].Trim();
                        if (sBarCodeList.Length == 1)
                        {
                            sBarCodeNew = sBarCodeNew + "-0001";
                        }
                        else
                        {
                            int    iCou = BaseFunction.ReturnInt(sBarCodeList[1]) + 1;
                            string sCou = iCou.ToString();
                            while (sCou.Length < 4)
                            {
                                sCou = "0" + sCou;
                            }
                            sBarCodeNew = sBarCodeList[0] + "-" + sCou;
                        }

                        model.oldBarCode = btnTxtBarCode.Text.Trim();
                        model.BarCode    = sBarCodeNew;
                        model.LOTQTY     = BaseFunction.ReturnDecimal(txtSplitQty.Text.Trim());


                        sSQL    = dal.Add(model);
                        iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        Model.BarStatus models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                        models.BarCode     = model.oldBarCode;
                        models.Type        = "调整";
                        models.QTY         = dLotQtyOld - BaseFunction.ReturnDecimal(txtSplitQty.Text.Trim());
                        models.UpdateTime  = dNow;
                        models.CreateDate  = dNowDate;
                        models.CreateUid   = sUserID;
                        models.iSOsID      = BaseFunction.ReturnLong(txtiSOsID.Text);
                        models.RoutingFrom = dtBarStatus.Rows[0]["RoutingFrom"].ToString().Trim();
                        models.RoutingTo   = dtBarStatus.Rows[0]["RoutingTo"].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);


                        models             = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                        models.BarCode     = model.BarCode;
                        models.Type        = "调整";
                        models.QTY         = model.LOTQTY;
                        models.UpdateTime  = dNow;
                        models.CreateDate  = dNowDate;
                        models.CreateUid   = sUserID;
                        models.iSOsID      = BaseFunction.ReturnLong(txtiSOsID.Text);
                        models.RoutingFrom = dtBarStatus.Rows[0]["RoutingFrom"].ToString().Trim();
                        models.RoutingTo   = dtBarStatus.Rows[0]["RoutingTo"].ToString().Trim();
                        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 LotQTY = aaaaaa
where BarCode = 'bbbbbb'
";
                        sSQL    = sSQL.Replace("aaaaaa", (dLotQtyOld - BaseFunction.ReturnDecimal(txtSplitQty.Text.Trim())).ToString());
                        sSQL    = sSQL.Replace("bbbbbb", model.oldBarCode);
                        iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }
                    else
                    {
                        sSQL = "select * from _BarCodeLabel where BarCode = '" + btnTxtBarCode2.Text.Trim() + "' ";
                        DataTable dtBarCodeTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dtBarCodeTemp == null || dtBarCodeTemp.Rows.Count == 0)
                        {
                            btnTxtBarCode2.Text = "";
                            btnTxtBarCode2.Focus();
                            throw new Exception("BarCode is not exists");
                        }

                        sProcess2 = dtBarCodeTemp.Rows[0]["Process"].ToString().Trim();

                        if (sProcess1 != sProcess2)
                        {
                            throw new Exception("Both Lot are not in the same process");
                        }

                        sSQL    = "update _BarCodeLabel set LotQTY = LotQTY - " + BaseFunction.ReturnDecimal(txtSplitQty.Text, 2) + " where BarCode = '" + btnTxtBarCode.Text.Trim() + "' and iSOsID = " + txtiSOsID.Text.Trim();
                        iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        sSQL    = "update _BarCodeLabel set LotQTY = LotQTY + " + BaseFunction.ReturnDecimal(txtSplitQty.Text, 2) + " where BarCode = '" + btnTxtBarCode2.Text.Trim() + "' and iSOsID = " + txtiSOsID.Text.Trim();
                        iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);



                        Model.BarStatus models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                        models.BarCode     = btnTxtBarCode.Text.Trim();
                        models.Type        = "调整";
                        models.QTY         = dLotQtyOld - BaseFunction.ReturnDecimal(txtSplitQty.Text.Trim());
                        models.UpdateTime  = dNow;
                        models.CreateDate  = dNowDate;
                        models.CreateUid   = sUserID;
                        models.iSOsID      = BaseFunction.ReturnLong(txtiSOsID.Text);
                        models.RoutingFrom = dtBarStatus.Rows[0]["RoutingFrom"].ToString().Trim();
                        models.RoutingTo   = dtBarStatus.Rows[0]["RoutingTo"].ToString().Trim();

                        DAL.BarStatus dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus();
                        sSQL = dals.Add(models);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        models         = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                        models.BarCode = btnTxtBarCode2.Text.Trim();
                        models.Type    = "调整";

                        decimal dQty = BaseFunction.ReturnDecimal(txtLotQTY2.Text) + BaseFunction.ReturnDecimal(txtSplitQty.Text);

                        if ((BaseFunction.ReturnDecimal(txtLotSize.Text) == 1 && dQty > BaseFunction.ReturnDecimal(txtOrderQTY.Text)) ||
                            (BaseFunction.ReturnDecimal(txtLotSize.Text) > 1 && dQty > BaseFunction.ReturnDecimal(txtLotSize.Text)))
                        {
                            throw new Exception("Qty is err");
                        }
                        models.QTY         = dQty;
                        models.UpdateTime  = dNow;
                        models.CreateDate  = dNowDate;
                        models.CreateUid   = sUserID;
                        models.iSOsID      = BaseFunction.ReturnLong(txtiSOsID.Text);
                        models.RoutingFrom = dtBarStatus.Rows[0]["RoutingFrom"].ToString().Trim();
                        models.RoutingTo   = dtBarStatus.Rows[0]["RoutingTo"].ToString().Trim();

                        dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus();
                        sSQL = dals.Add(models);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    if (sErr.Length > 0)
                    {
                        throw new Exception(sErr);
                    }

                    if (iCount > 0)
                    {
                        tran.Commit();

                        btnTxtBarCode_ButtonClick(null, null);

                        SetTxtNull();
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
コード例 #3
0
ファイル: PrintBarLabel.cs プロジェクト: chrgu000/DEMO
        private void btnPrint_Click(object sender, EventArgs e)
        {
            string sErr   = "";
            int    iCount = 0;

            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }


                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"));

                    DataTable dtGrid = ((DataTable)gridControl1.DataSource).Copy();
                    dtGrid.TableName = "dtGrid";

                    DataColumn dc = new DataColumn();
                    dc.ColumnName = "BarCreateDate";
                    dtGrid.Columns.Add(dc);


                    for (int i = dtGrid.Rows.Count - 1; i >= 0; i--)
                    {
                        if (!BaseFunction.ReturnBool(dtGrid.Rows[i]["choose"]))
                        {
                            dtGrid.Rows.RemoveAt(i);
                        }
                    }

                    sSQL = @"
select  MAX(SUBSTRING(BarCode,9,4))
from _BarCodeLabel 
where SUBSTRING(BarCode,3,6) = 'aaaaaa'
";
                    sSQL = sSQL.Replace("aaaaaa", dNowDate.ToString("yyMMdd"));
                    DataTable dt       = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    long      lBarList = BaseFunction.ReturnLong(dt.Rows[0][0]);

                    for (int i = 0; i < dtGrid.Rows.Count; i++)
                    {
                        long iLotSize = BaseFunction.ReturnLong(dtGrid.Rows[0]["LotSize"]);
                        if (iLotSize <= 0)
                        {
                            sErr = sErr + "Row " + (i + 1).ToString() + " lot qty err\n";
                            continue;
                        }

                        sSQL = "select count(1) from [_BarCodeLabel] where 1=1 and isnull(printCount,0) >0 and [iSOsID] = " + dtGrid.Rows[i]["iSOsID"].ToString().Trim() + " and [RDsID] = '" + dtGrid.Rows[i]["RdsAutoid"].ToString().Trim() + "'";
                        if (dtGrid.Rows[i]["cSTCode"].ToString().ToLower().Trim() == "os")
                        {
                            sSQL = sSQL.Replace("1=1", "1=1 and Batch = '" + dtGrid.Rows[i]["cBatch"].ToString().Trim() + "'");
                        }

                        dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (BaseFunction.ReturnInt(dt.Rows[0][0], -1) != 0)
                        {
                            sErr = sErr + dtGrid.Rows[i]["ORDNO"] + " " + dtGrid.Rows[i]["iRowNo"] + " is printed\n";
                            continue;
                        }

                        long dOrderQTY = BaseFunction.ReturnLong(dtGrid.Rows[i]["ORDQTY"]);
                        long dLOTQTY   = BaseFunction.ReturnLong(dtGrid.Rows[i]["LOTQTY"]);
                        if (dtGrid.Rows[i]["LOTNO"].ToString().Trim() != "")
                        {
                            dLOTQTY = 1;
                        }

                        if (dLOTQTY == 1 || dtGrid.Rows[i]["LOTNO"].ToString().Trim() != "")
                        {
                            dLOTQTY = dOrderQTY;
                        }

                        ////OS 业务使用入库单作为 dOrderQTY用于判断打印循环
                        //if (dtGrid.Rows[i]["cSTCode"].ToString().ToLower().Trim() == "os")
                        //{
                        //    dOrderQTY = dLOTQTY;
                        //}
                        while (dOrderQTY > 0)
                        {
                            lBarList += 1;

                            Model._BarCodeLabel model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._BarCodeLabel();

                            dtGrid.Rows[i]["BarCreateDate"] = "Printed on " + dNow.ToString("yyyy/MM/dd HH:mm:ss");

                            if (dtGrid.Rows[i]["LOTNO"].ToString().Trim() == "")
                            {
                                string sBarList = lBarList.ToString();
                                while (sBarList.Length < 4)
                                {
                                    sBarList = "0" + sBarList;
                                }
                                model.BarCode = dtGrid.Rows[i]["cSTCode"].ToString().Trim() + dNowDate.ToString("yyMMdd") + sBarList;
                            }
                            else
                            {
                                model.BarCode = dtGrid.Rows[i]["LOTNO"].ToString().Trim();
                            }
                            dtGrid.Rows[i]["barcode"] = model.BarCode;
                            model.SaleOrderNo         = dtGrid.Rows[i]["ORDNO"].ToString().Trim();

                            model.SaleOrderRowNo = BaseFunction.ReturnLong(dtGrid.Rows[i]["iRowNo"]);
                            model.iSOsID         = BaseFunction.ReturnLong(dtGrid.Rows[i]["iSOsID"]);
                            model.cInvCode       = dtGrid.Rows[i]["ITEMNO"].ToString().Trim();
                            model.cInvName       = dtGrid.Rows[i]["ITEMDESC"].ToString().Trim();
                            model.DEPT           = dtGrid.Rows[i]["DEPT"].ToString().Trim();
                            model.CUST           = dtGrid.Rows[i]["CUST"].ToString().Trim();
                            model.ORDERNO        = dtGrid.Rows[i]["ORDNO"].ToString().Trim();
                            model.CUSTDO         = dtGrid.Rows[i]["CUSTDO"].ToString().Trim();
                            model.LOTNO          = dtGrid.Rows[i]["LOTNO"].ToString().Trim();
                            model.ORDERQTY       = BaseFunction.ReturnLong(dtGrid.Rows[i]["ORDQTY"]);
                            model.CUSTLOT        = dtGrid.Rows[i]["CUSTLOT"].ToString().Trim();
                            model.LotSize        = BaseFunction.ReturnDecimal(dtGrid.Rows[i]["LotSize"], 2);
                            model.Batch          = dtGrid.Rows[i]["cBatch"].ToString().Trim();
                            model.RDsID          = BaseFunction.ReturnLong(dtGrid.Rows[i]["RdsAutoid"]);
                            model.RDType         = dtGrid.Rows[i]["RDsType"].ToString().Trim();
                            model.Process        = dtGrid.Rows[i]["cWhCode"].ToString().Trim();

                            if (dOrderQTY >= dLOTQTY)
                            {
                                model.LOTQTY = dLOTQTY;
                                dOrderQTY    = dOrderQTY - dLOTQTY;
                            }
                            else
                            {
                                model.LOTQTY = dOrderQTY;
                                dOrderQTY    = 0;
                            }

                            model.LOTQTY2    = model.LOTQTY;
                            model.RECDate    = BaseFunction.ReturnDate(dtGrid.Rows[i]["RECDTE"]);
                            model.DueDate    = BaseFunction.ReturnDate(dtGrid.Rows[i]["DUEDTE"]);
                            model.Creater    = sUserID;
                            model.CreateDate = dNow;
                            model.PrintTime  = dNow;
                            model.PrintCount = 1;
                            model.Status     = "新增";

                            DAL._BarCodeLabel dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._BarCodeLabel();
                            sSQL    = dal.Add(model);
                            iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                            Model.BarStatus models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                            models.BarCode     = model.BarCode;
                            models.Type        = "新增";
                            models.UpdateTime  = dNow;
                            models.QTY         = model.LOTQTY;
                            models.CreateDate  = dNowDate;
                            models.CreateUid   = sUserID;
                            models.iSOsID      = model.iSOsID;
                            models.RoutingFrom = "新增";
                            models.RoutingTo   = model.Process;

                            DAL.BarStatus dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus();
                            sSQL = dals.Add(models);
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        //}
                        //else
                        //{
                        //    sSQL = "update _BarCodeLabel set Status = '新增', printTime = getdate(), PrintCount = 1, createdate = '" + dNow + "' where BarCode = '" + dtGrid.Rows[i]["LOTNO"].ToString().Trim() + "' and iSOsID = " + dtGrid.Rows[i]["iSOsID"].ToString().Trim();
                        //    iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        //}
                    }

                    if (sErr.Length > 0)
                    {
                        throw new Exception(sErr);
                    }

                    if (iCount == 0)
                    {
                        throw new Exception("Please choose data\n" + sErr);
                    }

                    Rep = new RepBaseGrid();
                    if (File.Exists(sPrintLayOutMod))
                    {
                        Rep.LoadLayout(sPrintLayOutMod);
                    }
                    else
                    {
                        MessageBox.Show("加载报表模板失败,请与管理员联系");
                        return;
                    }

                    sSQL = @"
select 
    a.barCode, a.SaleOrderNo, a.SaleOrderRowNo, a.iSOsID, a.cInvCode, a.cInvName, a.cInvStd, Inv.cInvDepCode as DEPT 
    ,b.cDepName as DEPTName, CUST,ORDERNO AS ORDNO, CUSTDO, LOTNO, ORDERQTY, LOTQTY, RECDate, DueDate, Creater, CreateDate 
    ,PrintTime, PrintCount, a.cInvCode AS ITEMNO, a.cInvName AS ITEMDESC 
    ,RECDate,DueDate
    ,cast(null as varchar(50)) as RECDate2,cast(null as varchar(50)) as DueDate2
    ,ORDERQTY as ORDQTY
    ,CUSTLOT
    ,'Printed on ' as PrintInfo
    ,c.cMemo
    ,Inv.cInvDefine6
    ,Inv.cComUnitCode as cUnitID
from _BarCodeLabel a
    inner join Inventory Inv on a.cInvCode = Inv.cInvCode
    left join Department b on Inv.cInvDepCode = b.cDepCode
    left join SO_SODetails c on c.iSOsID = a.iSOsID
where creater = '{0}' and createdate = '{1}'
order by a.barCode
";

                    sSQL = string.Format(sSQL, sUserID, dNow);
                    DataTable dtBarCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    for (int i = 0; i < dtBarCode.Rows.Count; i++)
                    {
                        dtBarCode.Rows[i]["PrintInfo"] = "Printed on " + BaseFunction.ReturnDate(dtBarCode.Rows[i]["PrintTime"]).ToString("yyyy/MM/dd HH:mm:ss");
                        dtBarCode.Rows[i]["RECDate2"]  = BaseFunction.ReturnDate(dtBarCode.Rows[i]["RECDate"]).ToString("yyyy-MM-dd");
                        dtBarCode.Rows[i]["DueDate2"]  = BaseFunction.ReturnDate(dtBarCode.Rows[i]["DueDate"]).ToString("yyyy-MM-dd");
                    }

                    Rep.dsPrint.Tables.Clear();
                    Rep.dsPrint.Tables.Add(dtBarCode.Copy());
                    Rep.dsPrint.Tables[0].TableName = "dtGrid";

                    if (radioPreview.Checked)
                    {
                        Rep.ShowPreview();
                    }
                    if (radioPrint.Checked)
                    {
                        if (lookUpEditPrinter.Text.Trim() == "")
                        {
                            lookUpEditPrinter.Focus();
                            throw new Exception("Please choose printer");
                        }
                        Rep.PrinterName = lookUpEditPrinter.Text.Trim();
                        Rep.Print();
                    }
                    if (iCount > 0)
                    {
                        tran.Commit();
                        GetGrid();
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
コード例 #4
0
ファイル: BarSplitList.cs プロジェクト: chrgu000/DEMO
        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);
            }
        }