Beispiel #1
0
        private void btnAudit_Click(object sender, EventArgs e)
        {
            try
            {
                if (!clsUserRight.chkRight(sUserID, 8040))
                {
                    throw new Exception("没有权限");
                }

                if (txtCode.Text.Trim() == "")
                {
                    throw new Exception("请选择单据审核");
                }

                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string    sSQL   = "select * from  _Scrap where cCode = N'" + txtCode.Text.Trim() + "'";
                    DataTable dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtTemp == null || dtTemp.Rows.Count == 0)
                    {
                        throw new Exception("单据未保存");
                    }
                    if (dtTemp != null && dtTemp.Rows.Count > 0)
                    {
                        if (dtTemp.Rows[0]["AuditUserName"].ToString().Trim() != "")
                        {
                            throw new Exception("单据已经审核");
                        }
                    }

                    sSQL = "update _Scrap set AuditUserName = N'111111',AuditDate = getdate() where cCode = N'222222'";
                    sSQL = sSQL.Replace("111111", sUserName);
                    sSQL = sSQL.Replace("222222", txtCode.Text.Trim());
                    int iCou = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    if (iCou > 0)
                    {
                        tran.Commit();
                        MessageBox.Show("审核成功");

                        GetGrid(txtCode.Text.Trim());
                    }
                    else
                    {
                        throw new Exception("no data");
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #2
0
        private void GetGrid()
        {
            string sSQL = @"
select a.cCode,b.cSoCode 
from rdrecord08 a inner join rdrecords08 b on a.id = b.id
where b.cSoCode = 'aaaaaa'
";

            sSQL = sSQL.Replace("aaaaaa", s单据号);
            DataTable dt = DbHelperSQL.ExecuteDataset(sConnString, CommandType.Text, sSQL).Tables[0];

            if (dt != null && dt.Rows.Count > 0)
            {
                MessageBox.Show("exist \n" + dt.Rows[0]["cCode"].ToString().Trim());
                this.Close();
                return;
            }

            sSQL     = @"
select * 
from SO_SOMain a inner join SO_SODetails b on a.ID = b.ID
    left join _SystemSet c on a.cSTCode = c.cSTCode
    left join Inventory d on b.cInvCode = d.cInvCode
where a.cSOCode = 'aaaaaa'
order by b.autoid
";
            sSQL     = sSQL.Replace("aaaaaa", s单据号);
            dtSOMain = DbHelperSQL.ExecuteDataset(sConnString, CommandType.Text, sSQL).Tables[0];

            if (dtSOMain == null || dtSOMain.Rows.Count == 0)
            {
                throw new Exception("Please check sale order");
            }
            string sAudit = dtSOMain.Rows[0]["cVerifier"].ToString().Trim();
            string sClose = dtSOMain.Rows[0]["cCloser"].ToString().Trim();

            if (sClose != "")
            {
                DialogResult d = MessageBox.Show("Sale order is closed ,is continue?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                if (d != DialogResult.Yes)
                {
                    this.Close();
                }
            }
            if (sAudit == "")
            {
                DialogResult d = MessageBox.Show("Sale order is not approve ,is continue?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                if (d != DialogResult.Yes)
                {
                    this.Close();
                }
            }

            lookUpEditcWhCode.EditValue  = dtSOMain.Rows[0]["cWhCode"].ToString().Trim();
            lookUpEditRd_Style.EditValue = dtSOMain.Rows[0]["cRdCode"].ToString().Trim();

            gridControl1.DataSource            = dtSOMain;
            gridView1.OptionsBehavior.Editable = false;
            gridView1.BestFitColumns();
        }
Beispiel #3
0
        public string sGetBarStatus(SqlTransaction tran, string sBarCode, long iSOsID)
        {
            string sBarStatus = "";
            string sSQL       = @"
select top 1 case when isnull(a.CloseUid,'') <> '' then '关闭' when isnull(c.iSOsID,0) = 0 then '单据删除'
	else a.[Status] end as BarStatus
from [dbo].[_BarCodeLabel] a left join [dbo].[_BarStatus] b on a.BarCode = b.BarCode
	left join SO_SODetails c on a.iSOsID = c.iSOsID
where a.BarCode = 'aaaaaa' and a.iSOsID = bbbbbb
order by b.iID desc
";

            sSQL = sSQL.Replace("aaaaaa", sBarCode);
            sSQL = sSQL.Replace("bbbbbb", iSOsID.ToString());
            DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

            if (dt == null || dt.Rows.Count == 0)
            {
                sBarStatus = "不存在";
            }
            else
            {
                sBarStatus = dt.Rows[0]["BarStatus"].ToString().Trim();
            }
            return(sBarStatus);
        }
Beispiel #4
0
        private void lookUpEdit检验工位_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                if (lookUpEdit检验工位.EditValue == null || lookUpEdit检验工位.Text.Trim() == "")
                {
                    return;
                }

                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string    sSQL = "select getdate()";
                    DataTable dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    dateEdit单据日期.DateTime = Convert.ToDateTime(dt.Rows[0][0]);


                    GetGrid(tran, lookUpEdit检验工位.Text.Trim());


                    tran.Commit();
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                }
            }
            catch { }
        }
Beispiel #5
0
        private void btnDel_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView返利单.FocusedRowHandle -= 1;
                    gridView返利单.FocusedRowHandle += 1;
                }
                catch { }

                string        sErr = "";
                int           iCou = 0;
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    if (txt单据号.Text.Trim() == "")
                    {
                        throw new Exception("请选择单据");
                    }

                    string sSQL = @"
