/// <summary> /// 增加一条数据 /// </summary> public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._成本记录表 model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.单据号 != null) { strSql1.Append("单据号,"); strSql2.Append("'" + model.单据号 + "',"); } if (model.单据日期 != null) { strSql1.Append("单据日期,"); strSql2.Append("'" + model.单据日期 + "',"); } if (model.部门编码 != null) { strSql1.Append("部门编码,"); strSql2.Append("'" + model.部门编码 + "',"); } if (model.存货编码 != null) { strSql1.Append("存货编码,"); strSql2.Append("'" + model.存货编码 + "',"); } if (model.数量 != null) { strSql1.Append("数量,"); strSql2.Append("" + model.数量 + ","); } if (model.单价 != null) { strSql1.Append("单价,"); strSql2.Append("" + model.单价 + ","); } if (model.金额 != null) { strSql1.Append("金额,"); strSql2.Append("" + model.金额 + ","); } if (model.单据类型 != null) { strSql1.Append("单据类型,"); strSql2.Append("'" + model.单据类型 + "',"); } if (model.料 != null) { strSql1.Append("料,"); strSql2.Append("" + model.料 + ","); } if (model.部门分摊 != null) { strSql1.Append("部门分摊,"); strSql2.Append("" + model.部门分摊 + ","); } if (model.公用分摊 != null) { strSql1.Append("公用分摊,"); strSql2.Append("" + model.公用分摊 + ","); } if (model.计算时间 != null) { strSql1.Append("计算时间,"); strSql2.Append("'" + model.计算时间 + "',"); } if (model.产品总数 != null) { strSql1.Append("产品总数,"); strSql2.Append("" + model.产品总数 + ","); } if (model.id != null) { strSql1.Append("id,"); strSql2.Append("" + model.id + ","); } if (model.autoid != null) { strSql1.Append("autoid,"); strSql2.Append("" + model.autoid + ","); } if (model.收发类别 != null) { strSql1.Append("收发类别,"); strSql2.Append("'" + model.收发类别 + "',"); } if (model.会计期间 != null) { strSql1.Append("会计期间,"); strSql2.Append("'" + model.会计期间 + "',"); } if (model.制单人 != null) { strSql1.Append("制单人,"); strSql2.Append("'" + model.制单人 + "',"); } if (model.制单日期 != null) { strSql1.Append("制单日期,"); strSql2.Append("getdate(),"); } strSql.Append("insert into _成本记录表("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); return(strSql.ToString()); }
private void btnSave_Click(object sender, EventArgs e) { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } try { string sSQL = @" select count(*) as iCou from ( select a.cHandler ,b.cbaccounter ,a.cCode from Rdrecord10 a inner join Rdrecords10 b on a.id = b.id inner join Inventory c on b.cInvCode = c.cInvCode inner join Department d on a.cDepCode = d.cDepCode where a.cWhCode in (select sType from _CostType where iType = 4) and a.cRdCode in (select sType from _CostType where iType = 3) and a.dDAte >= '111111' and a.dDate < '222222' and isnull(b.iQuantity,0) > 0 union All select a.cHandler ,b.cbaccounter ,a.cCode from Rdrecord08 a inner join Rdrecords08 b on a.id = b.id inner join Inventory c on b.cInvCode = c.cInvCode inner join Department d on a.cDepCode = d.cDepCode where a.cWhCode in (select sType from _CostType where iType = 4) and a.cRdCode in (select sType from _CostType where iType = 3) and a.dDAte >= '111111' and a.dDate < '222222' and isnull(b.iQuantity,0) > 0 )a where isnull(a.cHandler,'') = '' or ISNULL(a.cbaccounter,'') <> '' "; sSQL = sSQL.Replace("111111", lookUpEdit会计期间.EditValue.ToString() + "-01"); sSQL = sSQL.Replace("222222", BaseFunction.ReturnDate(lookUpEdit会计期间.EditValue.ToString() + "-01").AddMonths(1).ToString("yyyy-MM-dd")); long lCou = BaseFunction.ReturnLong(DbHelperSQL.GetSingle(sSQL)); if (lCou > 0) { throw new Exception("存在未审核或者已记账单据"); } int iCou = 0; SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { sSQL = @" delete dbo._成本记录表 where 会计期间 = '111111' "; sSQL = sSQL.Replace("111111", lookUpEdit会计期间.EditValue.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); for (int i = 0; i < gridView1.RowCount; i++) { string s单据类型 = gridView1.GetRowCellValue(i, gridColRdType).ToString().Trim(); decimal d单价 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiUnitCost), 6); decimal d金额 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiPrice), 6); long lAutoid = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColautoid)); if (s单据类型 == "产成品入库") { sSQL = "update Rdrecords10 set iUnitCost = " + d单价.ToString() + ",iPrice = " + d金额 + " where autoid = " + lAutoid.ToString(); iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (s单据类型 == "其他入库") { sSQL = "update Rdrecords08 set iUnitCost = " + d单价.ToString() + ",iPrice = " + d金额 + " where autoid = " + lAutoid.ToString(); iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } Model._成本记录表 model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._成本记录表(); model.单据号 = gridView1.GetRowCellValue(i, gridColcCode).ToString().Trim(); model.单据日期 = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridColdDate)); model.部门编码 = gridView1.GetRowCellValue(i, gridColcDepCode).ToString().Trim(); model.存货编码 = gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim(); model.数量 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiQuantity), 6); model.单价 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiUnitCost), 6); model.金额 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiPrice), 6); model.单据类型 = gridView1.GetRowCellValue(i, gridColRdType).ToString().Trim(); model.料 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol料), 6); model.部门分摊 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol部门分摊), 6); model.公用分摊 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol公用分摊), 6); model.计算时间 = gridView1.GetRowCellValue(i, gridCol计算时间).ToString().Trim(); model.产品总数 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol产品总数), 6); model.id = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColid)); model.autoid = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColautoid)); model.收发类别 = gridView1.GetRowCellValue(i, gridColcRdCode).ToString().Trim(); model.会计期间 = lookUpEdit会计期间.EditValue.ToString().Trim(); model.制单人 = sUserID; model.制单日期 = DateTime.Now; DAL._成本记录表 dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._成本记录表(); sSQL = dal.Add(model); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (iCou > 0) { tran.Commit(); MessageBox.Show("保存成功"); } else { MessageBox.Show("未更新成本数据"); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }