示例#1
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();
            }
        }
示例#2
0
        /// <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.行类型 != 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.记账日期 + "',");
            }
            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());
        }