select * from [dbo].[_高开返利核销单] where cCode = '{0}' 
";
                    sSQL = string.Format(sSQL, txt单据号.Text.Trim());
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("单据不存在");
                    }

                    DAL._高开返利核销单 dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._高开返利核销单();
                    sSQL = dal.Delete(txt单据号.Text.Trim());
                    iCou = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    tran.Commit();

                    if (iCou > 0)
                    {
                        MessageBox.Show("删除成功");

                        this.Close();
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "删除失败";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Beispiel #6
0
        private void CreateLog(string sConn, string cSoCode, string DisCode, string RdCode, string Status, string Remark)
        {
            try
            {
                SqlConnection conn = new SqlConnection(sConn);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                string         sSQL = "";

                try
                {
                    Model._CreateDisInfo mod = new DllForService.Model._CreateDisInfo();
                    mod.cSOCode    = cSoCode;
                    mod.DisCode    = DisCode;
                    mod.RdCode     = RdCode;
                    mod.Status     = Status;
                    mod.CreateDate = DateTime.Now;
                    mod.Remark     = Remark;
                    DAL._CreateDisInfo dal = new DllForService.DAL._CreateDisInfo();

                    sSQL = dal.Exists(mod.cSOCode);
                    bool b = BaseFunction.ReturnBool(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    if (b)
                    {
                        sSQL = dal.Update(mod);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }
                    else
                    {
                        sSQL = dal.Add(mod);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    Model._CreateDisInfo_Log mod_log = new DllForService.Model._CreateDisInfo_Log();
                    mod_log.cSOCode    = cSoCode;
                    mod_log.DisCode    = DisCode;
                    mod_log.RdCode     = RdCode;
                    mod_log.Status     = Status;
                    mod_log.CreateDate = DateTime.Now;
                    mod_log.Remark     = Remark;
                    DAL._CreateDisInfo_Log dal_log = new DllForService.DAL._CreateDisInfo_Log();
                    sSQL = dal_log.Add(mod_log);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    tran.Commit();
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                }
            }
            catch (Exception ee)
            {
            }
        }
Beispiel #7
0
        private void Frm_Load(object sender, EventArgs e)
        {
            try
            {
                string sSQL = @"
SELECT * FROM [dbo].[_SaleBillVouchExportToCSV] 
WHERE cSBVCode = 'aaaaaa' 
ORDER BY autoid 
";
                sSQL = sSQL.Replace("aaaaaa", s单据号);
                DataTable dt = DbHelperSQL.ExecuteDataset(sConnString, CommandType.Text, sSQL).Tables[0];

                sSTCode = dt.Rows[0]["cSTCode"].ToString().Trim();


                if (sSTCode.ToLower() != "ic")
                {
                    gridControl2.Visible = false;
                    gridControl1.Visible = true;

                    if (sSTCode.ToLower() == "wp")
                    {
                        sSQL = @"
SELECT * FROM [dbo].[_SaleBillVouchExportToCSV3] 
WHERE cSBVCode = 'aaaaaa' 
ORDER BY autoid 
";
                        sSQL = sSQL.Replace("aaaaaa", s单据号);
                        dt   = DbHelperSQL.ExecuteDataset(sConnString, CommandType.Text, sSQL).Tables[0];
                    }
                    gridControl1.DataSource = dt;
                }
                else
                {
                    sSQL = @"
SELECT * FROM [dbo].[_SaleBillVouchExportToCSV2] 
WHERE cSBVCode = 'aaaaaa' 

";
                    sSQL = sSQL.Replace("aaaaaa", s单据号);
                    dt   = DbHelperSQL.ExecuteDataset(sConnString, CommandType.Text, sSQL).Tables[0];
                    gridControl1.Visible    = false;
                    gridControl2.Visible    = true;
                    gridControl2.DataSource = dt;
                    gridView2.BestFitColumns();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #8
0
        public BtnAR_UnAudit(LoginInfo LoginInfo)
        {
            _LoginInfo = LoginInfo;

            sLangType = _LoginInfo.LanguageRegion.ToLower();


            try
            {
                string        sErr = "";
                SqlConnection conn = new SqlConnection(_LoginInfo.UFDataSqlConStr);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();

                try
                {
                    string sSQL = @"
select * from   _UAP_Language where cVoucher = 'UAP_ClientPlugin_AR.BtnAR_ReadData'
";
                    dtLanguage = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtLanguage == null || dtLanguage.Rows.Count == 0)
                    {
                        if (sLangType == "" || sLangType == "zh-cn")
                        {
                            sErr = "请设置语言";
                        }
                        if (sLangType == "en-us")
                        {
                            sErr = "Please set language";
                        }

                        //if (sErr != "")
                        //{
                        //    throw new Exception(sErr);
                        //}
                    }
                    tran.Commit();
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                }
                finally
                {
                    conn.Close();
                }
            }
            catch (Exception ee)
            { }
        }
Beispiel #9
0
        private void GetGrid(SqlTransaction tran, string s检验工位)
        {
            string sSQL = @"
select top 20 * 
from  工作台测量 
where 工作台 = '{0}' and dtmCreate >= dateadd(hour,-2,getdate()) and isnull(删除人,'') = ''
order by iID desc
";

            sSQL = string.Format(sSQL, s检验工位);
            DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

            gridControl1.DataSource    = dt;
            gridView1.FocusedRowHandle = 0;
        }
Beispiel #10
0
        private void SetLookup()
        {
            string    sSQL = @"
SELECT cRdCode,cRdName FROM Rd_Style WHERE bRdEnd = 1 AND bRdFlag = 1 ORDER BY cRdCode
";
            DataTable dt   = DbHelperSQL.ExecuteDataset(sConnString, CommandType.Text, sSQL).Tables[0];

            lookUpEditRd_Style.Properties.DataSource = dt;

            sSQL = @"
select cWhCode,cWhName from Warehouse order by cWhCode
";
            dt   = DbHelperSQL.ExecuteDataset(sConnString, CommandType.Text, sSQL).Tables[0];
            lookUpEditcWhCode.Properties.DataSource = dt;
        }
Beispiel #11
0
        private void btnClose_Click(object sender, EventArgs e)
        {
            txtBarCode.Focus();

            int iCount = 0;

            try
            {
                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string    sSQL = @"select * from _BarCodeLabel  where [BarCode] = '" + txtBarCode.Text.Trim() + "'";
                    DataTable dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Barcode is not exists");
                    }
                    if (dt.Rows[0]["CloseUid"].ToString().Trim() != "")
                    {
                        throw new Exception("Barcode is closed");
                    }

                    sSQL    = "update [_BarCodeLabel] set [CloseUid] = '" + sUserID + "',[CloseDate] = GETDATE() where [BarCode] = '" + txtBarCode.Text.Trim() + "'";
                    iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

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

                        MessageBox.Show("OK");

                        SetTxtNull();
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #12
0
        private void GetGrid()
        {
            try
            {
                Rep = new RepBaseGrid();
                if (File.Exists(sPrintLayOutMod))
                {
                    Rep.LoadLayout(sPrintLayOutMod);
                }
                else
                {
                    MessageBox.Show("加载报表模板失败,请与管理员联系");
                    return;
                }
                Rep.dsPrint.Tables.Clear();

                SqlConnection conn = new SqlConnection(sConnString);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();

                string sSQL = @"
select * from v_scdd  
WHERE 1=1   AND  1=1   And mocode = N'aaaaaa'
";
                sSQL = sSQL.Replace("aaaaaa", s单据号);

                DataTable dtHead = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                dtHead.TableName = "dtHead";
                Rep.dsPrint.Tables.Add(dtHead.Copy());

                printControl1.PrintingSystem = Rep.PrintingSystem;
                Rep.CreateDocument();
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
        private void GetGrid(SqlTransaction tran)
        {
            string sSQL = @"
select cast(0 as bit) as bchoose, * ,cCode as FL_Code
from _TH_GET_FLD_HX_SZ 
where 1=1 and iID not in (select [FLD_iID] from [dbo].[_高开返利核销单_SZ])
order by iID
";

            if (lookUpEditcCusCode.Text.Trim() != "")
            {
                sSQL = sSQL.Replace("1=1", "1=1 and DLS = '" + lookUpEditcCusCode.EditValue.ToString().Trim() + "'");
            }
            if (lookUpEdit区域.Text.Trim() != "")
            {
                sSQL = sSQL.Replace("1=1", "1=1 and 城市编码 = '" + lookUpEdit区域.EditValue.ToString().Trim() + "'");
            }


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

            gridControl返利单.DataSource = dtFLD;
            gridView返利单.BestFitColumns();
        }
Beispiel #14
0
        private void btnDel_Click(object sender, EventArgs e)
        {
            try
            {
                if (!clsUserRight.chkRight(sUserID, 8020))
                {
                    throw new Exception("没有权限");
                }

                if (txtCode.Text.Trim() == "")
                {
                    throw new Exception("请选择单据删除");
                }

                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string    sSQL   = "select * from  _Scrap where cCode = N'" + txtCode.Text.Trim() + "'";
                    DataTable dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtTemp == null || dtTemp.Rows.Count == 0)
                    {
                        throw new Exception("单据未保存");
                    }
                    if (dtTemp != null && dtTemp.Rows.Count > 0)
                    {
                        if (dtTemp.Rows[0]["AuditUserName"].ToString().Trim() != "")
                        {
                            throw new Exception("单据已经审核");
                        }
                    }

                    sSQL = "update _FrockClamp set iState = 1,Closed = null ,CloseDate = null  where SerialNo in (select SerialNo from _Scraps where cCode = N'111111')";
                    sSQL = sSQL.Replace("111111", txtCode.Text.Trim());
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    sSQL = "delete _Scraps where cCode = N'111111'";
                    sSQL = sSQL.Replace("111111", txtCode.Text.Trim());
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    sSQL = "delete _Scrap where cCode = N'111111'";
                    sSQL = sSQL.Replace("111111", txtCode.Text.Trim());
                    int iCou = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    if (iCou > 0)
                    {
                        tran.Commit();
                        MessageBox.Show("删除成功");

                        this.DialogResult = DialogResult.OK;
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #15
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (!clsUserRight.chkRight(sUserID, 8010))
                {
                    throw new Exception("没有权限");
                }

                if (gridView1.RowCount == 0)
                {
                    throw new Exception("请输入表体");
                }
                string sErr = "";
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                int iCou = 0;

                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string       sSerCode = txtCode.Text.Trim();
                    Model._Scrap model    = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._Scrap();
                    string       sState   = "";

                    string    sSQL   = "select * from  _Scrap where cCode = N'" + txtCode.Text.Trim() + "'";
                    DataTable dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtTemp != null && dtTemp.Rows.Count > 0)
                    {
                        if (dtTemp.Rows[0]["AuditUserName"].ToString().Trim() != "")
                        {
                            throw new Exception("单据已经审核,不能保存");
                        }
                    }

                    //新增
                    if (txtCode.Text.Trim() == "")
                    {
                        sState = "add";
                        model.CreateUserName = sUserName;
                        model.CreateDate     = DateTime.Today;
                        long iCode = 0;

                        sSQL = "select max(cCode) as cCode from [_Scrap] where cCode like '111111%'";
                        sSQL = sSQL.Replace("111111", dtmCode.DateTime.ToString("yyMMdd"));
                        DataTable dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dtCode == null && dtCode.Rows.Count == 0)
                        {
                            iCode = 1;
                        }
                        else
                        {
                            string s = dtCode.Rows[0]["cCode"].ToString().Trim();
                            if (s.Length > 6)
                            {
                                iCode = BaseFunction.ReturnLong(s.Substring(6));
                            }
                            else
                            {
                                iCode = BaseFunction.ReturnLong(s);
                            }
                            iCode += 1;
                        }
                        string sCode = iCode.ToString().Trim();
                        while (sCode.Length < 4)
                        {
                            sCode = "0" + sCode;
                        }
                        sCode = dtmCode.DateTime.ToString("yyMMdd") + sCode;

                        model.cCode = sCode;

                        model.dDate = dtmCode.DateTime;

                        if (lookUpEditPerson.EditValue != null)
                        {
                            model.Person = lookUpEditPerson.EditValue.ToString().Trim();
                        }
                        if (lookUpEditDep.EditValue != null)
                        {
                            model.DepCode = lookUpEditDep.EditValue.ToString().Trim();
                        }
                        model.Remark         = txtRemark.Text.Trim();
                        model.CreateUserName = sUserName;
                        model.CreateDate     = DateTime.Now;

                        DAL._Scrap dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._Scrap();

                        sSQL = dal.Add(model);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }
                    else
                    {
                        sState               = "edit";
                        model.cCode          = txtCode.Text.Trim();
                        model.dDate          = dtmCode.DateTime;
                        model.Person         = lookUpEditPerson.EditValue.ToString().Trim();
                        model.DepCode        = lookUpEditDep.EditValue.ToString().Trim();
                        model.Remark         = txtRemark.Text.Trim();
                        model.CreateUserName = txtCreateUserName.Text.Trim();
                        model.CreateDate     = dtmCreate.DateTime;

                        DAL._Scrap dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._Scrap();
                        sSQL = dal.Update(model);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    sSQL = @"update  _FrockClamp set iState = 1 where  SerialNo in (select SerialNo from _Scraps where cCode = N'" + txtCode.Text.Trim() + "') and isnull(Closed,'') = '' ";
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    sSQL = "delete _Scraps where cCode = N'" + model.cCode + "'";
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        if (gridView1.GetRowCellValue(i, gridColSerialNo).ToString().Trim() != "")
                        {
                            Model._Scraps models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._Scraps();
                            models.cCode    = model.cCode;
                            models.SerialNo = gridView1.GetRowCellValue(i, gridColSerialNo).ToString().Trim();
                            models.Remark   = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim();

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

                            sSQL   = "select iState from _FrockClamp where SerialNo = '111111'";
                            sSQL   = sSQL.Replace("111111", gridView1.GetRowCellValue(i, gridColSerialNo).ToString().Trim());
                            dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                            if (dtTemp != null && BaseFunction.ReturnInt(dtTemp.Rows[0]["iState"]) == 1)
                            {
                                sSQL = "update _FrockClamp set iState = 4,Closed = N'222222',CloseDate = getdate() where SerialNo = N'111111'";
                                sSQL = sSQL.Replace("111111", gridView1.GetRowCellValue(i, gridColSerialNo).ToString().Trim());
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }
                            else
                            {
                                sErr = sErr + "行" + (i + 1).ToString() + "工装不是可用状态\n";
                                continue;
                            }
                        }
                    }

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

                    if (iCou > 0)
                    {
                        tran.Commit();
                        MessageBox.Show("OK\n");

                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        throw new Exception("no data");
                    }
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                    tran.Rollback();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #16
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                string sErr = "";

                if (gridView1.RowCount == 0)
                {
                    throw new Exception("请加载数据");
                }

                DataTable  dtErr = new DataTable();
                DataColumn dc    = new DataColumn();
                dc.ColumnName = "iID";
                dtErr.Columns.Add(dc);
                dc            = new DataColumn();
                dc.ColumnName = "sErr";
                dtErr.Columns.Add(dc);

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        bool b = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColbChoose));
                        if (!b)
                        {
                            continue;
                        }

                        bool bUsed = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColbUsed));
                        if (bUsed)
                        {
                            continue;
                        }

                        string sDate = gridView1.GetRowCellValue(i, gridColBLDAT).ToString().Trim();


                        DateTime dtmDate = BaseFunction.ReturnDate(sDate.Substring(0, 4) + "-" + sDate.Substring(4, 2) + "-" + sDate.Substring(6, 2));
                        if (dtmDate < Convert.ToDateTime("2018-01-01"))
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "日期不正确\n";
                            continue;
                        }

                        int iYear  = dtmDate.Year;
                        int iMonth = dtmDate.Month;

                        string sSQL = "SELECT * FROM dbo.GL_mend WHERE iyear = aaaaaa AND iperiod = bbbbbb";
                        sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                        sSQL = sSQL.Replace("bbbbbb", iMonth.ToString());
                        DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dt == null || dt.Rows.Count == 0)
                        {
                            throw new Exception("获得模块状态失败");
                        }
                        if (BaseFunction.ReturnBool(dt.Rows[0]["bflag"]))
                        {
                            throw new Exception("总账已结账");
                        }

                        string scsign = "";
                        int    ino_id = 0;
                        int    iRow   = 0;



                        int inid   = 0;
                        int iCount = 0;

                        sSQL = @"select * from dsign where csign = '{0}'";
                        sSQL = string.Format(sSQL, "记");
                        DataTable dtdsign = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dtdsign == null || dtdsign.Rows.Count == 0)
                        {
                            sErr = sErr + "凭证类别不正确\n";
                        }

                        if (ino_id == 0)
                        {
                            sSQL = @"
select isnull(max(ino_id),0) as ino_id from GL_accvouch where csign = '{0}' and iyear = {1} and iperiod = {2}
";
                            sSQL = string.Format(sSQL, scsign, iYear, iMonth);
                            DataTable dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                            if (dtTemp == null || dtTemp.Rows.Count == 0)
                            {
                                ino_id = 0;
                            }
                            else
                            {
                                ino_id = BaseFunction.ReturnInt(dtTemp.Rows[0]["ino_id"]);
                            }
                        }

                        ino_id += 1;


                        #region 第一行

                        inid += 1;
                        Model.GL_accvouch model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
                        model.iperiod = iMonth;

                        model.csign    = scsign;
                        model.isignseq = BaseFunction.ReturnInt(dtdsign.Rows[0]["isignseq"]);


                        model.ino_id = ino_id;

                        iRow             = 1;
                        model.inid       = iRow;
                        model.dbill_date = dtmDate;
                        model.idoc       = -1;
                        model.cbill      = sUserName;
                        model.ibook      = 0;
                        model.cdigest    = gridView1.GetRowCellValue(i, gridColSGTXT).ToString().Trim();;

                        sSQL = @"
select b.* 
from [_科目对照] a
	inner join code b on a.会计科目 = b.ccode and b.iyear = {1}
where 对照科目 = '{0}'
";
                        sSQL = string.Format(sSQL, gridView1.GetRowCellValue(i, gridColNEWKO), iYear);
                        DataTable dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dtCode != null && dtCode.Rows.Count == 1)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "会计科目不正确,请设置对照档案\n";
                            continue;
                        }

                        if (!BaseFunction.ReturnBool(dtCode.Rows[0]["bend"]))
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "会计科目不是末级科目,请设置对照档案\n";
                            continue;
                        }

                        model.ccode = dtCode.Rows[0]["会计科目"].ToString().Trim();


                        int NEWBS = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColNEWBS).ToString().Trim());
                        //借方
                        if (NEWBS == 40)
                        {
                            model.md    = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColWRBTR));
                            model.md_f  = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColWRBTR));
                            model.nfrat = 1;
                            model.nd_s  = 0;
                            model.nc_s  = 0;
                        }
                        else
                        {
                            model.mc    = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColWRBTR));
                            model.mc_f  = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColWRBTR));
                            model.nfrat = 1;
                            model.nd_s  = 0;
                            model.nc_s  = 0;
                        }

                        bool bperson = BaseFunction.ReturnBool(dtCode.Rows[0]["bperson"]);
                        if (bperson)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "必须有人员\n";
                            continue;
                        }

                        bool bcus = BaseFunction.ReturnBool(dtCode.Rows[0]["bcus"]);
                        if (bcus)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "必须有客户\n";
                            continue;
                        }


                        bool bsup = BaseFunction.ReturnBool(dtCode.Rows[0]["bsup"]);
                        if (bsup)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "必须有供应商\n";
                            continue;
                        }


                        bool bdept = BaseFunction.ReturnBool(dtCode.Rows[0]["bdept"]);
                        if (bsup)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "必须有部门\n";
                            continue;
                        }


                        model.bdelete         = false;
                        model.doutbilldate    = model.dbill_date;
                        model.bvouchedit      = true;
                        model.bvouchAddordele = false;
                        model.bvouchmoneyhold = false;
                        model.bvalueedit      = true;
                        model.bcodeedit       = true;
                        model.bPCSedit        = true;
                        model.bDeptedit       = true;
                        model.bItemedit       = true;
                        model.bCusSupInput    = false;
                        model.bFlagOut        = false;
                        model.RowGuid         = Guid.NewGuid().ToString();
                        model.iyear           = iYear;
                        model.iYPeriod        = iMonth;
                        model.tvouchtime      = DateTime.Now;



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

                        gridView1.SetRowCellValue(i, gridColbUsed, true);
                        #endregion

                        string XBLNR = gridView1.GetRowCellValue(i, gridColXBLNR).ToString().Trim();

                        for (int j = i + 1; j < gridView1.RowCount; j++)
                        {
                            string XBLNR_2 = gridView1.GetRowCellValue(j, gridColXBLNR).ToString().Trim();

                            if (XBLNR != XBLNR_2)
                            {
                                continue;
                            }

                            model         = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
                            model.iperiod = iMonth;

                            model.csign    = scsign;
                            model.isignseq = BaseFunction.ReturnInt(dtdsign.Rows[0]["isignseq"]);


                            model.ino_id = ino_id;

                            iRow            += 1;
                            model.inid       = iRow;
                            model.dbill_date = dtmDate;
                            model.idoc       = -1;
                            model.cbill      = sUserName;
                            model.ibook      = 0;
                            model.cdigest    = gridView1.GetRowCellValue(j, gridColSGTXT).ToString().Trim();;

                            sSQL   = @"
select b.* 
from [_科目对照] a
	inner join code b on a.会计科目 = b.ccode and b.iyear = {1}
where 对照科目 = '{0}'
";
                            sSQL   = string.Format(sSQL, gridView1.GetRowCellValue(j, gridColNEWKO), iYear);
                            dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                            if (dtCode != null && dtCode.Rows.Count == 1)
                            {
                                sErr = sErr + "行" + (j + 1).ToString() + "会计科目不正确,请设置对照档案\n";
                                continue;
                            }

                            if (!BaseFunction.ReturnBool(dtCode.Rows[0]["bend"]))
                            {
                                sErr = sErr + "行" + (j + 1).ToString() + "会计科目不是末级科目,请设置对照档案\n";
                                continue;
                            }

                            model.ccode = dtCode.Rows[0]["会计科目"].ToString().Trim();


                            NEWBS = BaseFunction.ReturnInt(gridView1.GetRowCellValue(j, gridColNEWBS).ToString().Trim());
                            //借方
                            if (NEWBS == 40)
                            {
                                model.md    = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(j, gridColWRBTR));
                                model.md_f  = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(j, gridColWRBTR));
                                model.nfrat = 1;
                                model.nd_s  = 0;
                                model.nc_s  = 0;
                            }
                            else
                            {
                                model.mc    = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(j, gridColWRBTR));
                                model.mc_f  = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(j, gridColWRBTR));
                                model.nfrat = 1;
                                model.nd_s  = 0;
                                model.nc_s  = 0;
                            }

                            bperson = BaseFunction.ReturnBool(dtCode.Rows[0]["bperson"]);
                            if (bperson)
                            {
                                sErr = sErr + "行" + (j + 1).ToString() + "必须有人员\n";
                                continue;
                            }

                            bcus = BaseFunction.ReturnBool(dtCode.Rows[0]["bcus"]);
                            if (bcus)
                            {
                                sErr = sErr + "行" + (j + 1).ToString() + "必须有客户\n";
                                continue;
                            }


                            bsup = BaseFunction.ReturnBool(dtCode.Rows[0]["bsup"]);
                            if (bsup)
                            {
                                sErr = sErr + "行" + (j + 1).ToString() + "必须有供应商\n";
                                continue;
                            }


                            bdept = BaseFunction.ReturnBool(dtCode.Rows[0]["bdept"]);
                            if (bsup)
                            {
                                sErr = sErr + "行" + (j + 1).ToString() + "必须有部门\n";
                                continue;
                            }


                            model.bdelete         = false;
                            model.doutbilldate    = model.dbill_date;
                            model.bvouchedit      = true;
                            model.bvouchAddordele = false;
                            model.bvouchmoneyhold = false;
                            model.bvalueedit      = true;
                            model.bcodeedit       = true;
                            model.bPCSedit        = true;
                            model.bDeptedit       = true;
                            model.bItemedit       = true;
                            model.bCusSupInput    = false;
                            model.bFlagOut        = false;
                            model.RowGuid         = Guid.NewGuid().ToString();
                            model.iyear           = iYear;
                            model.iYPeriod        = iMonth;
                            model.tvouchtime      = DateTime.Now;



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

                            gridView1.SetRowCellValue(j, gridColbUsed, true);
                        }
                    }
                    if (sErr.Length != 0)
                    {
                        throw new Exception(sErr);
                    }

                    tran.Commit();
                    MessageBox.Show("保存成功");
                    btnSel_Click(null, null);
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "提示";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Beispiel #17
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string sErr   = "";
            int    iCount = 0;

            try
            {
                if (lookUpEditiYear.EditValue == null || lookUpEditiYear.EditValue.ToString().Trim() == "")
                {
                    lookUpEditiYear.Focus();
                    throw new Exception("请选择年度");
                }

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

                string        sSQL = "";
                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        bool b = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose));
                        if (!b)
                        {
                            continue;
                        }

                        Model._科目对照 model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._科目对照();
                        model.会计科目    = gridView1.GetRowCellValue(i, gridCol会计科目).ToString().Trim();
                        model.对照科目    = gridView1.GetRowCellValue(i, gridCol对照科目).ToString().Trim();
                        model.Remark  = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim();
                        model.RemarkJ = gridView1.GetRowCellValue(i, gridColRemarkJ).ToString().Trim();
                        model.RemarkD = gridView1.GetRowCellValue(i, gridColRemarkD).ToString().Trim();

                        model.年度  = lookUpEditiYear.EditValue.ToString().Trim();
                        model.iID = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColiID).ToString().Trim());
                        //if (model.对照科目.Trim() == "")
                        //{
                        //    sErr = sErr + "行" + (i + 1).ToString() + "对照科目没有设置\n";
                        //    continue;
                        //}

                        DAL._科目对照 dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._科目对照();
                        sSQL = dal.Exists(model.年度, model.对照科目, model.iID.ToString());
                        DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            throw new Exception("行" + (i + 1) + "对照科目不可重复");
                        }
                        if (model.iID == 0)
                        {
                            sSQL = dal.Add(model);
                        }
                        else
                        {
                            sSQL = dal.Update(model);
                        }
                        iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

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


                    if (iCount > 0)
                    {
                        tran.Commit();
                        MessageBox.Show("OK\n");

                        GetGrid();
                    }
                    else
                    {
                        throw new Exception("no data");
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

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

                string sErr  = "";
                string sWarn = "";

                if (Rep.dsPrint == null)
                {
                    throw new Exception("没有需要打印的数据");
                }

                int           iCou = 0;
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    Rep.dsPrint.Tables.Clear();

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

                    string    sSQL     = "select getdate()";
                    DataTable dt       = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    DateTime  dDateSer = BaseFunction.ReturnDate(dt.Rows[0][0]);
                    if (dDateSer.Date < BaseFunction.ReturnDate("2014-8-1"))
                    {
                        throw new Exception("获得系统日期失败");
                    }

                    sSQL = "select max(BarCode) from dbo._BarCodeList where BarCode like '" + dDateSer.ToString("yyMMdd") + "%' ";
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    string sMaxCode = "";
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        sMaxCode = dt.Rows[0][0].ToString().Trim();
                    }
                    long lMaxID = 0;
                    if (sMaxCode != "")
                    {
                        lMaxID = BaseFunction.ReturnLong(sMaxCode.Substring(6));
                    }

                    Guid sGuid = Guid.NewGuid();

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        if (BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose)))
                        {
                            decimal dQuantity = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiQuantity));
                            if (dQuantity < 0)
                            {
                                dQuantity = -1 * dQuantity;
                            }

                            decimal dBatch = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol包装批量));
                            if (dBatch == 0)
                            {
                                dBatch = dQuantity;
                            }

                            int iCount = BaseFunction.ReturnInt(Math.Ceiling(dQuantity / dBatch));



                            for (int j = 0; j < iCount; j++)
                            {
                                Model_BarCodeList model = new Model_BarCodeList();

                                lMaxID += 1;
                                string sBarCode = getBaseData.GetBarCode(dDateSer, lMaxID);

                                model.cInvCode       = gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim();
                                model.cInvName       = gridView1.GetRowCellValue(i, gridColcInvName).ToString().Trim();
                                model.cInvStd        = gridView1.GetRowCellValue(i, gridColcInvStd).ToString().Trim();
                                model.BarCode        = sBarCode;
                                model.ExsID          = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColAutoID));
                                model.ExCode         = gridView1.GetRowCellValue(i, gridColcCode).ToString().Trim();
                                model.ExType         = "采购入库单";
                                model.ExRowNo        = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColirowno));
                                model.ExVenCode      = gridView1.GetRowCellValue(i, gridColcVenCode).ToString().Trim();
                                model.ExVenName      = gridView1.GetRowCellValue(i, gridColcVenName).ToString().Trim();
                                model.ExQuantity     = dQuantity;
                                model.ExBatchQty     = dBatch;
                                model.GUID           = sGuid;
                                model.cWhCode        = gridView1.GetRowCellValue(i, gridColcWhCode).ToString().Trim();
                                model.cWhName        = gridView1.GetRowCellValue(i, gridColcWhName).ToString().Trim();
                                model.ExcPTName      = gridView1.GetRowCellValue(i, gridColcPTName).ToString().Trim();
                                model.ExcInvDefine3  = gridView1.GetRowCellValue(i, gridColcInvDefine3).ToString().Trim();
                                model.ExcComUnitName = gridView1.GetRowCellValue(i, gridColcComUnitName).ToString().Trim();
                                model.ExcPTCode      = gridView1.GetRowCellValue(i, gridColcPTCode).ToString().Trim();

                                //国外供应商批号: R+采购订单号(后7位)+日期+订单行号
                                //国内供应商批号:采购订单号(后7位)+日期+订单行号
                                sSQL = @"
