コード例 #1
0
ファイル: ProMaterial.cs プロジェクト: chrgu000/DEMO
        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部门编码 = lookUpEditcDepCode.Text.Trim();
                    if (s部门编码 == "")
                    {
                        lookUpEditcDepCode.Focus();
                        throw new Exception("部门编码不能为空");
                    }

                    string s产品编码 = lookUpEditcInvName.Text.Trim();
                    if (s产品编码 == "")
                    {
                        lookUpEditcDepCode.Focus();
                        throw new Exception("产品编码不能为空");
                    }

                    string s会计期间 = lookUpEdit会计期间.Text.Trim();
                    if (s会计期间 == "")
                    {
                        lookUpEditcDepCode.Focus();
                        throw new Exception("会计期间不能为空");
                    }

                    if (txtWorkTime.Text.Trim() == "")
                    {
                        txtWorkTime.Focus();
                        throw new Exception("产品工时不能为空");
                    }

                    decimal d工时 = BaseFunction.ReturnDecimal(txtWorkTime.Text.Trim());
                    if (d工时 < 0)
                    {
                        txtWorkTime.Focus();
                        throw new Exception("产品工时不能小于0");
                    }


                    string sSQL = @"
select * 
from    _ProMaterial
where 1=1
ORDER BY iID
";
                    sSQL = sSQL.Replace("1=1", "1=1 and 会计期间 = '" + lookUpEdit会计期间.Text.Trim() + "' and 部门 = '" + s部门编码 + "' and 产品编码 = '" + s产品编码 + "' ");
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null)
                    {
                        throw new Exception("获得数据失败");
                    }

                    if (dt.Rows.Count > 0 && dt.Rows[0]["审核人"].ToString().Trim() != "")
                    {
                        throw new Exception("已经审核不能修改");
                    }

                    Model._ProMaterial model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._ProMaterial();
                    model.部门 = lookUpEditcDepCode.EditValue.ToString().Trim();

                    string sInvCode = lookUpEditcInvName.EditValue.ToString().Trim();
                    sSQL = "select * from Inventory where cInvCode = '" + sInvCode + "'";
                    DataTable dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtTemp == null || dtTemp.Rows.Count != 1)
                    {
                        sErr = sErr + " 产品存货编码不存在";
                    }
                    model.产品编码 = sInvCode;
                    model.会计期间 = lookUpEdit会计期间.EditValue.ToString().Trim();

                    UFIDA.U8.UAP.CustomApp.ControlForm.DAL._ProMaterial DAL = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._ProMaterial();
                    sSQL = DAL.Delete(model);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    bool b子件已登记 = false;
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        if (gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim() == "")
                        {
                            continue;
                        }

                        model         = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._ProMaterial();
                        model.部门      = lookUpEditcDepCode.EditValue.ToString().Trim();
                        model.产品编码    = lookUpEditcInvName.EditValue.ToString().Trim();
                        model.会计期间    = lookUpEdit会计期间.EditValue.ToString().Trim();
                        model.工时      = BaseFunction.ReturnDecimal(txtWorkTime.Text.Trim(), 1);
                        model.未完工工时   = BaseFunction.ReturnDecimal(txtWorkTimeUn.Text.Trim(), 1);
                        model.冻干完工工时  = BaseFunction.ReturnDecimal(txtDGTime.Text.Trim(), 1);
                        model.冻干未完工工时 = BaseFunction.ReturnDecimal(txtDGUTime.Text.Trim(), 1);

                        string scInvCode = gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim();
                        sSQL   = "select * from Inventory where cInvCode = '" + scInvCode + "'";
                        dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dtTemp == null || dtTemp.Rows.Count != 1)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + " 存货编码不存在";
                        }

                        model.存货编码 = scInvCode;
                        model.数量   = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol数量), 6);
                        if (model.数量 == 0)
                        {
                            continue;
                        }

                        b子件已登记 = true;

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

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

                    if (!b子件已登记)
                    {
                        sErr = sErr + "数量必须不为0\n";
                    }

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

                    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();
            }
        }
コード例 #2
0
ファイル: ProMaterial.cs プロジェクト: chrgu000/DEMO
        private void btnDel_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

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

                int           iCou = 0;
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string s部门编码 = lookUpEditcDepCode.Text.Trim();
                    if (s部门编码 == "")
                    {
                        lookUpEditcDepCode.Focus();
                        throw new Exception("部门编码不能为空");
                    }

                    string s产品编码 = lookUpEditcInvName.EditValue.ToString().Trim();
                    if (s产品编码 == "")
                    {
                        lookUpEditcDepCode.Focus();
                        throw new Exception("产品编码不能为空");
                    }

                    string s产品名称 = lookUpEditcInvName.Text.Trim();
                    if (s产品名称 == "")
                    {
                        lookUpEditcDepCode.Focus();
                        throw new Exception("产品名称不能为空");
                    }

                    string s会计期间 = lookUpEdit会计期间.Text.Trim();
                    if (s会计期间 == "")
                    {
                        lookUpEditcDepCode.Focus();
                        throw new Exception("会计期间不能为空");
                    }


                    string sSQL = @"
select * 
from    _ProMaterial
where 1=1
ORDER BY iID
";
                    sSQL = sSQL.Replace("1=1", "1=1 and 会计期间 = '" + lookUpEdit会计期间.Text.Trim() + "' and 部门 = '" + s部门编码 + "' and 产品编码 = '" + s产品编码 + "' ");
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("获得数据失败");
                    }

                    if (dt.Rows[0]["审核人"].ToString().Trim() != "")
                    {
                        throw new Exception("已经审核不能删除");
                    }

                    Model._ProMaterial model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._ProMaterial();
                    model.部门   = lookUpEditcDepCode.EditValue.ToString().Trim();
                    model.产品编码 = lookUpEditcInvName.EditValue.ToString().Trim();
                    model.会计期间 = lookUpEdit会计期间.EditValue.ToString().Trim();

                    UFIDA.U8.UAP.CustomApp.ControlForm.DAL._ProMaterial DAL = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._ProMaterial();
                    sSQL = DAL.Delete(model);
                    iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    tran.Commit();

                    MessageBox.Show("删除成功");

                    GetGrid();
                }
                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();
            }
        }