select a.cVenCode,b.cVCCode ,b. cVCName 
from Vendor a
	inner join VendorClass b on  a.cVCCode = b.cVCCode 
where a.cVenCode = '111111'
";
                                sSQL = sSQL.Replace("111111", gridView1.GetRowCellValue(0, gridColcVenCode).ToString().Trim());
                                DataTable dtVen    = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                                string    scVCCode = dtVen.Rows[0]["cVCCode"].ToString().Trim();

                                string sDDCode = gridView1.GetRowCellValue(i, gridColcPOID).ToString().Trim();
                                if (sDDCode.Length >= 7)
                                {
                                    sDDCode = sDDCode.Substring(sDDCode.Length - 7);
                                }

                                if (scVCCode == "20")
                                {
                                    model.Batch = "R" + sDDCode + "-" + dDateSer.ToString("yyMMdd") + "-" + gridView1.GetRowCellValue(i, gridColPORowNo).ToString().Trim();
                                }
                                else
                                {
                                    model.Batch = "" + sDDCode + "-" + dDateSer.ToString("yyMMdd") + "-" + gridView1.GetRowCellValue(i, gridColPORowNo).ToString().Trim();
                                }
                                model.CreateUserName = sUserName;
                                model.CreateDate     = dDateSer;
                                model.ExDepCode      = gridView1.GetRowCellValue(i, gridColcDepCode).ToString().Trim();
                                model.ExDepName      = gridView1.GetRowCellValue(i, gridColcDepName).ToString().Trim();
                                model.valid          = true;
                                model.Used           = 0;
                                model.ExcMemo        = gridView1.GetRowCellValue(i, gridColcMemo).ToString().Trim();
                                model.ExcInvDefine4  = gridView1.GetRowCellValue(i, gridColcInvDefine4).ToString().Trim();
                                model.ExcInvDefine5  = gridView1.GetRowCellValue(i, gridColcInvDefine5).ToString().Trim();

                                if (j != iCount - 1)
                                {
                                    model.iQty = dBatch;
                                }
                                else
                                {
                                    model.iQty = dQuantity - dBatch * (iCount - 1);
                                }
                                model.PosCode = gridView1.GetRowCellValue(i, gridCol货位).ToString().Trim();

                                sSQL = DAL.Add(model);
                                iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }
                        }
                    }

                    sSQL = @"
select a.* 
from [_BarCodeList] a

where GUID = '" + sGuid.ToString().Trim() + "'";
                    DataTable dtPrint = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    dtPrint.TableName = "dtGrid";

                    Rep.dsPrint.Tables.Add(dtPrint.Copy());

                    if (dtPrint.Rows.Count < 1)
                    {
                        if (sErr.Length > 0)
                        {
                            throw new Exception(sErr);
                        }
                        else
                        {
                            throw new Exception("没有要打印的单据");
                        }
                    }
                    if (sErr.Trim() != "")
                    {
                        throw new Exception(sErr);
                    }

                    if (iCou == 0)
                    {
                        throw new Exception("请选择需要保存的数据");
                    }

                    //Rep.Print();
                    Rep.ShowPreview();

                    tran.Commit();
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "打印失败";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Beispiel #19
0
        private void btnTxtSplitSize_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                string sBarCode = lBarCodeScaned.Text.Trim();

                decimal dSplit = BaseFunction.ReturnDecimal(btnTxtSplitSize.Text.Trim());
                if (dSplit <= 0)
                {
                    throw new Exception("Please set split size");
                }

                decimal dLotQty = BaseFunction.ReturnDecimal(txtLotQTY.Text.Trim());
                if (dLotQty <= 0)
                {
                    throw new Exception("Please check barcode");
                }

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string    sSQL      = @"
select cast(1 as bit) as choose,BarCode,LOTQTY from [_BarCodeLabel] where 1=-1
";
                    DataTable dtBarList = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    sSQL = @"
select max(BarCode) as BarCode 
from [dbo].[_BarCodeLabel] 
where BarCode like '{0}%' 
    and iSOsID in (select max(iSOsID) from _BarCodeLabel group by BarCode)
";
                    sSQL = string.Format(sSQL, sBarCode);
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Please check barcode");
                    }

                    string   sBarCodeNew = sBarCode;
                    string[] s           = dt.Rows[0]["BarCode"].ToString().Trim().Split('-');

                    int iMax = 0;
                    if (s.Length > 1)
                    {
                        iMax = BaseFunction.ReturnInt(s[1]);
                    }

                    //if (dLotQty >= dSplit)
                    //{
                    //    DataRow dr = dtBarList.NewRow();
                    //    dr["choose"] = true;
                    //    dr["BarCode"] = sBarCode;
                    //    dr["LOTQTY"] = dSplit;
                    //    dtBarList.Rows.Add(dr);

                    //    dLotQty = dLotQty - dSplit;
                    //}
                    //else
                    //{
                    //    DataRow dr = dtBarList.NewRow();
                    //    dr["choose"] = true;
                    //    dr["BarCode"] = sBarCode;
                    //    dr["LOTQTY"] = dLotQty;
                    //    dtBarList.Rows.Add(dr);
                    //    dLotQty = 0;
                    //}

                    while (dLotQty > 0)
                    {
                        if (dLotQty >= dSplit)
                        {
                            iMax += 1;
                            DataRow dr = dtBarList.NewRow();
                            dr["choose"]  = true;
                            dr["BarCode"] = sBarCode + "-" + iMax.ToString().PadLeft(4, '0');
                            dr["LOTQTY"]  = dSplit;
                            dtBarList.Rows.Add(dr);

                            dLotQty = dLotQty - dSplit;
                        }
                        else
                        {
                            iMax += 1;
                            DataRow dr = dtBarList.NewRow();
                            dr["choose"]  = true;
                            dr["BarCode"] = sBarCode + "-" + iMax.ToString().PadLeft(4, '0');
                            dr["LOTQTY"]  = dLotQty;
                            dtBarList.Rows.Add(dr);
                            dLotQty = 0;
                        }
                    }

                    gridControl1.DataSource = dtBarList;

                    tran.Commit();
                }
                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 #20
0
        private void btnUnAudit_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                string        sErr = "";
                int           iCou = 0;
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string s会计期间 = lookUpEdit会计期间.EditValue.ToString().Trim();
                    string s费用类型 = lookUpEditCostType.EditValue.ToString().Trim();
                    if (s会计期间 == "")
                    {
                        lookUpEdit会计期间.Focus();
                        throw new Exception("会计期间不能为空");
                    }

                    string sSQL = "select count(1) from _部门费用登记 where 会计期间 = '111111'";
                    sSQL = sSQL.Replace("111111", s会计期间);
                    int iCount = BaseFunction.ReturnInt(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    if (iCount == 0)
                    {
                        throw new Exception("请先保存数据");
                    }


                    sSQL   = "select count(1) from _部门费用登记 where 会计期间 = '111111' and isnull(记账人,'') <> '' and 费用类型 = '" + s费用类型 + "'";
                    sSQL   = sSQL.Replace("111111", s会计期间);
                    iCount = BaseFunction.ReturnInt(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    if (iCount > 0)
                    {
                        throw new Exception("已经记账");
                    }

                    sSQL   = "select count(1) from _部门费用登记 where 会计期间 = '111111' and isnull(审核人,'') <> '' and 费用类型 = '" + s费用类型 + "'";
                    sSQL   = sSQL.Replace("111111", s会计期间);
                    iCount = BaseFunction.ReturnInt(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    if (iCount == 0)
                    {
                        throw new Exception("尚未审核不能弃审");
                    }

                    sSQL = "update _部门费用登记 set 审核人 =null,审核日期 = null where  会计期间 = '111111' and 费用类型 = '" + s费用类型 + "'";

                    sSQL = sSQL.Replace("111111", s会计期间);
                    iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                    tran.Commit();

                    GetGrid();

                    if (iCou > 0)
                    {
                        MessageBox.Show("弃审成功");
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "弃审失败";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Beispiel #21
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                string        sErr = "";
                int           iCou = 0;
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string s会计期间 = lookUpEdit会计期间.EditValue.ToString().Trim();
                    if (s会计期间 == "")
                    {
                        lookUpEdit会计期间.Focus();
                        throw new Exception("会计期间不能为空");
                    }
                    string s费用类型 = lookUpEditCostType.EditValue.ToString().Trim();
                    if (s费用类型 == "")
                    {
                        lookUpEdit会计期间.Focus();
                        throw new Exception("费用类型不能为空");
                    }


                    string sSQL = "select count(1) from _部门费用登记 where 会计期间 = '111111' and isnull(审核人,'') <> '' and 费用类型 = '" + s费用类型 + "'";
                    sSQL = sSQL.Replace("111111", s会计期间);
                    int iCount = BaseFunction.ReturnInt(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    if (iCount > 0)
                    {
                        throw new Exception("已经审核不能修改");
                    }

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        decimal d金额 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol金额), 2);
                        if (d金额 < 0)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "金额不能小于0\n";
                            continue;
                        }

                        Model._部门费用登记 model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._部门费用登记();
                        model.备注   = gridView1.GetRowCellValue(i, gridCol备注).ToString().Trim();
                        model.费用类型 = s费用类型;
                        model.部门   = gridView1.GetRowCellValue(i, gridCol部门编码).ToString().Trim();
                        model.会计期间 = lookUpEdit会计期间.EditValue.ToString().Trim();
                        model.金额   = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol金额), 2);

                        DAL._部门费用登记 dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._部门费用登记();

                        sSQL = "select * from _部门费用登记 where 会计期间 = '111111' and isnull(部门,'') = '" + gridView1.GetRowCellValue(i, gridCol部门编码).ToString().Trim() + "' and 费用类型 = '" + s费用类型 + "'";
                        sSQL = sSQL.Replace("111111", s会计期间);
                        DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dt == null || dt.Rows.Count == 0)
                        {
                            model.制单人  = sUserName;
                            model.制单日期 = DateTime.Now;
                            sSQL       = dal.Add(model);
                        }
                        else
                        {
                            model.制单人  = gridView1.GetRowCellValue(i, gridCol制单人).ToString().Trim();
                            model.制单日期 = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridCol制单日期));
                            model.修改人  = sUserName;
                            model.修改日期 = DateTime.Now;
                            sSQL       = dal.Update(model);
                        }
                        iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    tran.Commit();

                    GetGrid();

                    if (iCou > 0)
                    {
                        MessageBox.Show("保存成功");
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "保存失败";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Beispiel #22
0
        private void btnAudit_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                string        sErr = "";
                int           iCou = 0;
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string s会计期间 = lookUpEdit会计期间.EditValue.ToString().Trim();
                    if (s会计期间 == "")
                    {
                        lookUpEdit会计期间.Focus();
                        throw new Exception("会计期间不能为空");
                    }

                    string s部门 = lookUpEditcDepCode.EditValue.ToString().Trim();
                    if (s部门 == "")
                    {
                        lookUpEditcDepCode.Focus();
                        throw new Exception("部门不能为空");
                    }

                    string sSQL = "select count(1) from _费用分配 where 会计期间 = '111111' and isnull(审核人,'') <> '' and 部门编码 = '222222'";
                    sSQL = sSQL.Replace("111111", s会计期间);
                    sSQL = sSQL.Replace("222222", s部门);
                    int iCount = BaseFunction.ReturnInt(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    if (iCount > 0)
                    {
                        throw new Exception("已经审核");
                    }

                    sSQL = "update _费用分配 set 审核人 = '" + sUserName + "' ,审核日期 = getdate() where 会计期间 = '111111' and 部门编码 = '222222'";
                    sSQL = sSQL.Replace("111111", s会计期间);
                    sSQL = sSQL.Replace("222222", s部门);
                    iCou = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    tran.Commit();

                    GetGrid();

                    if (iCou > 0)
                    {
                        MessageBox.Show("审核成功");
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "删除失败";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Beispiel #23
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                gridView1.FocusedRowHandle -= 1;
                gridView1.FocusedRowHandle += 1;
            }
            catch { }

            txtBarCode.Focus();
            string sErr = "";

            int iCount = 0;

            try
            {
                string sProcess = gridView1.GetRowCellValue(0, gridColProcess).ToString().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"));

                    int    iYear   = dNow.Year;
                    int    iPeriod = dNow.Month;
                    string s期间     = BaseFunction.ReturnDate(iYear.ToString() + "-" + iPeriod.ToString() + "-01").ToString("yyyyMM");
                    sSQL = "select isnull(bflag_ST,0) as bflag from GL_mend where iYPeriod = '" + s期间 + "'";
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Access module state failure");
                    }
                    int i结账 = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]);
                    if (i结账 > 0)
                    {
                        throw new Exception(dNow.ToString("yyyy-MM") + " have checked out");
                    }

                    #region 必须销售类型是“WP”,状态非关闭。 回写销售订单数量,并新增其它出库单(数量增加红字出库单,数量减少蓝字出库单)

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        long   lSOsID   = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiSOsID));
                        string sBarCode = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim();

                        decimal dLotQTY   = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY));
                        decimal dOrderQTY = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColcbdefine4));

                        string siSOsID = gridView1.GetRowCellValue(i, gridColiSOsID).ToString().Trim();

                        sSQL = @"
select LOTQTY from [dbo].[_BarCodeLabel] where Barcode = '{0}' and iSOsID =  {1}
";
                        sSQL = string.Format(sSQL, sBarCode, lSOsID);
                        DataTable dtBarCodeLabel = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];


                        if (dLotQTY == BaseFunction.ReturnDecimal(dtBarCodeLabel.Rows[0]["LOTQTY"]))
                        {
                            continue;
                        }

                        decimal dQTYtc = BaseFunction.ReturnDecimal(dtBarCodeLabel.Rows[0]["LOTQTY"]) - dLotQTY;

                        if (dLotQTY > dOrderQTY)
                        {
                            sErr = sErr + "Row " + (i + 1).ToString() + " lotqty is err\n";
                            continue;
                        }

                        if (gridView1.GetRowCellValue(i, gridColLOTQTY).ToString().Trim() == "")
                        {
                            sErr = sErr + "Row " + (i + 1).ToString() + " lotqty is err\n";
                            continue;
                        }

                        if (BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY).ToString().Trim()) == 0)
                        {
                            sErr = sErr + "Row " + (i + 1).ToString() + " lotqty is 0 err\n";
                            continue;
                        }


                        //回写条码数量
                        sSQL = @"update [_BarCodeLabel] set [Status] = '调整', orderqty = aaaaaa, LOTQTY = aaaaaa where BarCode = 'bbbbbb' and iSOsID = " + gridView1.GetRowCellValue(i, gridColiSOsID).ToString().Trim();
                        sSQL = sSQL.Replace("aaaaaa", dLotQTY.ToString());
                        sSQL = sSQL.Replace("bbbbbb", sBarCode);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        Model.BarStatus model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                        model.BarCode     = sBarCode;
                        model.iSOsID      = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiSOsID));
                        model.Type        = "调整";
                        model.RoutingFrom = gridView1.GetRowCellValue(i, gridColProcess).ToString().Trim();
                        model.RoutingTo   = gridView1.GetRowCellValue(i, gridColProcess).ToString().Trim();
                        model.UpdateTime  = dNow;
                        model.QTY         = dLotQTY;
                        model.CreateUid   = sUserID;
                        model.CreateDate  = dNow;
                        DAL.BarStatus dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus();
                        sSQL    = dal.Add(model);
                        iCount += 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, model.BarCode, model.iSOsID, dNow);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        //回写销售订单数量
                        sSQL = @"update SO_SODetails set iQuantity = aaaaaa where iSOsID =  bbbbbb";
                        sSQL = sSQL.Replace("aaaaaa", dLotQTY.ToString());
                        sSQL = sSQL.Replace("bbbbbb", lSOsID.ToString());
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        //回写销售订单金额
                        sSQL = @"
update SO_SODetails set iMoney = iQuantity * iUnitPrice,iSum = iTaxUnitPrice * iQuantity,iTax = iTaxUnitPrice * iQuantity - iQuantity * iUnitPrice
    ,iNatMoney = iNatUnitPrice * iQuantity , iNatSum = iNatMoney * (1 + iTaxRate / 100),iNatTax = iNatMoney * (1 + iTaxRate / 100) - iNatUnitPrice * iQuantity
where iSOsID =  bbbbbb
";
                        sSQL = sSQL.Replace("bbbbbb", lSOsID.ToString());
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        //------------------------------------------------------------------------
                        #region  步生成其它出库单

                        sSQL = @"
select * 
from SO_SOMain a inner join SO_SODetails b on a.ID = b.ID
    left join _SystemSet c on a.cSTCode = c.cSTCode
    inner join Inventory d on b.cInvCode = d.cInvCode
where b.iSOsID = aaaaaa
order by b.autoid
";
                        sSQL = sSQL.Replace("aaaaaa", lSOsID.ToString().Trim());
                        DataTable dtSOMain = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        if (dtSOMain == null || dtSOMain.Rows.Count == 0)
                        {
                            throw new Exception("Sale Order not exists err");
                        }

                        string sCTCode = dtSOMain.Rows[0]["cSTCode"].ToString().Trim();

                        //DateTime dDate = BaseFunction.ReturnDate(dtSOMain.Rows[0]["dDate"]);
                        DateTime dDate = DateTime.Today;
                        sSQL = "select isnull(bflag_ST,0) as bflag from GL_mend where iYPeriod = '" + dDate.ToString("yyyyMM") + "'";
                        dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dt == null || dt.Rows.Count == 0)
                        {
                            throw new Exception("Access module state failure");
                        }
                        int i结账RD = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]);
                        if (i结账RD > 0)
                        {
                            throw new Exception(dDate.ToString("yyyy-MM") + " have checked out");
                        }

                        //获得单据号
                        sSQL = "select cNumber from VoucherHistory with (ROWLOCK) Where cSeed = 'aaaaaa' AND cContentRule = 'YYYY' AND CardNumber = '0302' ORDER BY cNumber DESC";
                        sSQL = sSQL.Replace("aaaaaa", dDate.ToString("yyyy"));
                        dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        long lCodeRD = 0;
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            lCodeRD = BaseFunction.ReturnLong(dt.Rows[0]["cNumber"]);
                        }
                        else
                        {
                            lCodeRD = 0;
                        }

                        long lIDRD        = -1;
                        long lIDRDDetails = -1;
                        sSQL = @"
declare @p5 int
set @p5=aaaaaa
declare @p6 int
set @p6=bbbbbb
exec sp_GetId N'00',N'dddddd',N'rd',cccccc,@p5 output,@p6 output,default
select @p5, @p6
";
                        sSQL = sSQL.Replace("aaaaaa", lIDRD.ToString());
                        sSQL = sSQL.Replace("bbbbbb", lIDRDDetails.ToString());
                        sSQL = sSQL.Replace("cccccc", 1.ToString());
                        sSQL = sSQL.Replace("dddddd", sAccID);
                        dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        lIDRD        = BaseFunction.ReturnLong(dt.Rows[0][0]) - 1;
                        lIDRDDetails = BaseFunction.ReturnLong(dt.Rows[0][1]) - 1;

                        //ArrayList aList = new ArrayList();

                        Model.RdRecord09 modelRD = new Model.RdRecord09();
                        lIDRD     += 1;
                        modelRD.ID = lIDRD;

                        modelRD.bRdFlag    = 0;
                        modelRD.cVouchType = "09";
                        modelRD.cBusType   = "其他出库";
                        modelRD.cSource    = "库存";
                        //modelRD.cBusCode =


                        modelRD.cWhCode = dtSOMain.Rows[0]["cWhCode"].ToString().Trim();        //需要仓库默认值
                        if (dtSOMain.Rows[0]["cWhCode"].ToString().Trim() == "")
                        {
                            throw new Exception("Please set default warehouse");
                        }

                        modelRD.dDate = dDate;        //需要默认值

                        lCodeRD += 1;
                        string sCodeRD = lCodeRD.ToString();
                        while (sCodeRD.Length < 6)
                        {
                            sCodeRD = "0" + sCodeRD;
                        }
                        modelRD.cCode   = "MR" + dNow.ToString("yyyy") + sCodeRD;
                        modelRD.cRdCode = "AD";      //需要默认值
                        if (dtSOMain.Rows[0]["cRdCode"].ToString().Trim() == "")
                        {
                            throw new Exception("Please set RdCode");
                        }
                        //modelRD.cDepCode = ""
                        //modelRD.cPersonCode;
                        //modelRD.cPTCode;
                        //modelRD.cSTCode;
                        //modelRD.cCusCode;
                        //modelRD.cVenCode;
                        //modelRD.cOrderCode;
                        //modelRD.cARVCode;
                        //modelRD.cBillCode;
                        //modelRD.cDLCode;
                        //modelRD.cProBatch;
                        modelRD.cHandler = sUserName;
                        //modelRD.cMemo;
                        modelRD.bTransFlag = false;
                        //modelRD.cAccounter;
                        modelRD.cMaker   = sUserName;
                        modelRD.cDefine1 = dtSOMain.Rows[0]["cDefine1"].ToString();
                        modelRD.cDefine2 = dtSOMain.Rows[0]["cDefine2"].ToString();
                        modelRD.cDefine3 = dtSOMain.Rows[0]["cDefine3"].ToString();

                        if (dtSOMain.Rows[0]["cDefine4"].ToString().Trim() != "")
                        {
                            modelRD.cDefine4 = BaseFunction.ReturnDate(dtSOMain.Rows[0]["cDefine4"]);
                        }
                        if (dtSOMain.Rows[0]["cDefine5"].ToString().Trim() != "")
                        {
                            modelRD.cDefine5 = BaseFunction.ReturnLong(dtSOMain.Rows[0]["cDefine5"]);
                        }
                        if (dtSOMain.Rows[0]["cDefine6"].ToString().Trim() != "")
                        {
                            modelRD.cDefine6 = BaseFunction.ReturnDate(dtSOMain.Rows[0]["cDefine6"]);
                        }
                        if (dtSOMain.Rows[0]["cDefine7"].ToString().Trim() != "")
                        {
                            modelRD.cDefine7 = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["cDefine7"]);
                        }
                        modelRD.cDefine8  = dtSOMain.Rows[0]["cDefine8"].ToString();
                        modelRD.cDefine9  = dtSOMain.Rows[0]["cDefine9"].ToString();
                        modelRD.cDefine10 = dtSOMain.Rows[0]["cDefine10"].ToString();
                        //modelRD.dKeepDate;
                        modelRD.dVeriDate = dDate;
                        modelRD.bpufirst  = false;
                        modelRD.biafirst  = false;
                        //modelRD.iMQuantity;
                        //modelRD.dARVDate;
                        //modelRD.cChkCode;
                        //modelRD.dChkDate;
                        //modelRD.cChkPerson;
                        modelRD.VT_ID     = 85;
                        modelRD.bIsSTQc   = false;
                        modelRD.cDefine11 = dtSOMain.Rows[0]["cDefine11"].ToString();
                        modelRD.cDefine12 = dtSOMain.Rows[0]["cDefine12"].ToString();
                        modelRD.cDefine13 = dtSOMain.Rows[0]["cDefine13"].ToString();
                        modelRD.cDefine14 = dtSOMain.Rows[0]["cDefine14"].ToString();

                        if (dtSOMain.Rows[0]["cDefine15"].ToString() != "")
                        {
                            modelRD.cDefine15 = BaseFunction.ReturnLong(dtSOMain.Rows[0]["cDefine15"]);
                        }
                        if (dtSOMain.Rows[0]["cDefine16"].ToString() != "")
                        {
                            modelRD.cDefine16 = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["cDefine16"]);
                        }
                        //modelRD.gspcheck;
                        //modelRD.ufts;
                        //modelRD.iExchRate;
                        //modelRD.cExch_Name;
                        modelRD.bOMFirst         = false;
                        modelRD.bFromPreYear     = false;
                        modelRD.bIsLsQuery       = false;
                        modelRD.bIsComplement    = 0;
                        modelRD.iDiscountTaxType = 0;
                        modelRD.ireturncount     = 0;
                        modelRD.iverifystate     = 0;
                        modelRD.iswfcontrolled   = 0;
                        //modelRD.cModifyPerson;
                        //modelRD.dModifyDate;
                        //modelRD.dnmaketime;
                        //modelRD.dnmodifytime;
                        modelRD.dnverifytime = dNow;
                        modelRD.bredvouch    = 0;
                        //modelRD.iFlowId;
                        //modelRD.cPZID;
                        //modelRD.cSourceLs;
                        //modelRD.cSourceCodeLs;
                        modelRD.iPrintCount = 0;
                        //modelRD.ctransflag;
                        //modelRD.csysbarcode;
                        //modelRD.cCurrentAuditor;
                        DAL.RdRecord09 dalRD = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.RdRecord09();
                        sSQL = dalRD.Add(modelRD);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                        lIDRDDetails += 1;


                        Model.rdrecords09 modelsRD = new Model.rdrecords09();
                        modelsRD.AutoID = lIDRDDetails;


                        modelsRD.ID       = modelRD.ID;
                        modelsRD.cInvCode = dtSOMain.Rows[0]["cInvCode"].ToString().Trim();

                        //if (dtSOMain.Rows[0]["iNum"].ToString().Trim() != "")
                        //{
                        //    modelsRD.iNum = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["iNum"]);
                        //}
                        modelsRD.iQuantity = dQTYtc;
                        //modelsRD.iUnitCost;
                        //modelsRD.iPrice;
                        //modelsRD.iAPrice;
                        //modelsRD.iPUnitCost;
                        //modelsRD.iPPrice;

                        modelsRD.cBatch = gridView1.GetRowCellValue(i, gridColcBatch).ToString().Trim();

                        //modelsRD.cVouchCode;
                        //modelsRD.cInVouchCode;
                        //modelsRD.cinvouchtype;
                        //modelsRD.iSOutQuantity;
                        //modelsRD.iSOutNum;
                        //modelsRD.cFree1;
                        //modelsRD.cFree2;
                        modelsRD.iFlag = 0;
                        //modelsRD.iFNum;
                        //modelsRD.iFQuantity;
                        //modelsRD.dVDate;
                        //modelsRD.iTrIds;
                        //modelsRD.cPosition;
                        //modelsRD.cDefine22;
                        //modelsRD.cDefine23;
                        //modelsRD.cDefine24;
                        //modelsRD.cDefine25;
                        //modelsRD.cDefine26;
                        //modelsRD.cDefine27;
                        //modelsRD.cItem_class;
                        //modelsRD.cItemCode;
                        //modelsRD.cName;
                        //modelsRD.cItemCName;
                        //modelsRD.cFree3;
                        //modelsRD.cFree4;
                        //modelsRD.cFree5;
                        //modelsRD.cFree6;
                        //modelsRD.cFree7;
                        //modelsRD.cFree8;
                        //modelsRD.cFree9;
                        //modelsRD.cFree10;
                        //modelsRD.cBarCode;
                        //modelsRD.iNQuantity;
                        //modelsRD.iNNum;
                        //modelsRD.cAssUnit;
                        //modelsRD.dMadeDate;
                        //modelsRD.iMassDate;
                        //modelsRD.cDefine28;
                        //modelsRD.cDefine29;
                        //modelsRD.cDefine30;
                        //modelsRD.cDefine31;
                        //modelsRD.cDefine32;
                        //modelsRD.cDefine33;
                        //modelsRD.cDefine34;
                        //modelsRD.cDefine35;
                        //modelsRD.cDefine36;
                        //modelsRD.cDefine37;
                        //modelsRD.iCheckIds;
                        //modelsRD.cBVencode;
                        //modelsRD.chVencode;
                        //modelsRD.bGsp;
                        //modelsRD.cGspState;
                        //modelsRD.cCheckCode;
                        //modelsRD.iCheckIdBaks;
                        //modelsRD.cRejectCode;
                        //modelsRD.iRejectIds;
                        //modelsRD.cCheckPersonCode;
                        //modelsRD.dCheckDate;
                        //modelsRD.cMassUnit;
                        //modelsRD.bChecked;
                        modelsRD.bLPUseFree = false;
                        //modelsRD.iRSRowNO;
                        //modelsRD.iOriTrackID;
                        //modelsRD.coritracktype;
                        //modelsRD.cbaccounter;
                        //modelsRD.dbKeepDate;
                        modelsRD.bCosting = true;
                        modelsRD.bVMIUsed = false;
                        //modelsRD.iVMISettleQuantity;
                        //modelsRD.iVMISettleNum;
                        //modelsRD.cvmivencode;
                        //modelsRD.iInvSNCount;
                        //modelsRD.cwhpersoncode;
                        //modelsRD.cwhpersonname;
                        //modelsRD.cserviceoid;
                        //modelsRD.cbserviceoid;
                        //modelsRD.iinvexchrate;
                        //modelsRD.corufts;
                        //modelsRD.strContractGUID;
                        modelsRD.iExpiratDateCalcu = 0;
                        //modelsRD.cExpirationdate;
                        //modelsRD.dExpirationdate;
                        //modelsRD.cciqbookcode;
                        //modelsRD.iBondedSumQty;
                        //modelsRD.iorderdid;
                        modelsRD.iordertype = 0;
                        //modelsRD.iordercode;
                        //modelsRD.iorderseq;
                        //modelsRD.isodid;
                        modelsRD.isotype = 0;
                        modelsRD.csocode = dtSOMain.Rows[0]["cSOCode"].ToString().Trim();
                        //modelsRD.isoseq
                        //modelsRD.cBatchProperty1;
                        //modelsRD.cBatchProperty2;
                        //modelsRD.cBatchProperty3;
                        //modelsRD.cBatchProperty4;
                        //modelsRD.cBatchProperty5;
                        //modelsRD.cBatchProperty6;
                        //modelsRD.cBatchProperty7;
                        //modelsRD.cBatchProperty8;
                        //modelsRD.cBatchProperty9;
                        //modelsRD.cBatchProperty10;
                        //modelsRD.cbMemo;
                        modelsRD.irowno = 1;
                        //modelsRD.strowguid;
                        //modelsRD.rowufts;
                        //modelsRD.ipreuseqty;
                        //modelsRD.ipreuseinum;
                        //modelsRD.cbsourcecodels;
                        //modelsRD.iGroupNO;
                        //modelsRD.iDebitIDs;
                        //modelsRD.idebitchildids;
                        //modelsRD.OutCopiedQuantity;
                        //modelsRD.cbsysbarcode

                        DAL.rdrecords09 dalsRD = new DAL.rdrecords09();
                        sSQL   = dalsRD.Add(modelsRD);
                        iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        sSQL = @"
if exists
    (select * from  CurrentStock where cInvCode = '@cInvCode' and cWhCode = '@cWhCode'
        and isnull(cFree1,'') = @cFree1 
        and isnull(cFree2,'') = @cFree2
        and isnull(cFree3,'') = @cFree3
        and isnull(cFree4,'') = @cFree4
        and isnull(cFree5,'') = @cFree5
        and isnull(cFree6,'') = @cFree6
        and isnull(cFree7,'') = @cFree7
        and isnull(cFree8,'') = @cFree8
        and isnull(cFree9,'') = @cFree9
        and isnull(cFree10,'') = @cFree10
        and isnull(cBatch,'') = @cBatch 
    )
    update  CurrentStock set iQuantity = isnull(iQuantity,0) + @iQuantity  
    where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' 
        and isnull(cFree1,'') = @cFree1 
        and isnull(cFree2,'') = @cFree2
        and isnull(cFree3,'') = @cFree3
        and isnull(cFree4,'') = @cFree4
        and isnull(cFree5,'') = @cFree5
        and isnull(cFree6,'') = @cFree6
        and isnull(cFree7,'') = @cFree7
        and isnull(cFree8,'') = @cFree8
        and isnull(cFree9,'') = @cFree9
        and isnull(cFree10,'') = @cFree10
        and isnull(cBatch,'') = @cBatch 
else 
    begin 
        declare @itemid varchar(20); 
        declare @iCount int;  
        select @iCount=count(itemid) from CurrentStock where cInvCode = '@cInvCode';
        if( @iCount > 0 )
	        select @itemid=itemid from CurrentStock where cInvCode = '@cInvCode';
        else  
            select @itemid=max(itemid+1) from CurrentStock  
            insert into CurrentStock(cWhCode,cInvCode,iQuantity,itemid, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,cBatch,iSoDid)
            values('@cWhCode','@cInvCode', @iQuantity,@itemid, @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8, @cFree9, @cFree10,@cBatch,'') 
    end
";
                        sSQL = sSQL.Replace("@cInvCode", modelsRD.cInvCode);
                        sSQL = sSQL.Replace("@cWhCode", modelRD.cWhCode);
                        sSQL = sSQL.Replace("@iQuantity", (-1 * modelsRD.iQuantity).ToString());
                        sSQL = sSQL.Replace("@iNum", (-1 * modelsRD.iNum).ToString());
                        sSQL = sSQL.Replace("@cFree10", modelsRD.cFree10 == null ? "''" : "'" + modelsRD.cFree10 + "'");
                        sSQL = sSQL.Replace("@cFree1", modelsRD.cFree1 == null ? "''" : "'" + modelsRD.cFree1 + "'");
                        sSQL = sSQL.Replace("@cFree2", modelsRD.cFree2 == null ? "''" : "'" + modelsRD.cFree2 + "'");
                        sSQL = sSQL.Replace("@cFree3", modelsRD.cFree3 == null ? "''" : "'" + modelsRD.cFree3 + "'");
                        sSQL = sSQL.Replace("@cFree4", modelsRD.cFree4 == null ? "''" : "'" + modelsRD.cFree4 + "'");
                        sSQL = sSQL.Replace("@cFree5", modelsRD.cFree5 == null ? "''" : "'" + modelsRD.cFree5 + "'");
                        sSQL = sSQL.Replace("@cFree6", modelsRD.cFree6 == null ? "''" : "'" + modelsRD.cFree6 + "'");
                        sSQL = sSQL.Replace("@cFree7", modelsRD.cFree7 == null ? "''" : "'" + modelsRD.cFree7 + "'");
                        sSQL = sSQL.Replace("@cFree8", modelsRD.cFree8 == null ? "''" : "'" + modelsRD.cFree8 + "'");
                        sSQL = sSQL.Replace("@cFree9", modelsRD.cFree9 == null ? "''" : "'" + modelsRD.cFree9 + "'");
                        sSQL = sSQL.Replace("@cBatch", modelsRD.cBatch == null ? "''" : "'" + modelsRD.cBatch + "'");
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                        sSQL = @"
exec ST_SaveForStock N'09',N'aaaaaa',1,0 ,1
";
                        sSQL = sSQL.Replace("aaaaaa", lIDRD.ToString());
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        sSQL = @"
exec ST_SaveForTrackStock N'09',N'aaaaaa', 0 ,1
";
                        sSQL = sSQL.Replace("aaaaaa", lIDRD.ToString());
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        sSQL = @"
exec IA_SP_WriteUnAccountVouchForST 'aaaaaa',N'09'
";
                        sSQL = sSQL.Replace("aaaaaa", lIDRD.ToString());
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                        if (lIDRD > 1000000000)
                        {
                            lIDRD = lIDRD - 1000000000;
                        }
                        if (lIDRDDetails > 1000000000)
                        {
                            lIDRDDetails = lIDRDDetails - 1000000000;
                        }
                        sSQL = "update UFSystem..UA_Identity set iFatherId = " + lIDRD.ToString() + ",iChildId = " + lIDRDDetails + " where cAcc_Id = '" + sAccID + "' and cVouchType = 'rd'";
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        sSQL = @"
if exists(select * from VoucherHistory where CardNumber = '0302' and cSeed = 'aaaaaa' AND cContentRule = 'YYYY')
	update VoucherHistory set cNumber = bbbbbb  where CardNumber = '0302' and cSeed = 'aaaaaa' AND cContentRule = 'YYYY'
else
	insert into VoucherHistory(CardNumber,cContent,cContentRule,cSeed,cNumber,bEmpty)
	values('0302','日期','YYYY','aaaaaa','bbbbbb',0)
";
                        sSQL = sSQL.Replace("aaaaaa", dDate.ToString("yyyy"));
                        sSQL = sSQL.Replace("bbbbbb", lCodeRD.ToString());
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        #endregion
                        //------------------------------------------------------------------------
                    }

                    #endregion

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

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

                        MessageBox.Show("OK\n");

                        SetTxtNull();

                        gridControl1.DataSource = DbHelperSQL.Query(sSQLBar);
                        txtBarCode.Focus();
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #24
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                Rep = new RepBaseGrid();

                Rep.dsPrint.Tables.Clear();

                if (radioCG.Checked)
                {
                    sPrintLayOutMod  = Application.StartupPath + "\\UAP\\Runtime\\print\\Model\\历史条形码打印Mod.dll";
                    sPrintLayOutUser = Application.StartupPath + "\\UAP\\Runtime\\print\\User\\历史条形码打印User.dll";

                    if (radioBarCode.Checked)
                    {
                        if (File.Exists(sPrintLayOutUser))
                        {
                            Rep.LoadLayout(sPrintLayOutUser);
                        }
                        else if (File.Exists(sPrintLayOutMod))
                        {
                            Rep.LoadLayout(sPrintLayOutMod);
                        }
                        else
                        {
                            MessageBox.Show("加载报表模板失败,请与管理员联系");
                            return;
                        }
                    }
                    if (radioBarCodeBox.Checked)
                    {
                        if (File.Exists(sPrintLayOutUser2))
                        {
                            Rep.LoadLayout(sPrintLayOutUser2);
                        }
                        else if (File.Exists(sPrintLayOutMod2))
                        {
                            Rep.LoadLayout(sPrintLayOutMod2);
                        }
                        else
                        {
                            MessageBox.Show("加载报表模板失败,请与管理员联系");
                            return;
                        }
                    }

                    string sErr  = "";
                    string sWarn = "";

                    if (Rep.dsPrint == null)
                    {
                        throw new Exception("没有需要打印的数据");
                    }

                    int           iCou = 0;
                    SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                    conn.Open();
                    //启用事务
                    SqlTransaction tran = conn.BeginTransaction();
                    try
                    {
                        Rep.dsPrint.Tables.Clear();

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

                        string    sSQL     = "select getdate()";
                        DataTable dt       = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        DateTime  dDateSer = BaseFunction.ReturnDate(dt.Rows[0][0]);
                        if (dDateSer.Date < BaseFunction.ReturnDate("2014-8-1"))
                        {
                            throw new Exception("获得系统日期失败");
                        }

                        string sCode = dDateSer.ToString("yyMMrrhhmmss");

                        long lMaxID = 0;
                        if (radioBarCode.Checked)
                        {
                            sSQL = "select max(BarCode) from dbo._BarCodeList where BarCode like '" + dDateSer.ToString("yyMMdd") + "%' ";
                            dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            string sMaxCode = "";
                            if (dt != null && dt.Rows.Count > 0)
                            {
                                sMaxCode = dt.Rows[0][0].ToString().Trim();
                            }
                            if (sMaxCode != "")
                            {
                                lMaxID = BaseFunction.ReturnLong(sMaxCode.Substring(6));
                            }
                        }
                        if (radioBarCodeBox.Checked)
                        {
                            sSQL = "select max(BarCode) from dbo._BarCodeList where BarCode not like '" + dDateSer.ToString("yyMMdd") + "%' ";
                            dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            string sMaxCode = "";
                            if (dt != null && dt.Rows.Count > 0)
                            {
                                sMaxCode = dt.Rows[0][0].ToString().Trim();
                            }
                            if (sMaxCode != "")
                            {
                                lMaxID = BaseFunction.ReturnLong(sMaxCode.Substring(7));
                            }
                        }

                        Guid sGuid = Guid.NewGuid();

                        for (int i = 0; i < gridView1.RowCount; i++)
                        {
                            if (BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose)))
                            {
                                string    sBarCodeHis = gridView1.GetRowCellValue(i, gridColBarCode).ToString().Trim();
                                DataRow[] drList      = dtGrid.Select("BarCode = '" + sBarCodeHis + "'");
                                DataRow   dr          = drList[0];

                                Model_BarCodeList model = new Model_BarCodeList();

                                lMaxID += 1;

                                string sBarCode = "";
                                if (radioBarCode.Checked)
                                {
                                    sBarCode = getBaseData.GetBarCode(dDateSer, lMaxID);
                                }
                                if (radioBarCodeBox.Checked)
                                {
                                    sBarCode = getBaseData.GetBarCodeBox(dDateSer, lMaxID);
                                }

                                model = DAL.DataRowToModel(dr);

                                model.BarCode    = sBarCode;
                                model.BarCodeHis = sBarCodeHis;
                                model.ExQuantity = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiQty));

                                model.iQty           = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColUseQty));
                                model.CreateUserName = sUserName;
                                model.CreateDate     = dDateSer;
                                model.valid          = true;
                                model.Used           = 0;
                                model.GUID           = sGuid;

                                sSQL = DAL.Add(model);
                                iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                sSQL = "update _BarCodeList set valid = 0 where BarCode = '" + sBarCodeHis + "'";
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                if (radioBarCode.Checked)
                                {
                                    //登记源条码作废
                                    Model_BarCodeRD modelRD = new Model_BarCodeRD();
                                    DAL_BarCodeRD   dalRD   = new DAL_BarCodeRD();
                                    modelRD.sCode      = sCode;
                                    modelRD.BarCode    = sBarCodeHis;
                                    modelRD.sType      = "历史条码打印";
                                    modelRD.cInvCode   = gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim();
                                    modelRD.Qty        = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColUseQty));
                                    modelRD.CreateUid  = sUserName;
                                    modelRD.CreateDate = dDateSer;
                                    modelRD.ExCode     = sBarCodeHis;
                                    modelRD.RDType     = 2;
                                    sSQL = dalRD.Add(modelRD);
                                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                    modelRD.BarCode = sBarCode;
                                    modelRD.RDType  = 1;
                                    sSQL            = dalRD.Add(modelRD);
                                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                                }
                            }
                        }

                        sSQL = "select * from [_BarCodeList] where GUID = '" + sGuid.ToString().Trim() + "'";
                        DataTable dtPrint = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        dtPrint.TableName = "dtGrid";

                        Rep.dsPrint.Tables.Add(dtPrint.Copy());

                        if (dtPrint.Rows.Count < 1)
                        {
                            throw new Exception("没有要打印的单据");
                        }
                        if (sErr.Trim() != "")
                        {
                            throw new Exception(sErr);
                        }

                        if (iCou == 0)
                        {
                            throw new Exception("请选择需要保存的数据");
                        }

                        //Rep.Print();
                        Rep.ShowPreview();

                        tran.Commit();

                        btnRefresh_Click(null, null);
                    }
                    catch (Exception error)
                    {
                        tran.Rollback();
                        throw new Exception(error.Message);
                    }
                }
                if (radioQC.Checked)
                {
                    sPrintLayOutMod  = Application.StartupPath + "\\UAP\\Runtime\\print\\Model\\期初条形码打印Mod.dll";
                    sPrintLayOutUser = Application.StartupPath + "\\UAP\\Runtime\\print\\User\\期初条形码打印User.dll";

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

                    DataTable dtPrint = (DataTable)gridControl1.DataSource;

                    DataTable dtPrTemp = dtPrint.Copy();
                    for (int i = dtPrTemp.Rows.Count - 1; i >= 0; i--)
                    {
                        bool b = BaseFunction.ReturnBool(dtPrTemp.Rows[i]["choose"]);
                        if (!b)
                        {
                            dtPrTemp.Rows.RemoveAt(i);
                        }
                    }

                    dtPrTemp.TableName = "dtGrid";


                    Rep.dsPrint.Tables.Add(dtPrTemp.Copy());

                    if (dtPrint.Rows.Count < 1)
                    {
                        throw new Exception("没有要打印的单据");
                    }
                    //Rep.Print();
                    Rep.ShowPreview();
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "打印失败";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Beispiel #25
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 #26
0
        private void btnSave_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"));

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        int    iID    = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColiID));
                        string iState = gridView1.GetRowCellValue(i, gridColiState).ToString().Trim();

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

                        if (gridView1.GetRowCellValue(i, gridColProcessNo).ToString().Trim() == "")
                        {
                            continue;
                        }

                        Model._Process model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._Process();
                        model.ProcessNo = gridView1.GetRowCellValue(i, gridColProcessNo).ToString().Trim();
                        model.Process   = gridView1.GetRowCellValue(i, gridColProcess).ToString().Trim();
                        if (model.Process == "")
                        {
                            sErr = sErr + "Row " + (i + 1).ToString() + " error\n";
                            continue;
                        }

                        model.Condition   = gridView1.GetRowCellValue(i, gridColCondition).ToString().Trim();
                        model.PLATINGSPEC = gridView1.GetRowCellValue(i, gridColPLATINGSPEC).ToString().Trim();
                        model.TIME        = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColTIME));
                        model.THICKNESS   = gridView1.GetRowCellValue(i, gridColTHICKNESS).ToString().Trim();
                        model.AMPHRS      = gridView1.GetRowCellValue(i, gridColAMPHRS).ToString().Trim();
                        model.Remark      = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim();

                        if (iID == 0)
                        {
                            model.CreateUid  = sUserID;
                            model.CreateDate = dNowDate;

                            DAL._Process dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._Process();
                            sSQL   = dal.Add(model);
                            iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        else
                        {
                            model.CreateUid  = gridView1.GetRowCellValue(i, gridColCreateUid).ToString().Trim();
                            model.CreateDate = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridColCreateDate));
                            DAL._Process dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._Process();
                            sSQL   = dal.Update(model);
                            iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }

                    if (sErr != "")
                    {
                        throw new Exception(sErr);
                    }

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

                        MessageBox.Show("OK");

                        GetGrid();
                    }
                    else
                    {
                        throw new Exception("no data");
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #27
0
        private void btnDEL_Click(object sender, EventArgs e)
        {
            try
            {
                if (!clsUserRight.chkRight(sUserID, 3540))
                {
                    throw new Exception("没有权限");
                }


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

                if (gridView1.RowCount == 0)
                {
                    throw new Exception("no data");
                }

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    int iCou = 0;

                    string sCode = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridColcCode).ToString().Trim();
                    if (sCode == "")
                    {
                        throw new Exception("请选择需要删除的单据");
                    }

                    DialogResult d = MessageBox.Show("确定删除单据" + sCode + "?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                    if (d != DialogResult.Yes)
                    {
                        return;
                    }

                    string sSQL = "select * from _Maintenance where cCode = '111111'";
                    sSQL = sSQL.Replace("111111", sCode);
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("单据不存在");
                    }

                    if (dt.Rows[0]["AuditUserName"].ToString().Trim() != "")
                    {
                        throw new Exception("单据已审核");
                    }

                    sSQL = "update _FrockClamp set iState = 1 where SerialNo in (select SerialNo from _Maintenances where cCode = N'111111')";
                    sSQL = sSQL.Replace("111111", sCode);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    sSQL = "delete _Maintenances where cCode = '111111' ";
                    sSQL = sSQL.Replace("111111", sCode);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    sSQL = "delete _Maintenance where cCode = '111111' ";
                    sSQL = sSQL.Replace("111111", sCode);
                    iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                    if (sErr != "")
                    {
                        throw new Exception(sErr);
                    }

                    if (iCou > 0)
                    {
                        tran.Commit();
                        MessageBox.Show("OK\n");

                        GetGrid();
                    }
                    else
                    {
                        throw new Exception("no data");
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #28
0
        private void btnSave_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"));

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        string sState = gridView1.GetRowCellValue(i, gridColiState).ToString().Trim();
                        if (sState == "")
                        {
                            continue;
                        }

                        UFIDA.U8.UAP.CustomApp.ControlForm.Model._SystemSet model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._SystemSet();
                        model.cSTCode       = gridView1.GetRowCellValue(i, gridColcSTCode).ToString().Trim();
                        model.cWhCode       = gridView1.GetRowCellValue(i, gridColcWhCode).ToString().Trim();
                        model.cRdCode       = gridView1.GetRowCellValue(i, gridColcRdCode).ToString().Trim();
                        model.SAPCode       = gridView1.GetRowCellValue(i, gridColSAPCode).ToString().Trim();
                        model.SAPWorkCenter = gridView1.GetRowCellValue(i, gridColSAPWorkCenter).ToString().Trim();
                        model.InternalOrder = gridView1.GetRowCellValue(i, gridColInternalOrder).ToString().Trim();
                        model.Remark        = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim();
                        model.CreaterUid    = sUserName;
                        model.CreaterDate   = dNowDate;

                        UFIDA.U8.UAP.CustomApp.ControlForm.DAL._SystemSet dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._SystemSet();
                        sSQL = dal.Exists(model.cSTCode);
                        bool b = DbHelperSQL.Exists(tran, sSQL);

                        if (b)
                        {
                            sSQL   = dal.Update(model);
                            iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        else
                        {
                            sSQL   = dal.Add(model);
                            iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }

                    if (sErr != "")
                    {
                        throw new Exception(sErr);
                    }

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

                        MessageBox.Show("OK");

                        GetGrid();
                    }
                    else
                    {
                        throw new Exception("no data");
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #29
0
        /// <summary>
        /// 保存材料出库单扫描数量
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public int iSaveRdrecord11ChkQty(string sCode, DataTable dtBarCode, string sUid)
        {
            int iCou = 0;

            try
            {
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    decimal dQtyScanSum = 0;        //  累计扫描数量
                    for (int i = 0; i < dtBarCode.Rows.Count; i++)
                    {
                        dQtyScanSum = dQtyScanSum + ClsBaseDataInfo.ReturnObjectToDecimal(dtBarCode.Rows[i]["数量"]);
                    }

                    string    sSQL         = "select a.cCode,b.iRowNo, b.cInvCode,b.iQuantity,b.cDefine29 as 已扫描数量,b.cDefine28 as 货位,b.cDefine30 as 批号,cast(null as decimal(16,6)) as 本次扫描数量,b.autoid from RdRecord11 a inner join rdrecords11 b on a.id = b.id where a.cCode = '" + sCode + "' order by b.cInvCode";
                    DataTable dtRdRecord11 = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    bool bRed = false;
                    if (dtRdRecord11 != null && dtRdRecord11.Rows.Count > 0 && BaseClass.BaseFunction.ReturnDecimal(dtRdRecord11.Rows[0]["iQuantity"]) < 0)
                    {
                        bRed = true;
                    }

                    sSQL = "select getdate()";
                    DataTable dtTime          = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    DateTime  dtmNow          = BaseFunction.ReturnDate(dtTime.Rows[0][0]);
                    string    s_BarCodeRDCode = BaseFunction.ReturnDate(dtTime.Rows[0][0]).ToString("yyMMddHHmmss");
                    dtTime = null;

                    _BarCodeRD   DAL_BarCodeRD   = new _BarCodeRD();
                    _BarCodeList DAL_BarCodeList = new _BarCodeList();

                    #region 蓝字单据

                    if (!bRed)
                    {
                        for (int i = 0; i < dtBarCode.Rows.Count; i++)
                        {
                            string  sInvCode    = dtBarCode.Rows[i]["存货编码"].ToString().Trim();
                            decimal dQtyBarCode = BaseFunction.ReturnDecimal(dtBarCode.Rows[i]["数量"]);


                            //条形码中仅存货编码与入库单对应
                            DataRow[] drCode = dtRdRecord11.Select("cInvCode = '" + sInvCode + "'");

                            for (int j = 0; j < drCode.Length; j++)
                            {
                                if (dQtyBarCode <= 0)
                                {
                                    break;
                                }

                                decimal diQuantity = BaseFunction.ReturnDecimal(drCode[j]["iQuantity"]);
                                decimal dQtyScaned = BaseFunction.ReturnDecimal(drCode[j]["已扫描数量"]);
                                decimal dQtyNow    = BaseFunction.ReturnDecimal(drCode[j]["本次扫描数量"]);
                                decimal d          = diQuantity - dQtyScaned - dQtyNow;


                                Model._BarCodeRD model_BarCodeRD = new TH.WebService.Model._BarCodeRD();
                                model_BarCodeRD.sCode      = s_BarCodeRDCode;
                                model_BarCodeRD.BarCode    = dtBarCode.Rows[i]["条形码"].ToString().Trim();
                                model_BarCodeRD.sType      = "材料出库单";
                                model_BarCodeRD.ExsID      = BaseFunction.ReturnLong(drCode[j]["autoid"]);
                                model_BarCodeRD.ExCode     = drCode[j]["cCode"].ToString().Trim();
                                model_BarCodeRD.ExRowNo    = ClsBaseDataInfo.ReturnObjectToLong(drCode[j]["iRowNo"]);
                                model_BarCodeRD.cInvCode   = drCode[j]["cInvCode"].ToString().Trim();
                                model_BarCodeRD.CreateUid  = dtBarCode.Rows[i]["制单人"].ToString().Trim();
                                model_BarCodeRD.CreateDate = dtmNow;
                                model_BarCodeRD.XBarCode   = dtBarCode.Rows[i]["箱码"].ToString().Trim();
                                model_BarCodeRD.RDType     = 2;

                                //条形码数量超出单据数量
                                if (dQtyBarCode >= d)
                                {
                                    model_BarCodeRD.Qty = d;
                                    dQtyScanSum         = dQtyScanSum - d;

                                    drCode[j]["本次扫描数量"] = BaseFunction.ReturnDecimal(drCode[j]["本次扫描数量"]) + d;
                                    dQtyBarCode         = dQtyBarCode - d;
                                }
                                else
                                {
                                    model_BarCodeRD.Qty = dQtyBarCode;
                                    dQtyScanSum         = dQtyScanSum - dQtyBarCode;

                                    drCode[j]["本次扫描数量"] = BaseFunction.ReturnDecimal(drCode[j]["本次扫描数量"]) + dQtyBarCode;
                                    dQtyBarCode         = 0;
                                }

                                sSQL = DAL_BarCodeRD.Add(model_BarCodeRD);
                                iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                string sUpdate = "";
                                if (drCode[j]["货位"].ToString().Trim() == "" && drCode[j]["批号"].ToString().Trim() == "")
                                {
                                    sUpdate = sUpdate + ",cDefine28 = '" + dtBarCode.Rows[i]["货位"].ToString().Trim() + "'";
                                    sUpdate = sUpdate + ",cDefine30 = '" + dtBarCode.Rows[i]["批号"].ToString().Trim() + "'";
                                }

                                sSQL = "update rdrecords11 set cDefine29 = cast(isnull(cDefine29,0) as decimal(16,6)) + " + model_BarCodeRD.Qty.ToString() + " 111111 where autoid = " + model_BarCodeRD.ExsID.ToString();
                                if (sUpdate == "")
                                {
                                    sSQL = sSQL.Replace("111111", "");
                                }
                                else
                                {
                                    sSQL = sSQL.Replace("111111", sUpdate);
                                }
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);



                                //当可用量为0是,标记条形码失效
                                sSQL = DAL_BarCodeList.sBarCodeQty(model_BarCodeRD.BarCode);
                                DataTable dtQty = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                                if (dtQty != null && dtQty.Rows.Count > 0)
                                {
                                    decimal dQtyUsed = BaseFunction.ReturnDecimal(dtQty.Rows[0][0]);
                                    if (dQtyUsed <= 0)
                                    {
                                        sSQL = "update _BarCodeList set valid = 0 where BarCode = '" + model_BarCodeRD.BarCode + "'";
                                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                    #region 红字

                    else
                    {
                        for (int i = 0; i < dtBarCode.Rows.Count; i++)
                        {
                            string  sInvCode    = dtBarCode.Rows[i]["存货编码"].ToString().Trim();
                            decimal dQtyBarCode = BaseFunction.ReturnDecimal(dtBarCode.Rows[i]["数量"]);


                            //条形码中仅存货编码与入库单对应
                            DataRow[] drCode = dtRdRecord11.Select("cInvCode = '" + sInvCode + "'");

                            for (int j = 0; j < drCode.Length; j++)
                            {
                                if (dQtyBarCode >= 0)
                                {
                                    break;
                                }

                                decimal diQuantity = BaseFunction.ReturnDecimal(drCode[j]["iQuantity"]);
                                decimal dQtyScaned = BaseFunction.ReturnDecimal(drCode[j]["已扫描数量"]);
                                decimal dQtyNow    = BaseFunction.ReturnDecimal(drCode[j]["本次扫描数量"]);
                                decimal d          = diQuantity - dQtyScaned - dQtyNow;


                                Model._BarCodeRD model_BarCodeRD = new TH.WebService.Model._BarCodeRD();
                                model_BarCodeRD.sCode      = s_BarCodeRDCode;
                                model_BarCodeRD.BarCode    = dtBarCode.Rows[i]["条形码"].ToString().Trim();
                                model_BarCodeRD.sType      = "材料出库单";
                                model_BarCodeRD.ExsID      = BaseFunction.ReturnLong(drCode[j]["autoid"]);
                                model_BarCodeRD.ExCode     = drCode[j]["cCode"].ToString().Trim();
                                model_BarCodeRD.ExRowNo    = ClsBaseDataInfo.ReturnObjectToLong(drCode[j]["iRowNo"]);
                                model_BarCodeRD.cInvCode   = drCode[j]["cInvCode"].ToString().Trim();
                                model_BarCodeRD.CreateUid  = dtBarCode.Rows[i]["制单人"].ToString().Trim();
                                model_BarCodeRD.CreateDate = dtmNow;
                                model_BarCodeRD.XBarCode   = dtBarCode.Rows[i]["箱码"].ToString().Trim();
                                model_BarCodeRD.RDType     = 2;

                                //条形码数量超出单据数量
                                if (dQtyBarCode <= d)
                                {
                                    if (d >= 0)
                                    {
                                        continue;
                                    }

                                    model_BarCodeRD.Qty = d;
                                    dQtyScanSum         = dQtyScanSum - d;

                                    drCode[j]["本次扫描数量"] = BaseFunction.ReturnDecimal(drCode[j]["本次扫描数量"]) + d;
                                    dQtyBarCode         = dQtyBarCode - d;
                                }
                                else
                                {
                                    model_BarCodeRD.Qty = dQtyBarCode;
                                    dQtyScanSum         = dQtyScanSum - dQtyBarCode;

                                    drCode[j]["本次扫描数量"] = BaseFunction.ReturnDecimal(drCode[j]["本次扫描数量"]) + dQtyBarCode;
                                    dQtyBarCode         = 0;
                                }

                                sSQL = DAL_BarCodeRD.Add(model_BarCodeRD);
                                iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                string sUpdate = "";
                                if (drCode[j]["货位"].ToString().Trim() == "" && drCode[j]["批号"].ToString().Trim() == "")
                                {
                                    sUpdate = sUpdate + ",cDefine28 = '" + dtBarCode.Rows[i]["货位"].ToString().Trim() + "'";
                                    sUpdate = sUpdate + ",cDefine30 = '" + dtBarCode.Rows[i]["批号"].ToString().Trim() + "'";
                                }

                                sSQL = "update rdrecords11 set cDefine29 = cast(isnull(cDefine29,0) as decimal(16,6)) + " + model_BarCodeRD.Qty.ToString() + " 111111 where autoid = " + model_BarCodeRD.ExsID.ToString();
                                if (sUpdate == "")
                                {
                                    sSQL = sSQL.Replace("111111", "");
                                }
                                else
                                {
                                    sSQL = sSQL.Replace("111111", sUpdate);
                                }
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                sSQL = "update _BarCodeList set valid = 1 where BarCode = '" + model_BarCodeRD.BarCode + "'";
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }
                        }
                    }
                    #endregion

                    if (dQtyScanSum != 0)
                    {
                        throw new Exception("扫描数量未完全分配");
                    }
                    if (iCou == 0)
                    {
                        throw new Exception("没有语句执行");
                    }

                    #region 判断所有数量扫描后审核单据

                    sSQL = "select getdate()";
                    DataTable dTime    = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    DateTime  dTimeNow = ClsBaseDataInfo.ReturnObjectToDatetime(dTime.Rows[0][0]);
                    sSQL = @"
select case when sum(cast(isnull(b.cDefine29,0) as decimal(16,6))) <> sum(b.iQuantity) then 1 else 0 end as iCou
from rdrecord11 a inner join rdrecords11 b on a.id = b.id 
where a.cCode = '111111' 
group by a.cCode 
";
                    sSQL = sSQL.Replace("111111", sCode);
                    DataTable dtTemp2 = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtTemp2 != null && dtTemp2.Rows.Count == 1)
                    {
                        int iC = BaseFunction.ReturnInt(dtTemp2.Rows[0][0]);
                        if (iC == 0)
                        {
                            sSQL = "update rdrecord11 set cHandler = '222222',dVeriDate  = '333333',dnverifytime = getdate() where cCode = '111111'";
                            sSQL = sSQL.Replace("111111", sCode);
                            sSQL = sSQL.Replace("222222", sUid);
                            sSQL = sSQL.Replace("333333", dTimeNow.ToString("yyyy-MM-dd"));
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                            //修改现存量
                            //sSQL = "exec SP_ClearCurrentStock_ST";
                            //DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }


                    #endregion


                    tran.Commit();
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                throw new Exception(ee.Message);
            }
            return(iCou);
        }
Beispiel #30
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                if (gridView1.RowCount <= 0)
                {
                    throw new Exception("请设置数据后处理");
                }

                if (BaseFunction.ReturnDecimal(txt应摊能源费用.Text.Trim()) < 0)
                {
                    throw new Exception("请重新获得应摊能源费用");
                }
                if (BaseFunction.ReturnDecimal(txt应摊工资费用.Text.Trim()) < 0)
                {
                    throw new Exception("请重新获得应摊工资费用");
                }
                if (BaseFunction.ReturnDecimal(txt应摊制造费用.Text.Trim()) < 0)
                {
                    throw new Exception("请重新获得应摊制造费用");
                }


                decimal d1 = 0;
                decimal d2 = 0;
                decimal d3 = 0;
                for (int i = 0; i < gridView1.RowCount; i++)
                {
                    int iType = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridCol行类型));
                    if (iType == 2)
                    {
                        continue;
                    }

                    d1 = d1 + BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol应摊能源费用行));
                    d2 = d2 + BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol应摊工资费用行));
                    d3 = d3 + BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol应摊制造费用行));
                }

                txt应摊工资费用_汇总.Text = d2.ToString();
                txt应摊能源费用_汇总.Text = d1.ToString();
                txt应摊制造费用_汇总.Text = d3.ToString();

                if (BaseFunction.ReturnDecimal(txt应摊能源费用.Text.Trim()) != d1)
                {
                    throw new Exception("应摊能源费用分配不正确");
                }
                if (BaseFunction.ReturnDecimal(txt应摊工资费用.Text.Trim()) != d2)
                {
                    throw new Exception("应摊工资费用分配不正确");
                }
                if (BaseFunction.ReturnDecimal(txt应摊制造费用.Text.Trim()) != d3)
                {
                    throw new Exception("应摊制造费用分配不正确");
                }

                string        sErr = "";
                int           iCou = 0;
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string s会计期间 = lookUpEdit会计期间.EditValue.ToString().Trim();
                    if (s会计期间 == "")
                    {
                        lookUpEdit会计期间.Focus();
                        throw new Exception("会计期间不能为空");
                    }

                    string s部门 = lookUpEditcDepCode.EditValue.ToString().Trim();
                    if (s部门 == "")
                    {
                        lookUpEditcDepCode.Focus();
                        throw new Exception("部门不能为空");
                    }

                    string sSQL = "select count(1) from _费用分配 where 会计期间 = '111111' and isnull(审核人,'') <> '' and 部门编码 = '222222'";
                    sSQL = sSQL.Replace("111111", s会计期间);
                    sSQL = sSQL.Replace("222222", s部门);
                    int iCount = BaseFunction.ReturnInt(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    if (iCount > 0)
                    {
                        throw new Exception("已经审核不能修改");
                    }

                    string s下一会计期间 = BaseFunction.ReturnDate(lookUpEdit会计期间.Text.Trim() + "-01").AddMonths(1).ToString("yyyy-MM");

                    sSQL = "delete _费用分配 where 会计期间 = '111111' and 部门编码 = '222222'";
                    sSQL = sSQL.Replace("111111", s会计期间);
                    sSQL = sSQL.Replace("222222", s部门);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        if (gridView1.GetRowCellValue(i, gridCol存货编码).ToString().Trim() == "" && BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridCol行类型)) != 0)
                        {
                            continue;
                        }

                        Model._费用分配 model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._费用分配();
                        model.会计期间   = s会计期间;
                        model.部门编码   = s部门;
                        model.应摊能源费用 = BaseFunction.ReturnDecimal(txt应摊能源费用.Text.Trim());
                        model.应摊工资费用 = BaseFunction.ReturnDecimal(txt应摊工资费用.Text.Trim());
                        model.应摊制造费用 = BaseFunction.ReturnDecimal(txt应摊制造费用.Text.Trim());
                        //model.合计分摊 =

                        string s存货编码 = gridView1.GetRowCellValue(i, gridCol存货编码).ToString().Trim();
                        model.行类型 = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridCol行类型));

                        if (model.行类型 == 0)
                        {
                            s存货编码      = s存货编码.Replace("调整:", "");
                            model.存货编码 = "调整:" + s存货编码;
                        }
                        else
                        {
                            model.存货编码 = s存货编码;
                        }

                        model.生产工时    = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol生产工时));
                        model.冻干工时    = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol冻干工时));
                        model.应摊能源费用行 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol应摊能源费用行));
                        model.应摊工资费用行 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol应摊工资费用行));
                        model.应摊制造费用行 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol应摊制造费用行));
                        model.合计分摊    = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol合计分摊));


                        model.制单人  = sUserName;
                        model.制单日期 = DateTime.Now;

                        DAL._费用分配 dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._费用分配();
                        sSQL = dal.Add(model);

                        iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        //Model._QCCost modQCCost = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._QCCost();
                        //modQCCost.部门 = s部门;
                        //modQCCost.会计期间 = s下一会计期间;
                        //modQCCost.产品编码 = model.存货编码;


                        //DAL._QCCost dalQccost = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._QCCost();
                        //sSQL = dalQccost.Add(modQCCost);
                        //DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        sSQL = "update _能源分配 set 记账人 = '" + sUserName + "',记账日期 = getdate() where 会计期间 = '111111' and 部门编码 = '222222'";
                        sSQL = sSQL.Replace("111111", s会计期间);
                        sSQL = sSQL.Replace("222222", s部门);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    tran.Commit();

                    GetGrid();

                    if (iCou > 0)
                    {
                        MessageBox.Show("保存成功");
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "保存失败";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }