Example #1
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();
            }
        }
Example #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.iperiod != null)
            {
                strSql1.Append("iperiod,");
                strSql2.Append("" + model.iperiod + ",");
            }
            if (model.csign != null)
            {
                strSql1.Append("csign,");
                strSql2.Append("'" + model.csign + "',");
            }
            if (model.isignseq != null)
            {
                strSql1.Append("isignseq,");
                strSql2.Append("" + model.isignseq + ",");
            }
            if (model.ino_id != null)
            {
                strSql1.Append("ino_id,");
                strSql2.Append("" + model.ino_id + ",");
            }
            if (model.inid != null)
            {
                strSql1.Append("inid,");
                strSql2.Append("" + model.inid + ",");
            }
            if (model.dbill_date != null)
            {
                strSql1.Append("dbill_date,");
                strSql2.Append("'" + model.dbill_date + "',");
            }
            if (model.idoc != null)
            {
                strSql1.Append("idoc,");
                strSql2.Append("" + model.idoc + ",");
            }
            if (model.cbill != null)
            {
                strSql1.Append("cbill,");
                strSql2.Append("'" + model.cbill + "',");
            }
            if (model.ccheck != null)
            {
                strSql1.Append("ccheck,");
                strSql2.Append("'" + model.ccheck + "',");
            }
            if (model.cbook != null)
            {
                strSql1.Append("cbook,");
                strSql2.Append("'" + model.cbook + "',");
            }
            if (model.ibook != null)
            {
                strSql1.Append("ibook,");
                strSql2.Append("" + model.ibook + ",");
            }
            if (model.ccashier != null)
            {
                strSql1.Append("ccashier,");
                strSql2.Append("'" + model.ccashier + "',");
            }
            if (model.iflag != null)
            {
                strSql1.Append("iflag,");
                strSql2.Append("" + model.iflag + ",");
            }
            if (model.ctext1 != null)
            {
                strSql1.Append("ctext1,");
                strSql2.Append("'" + model.ctext1 + "',");
            }
            if (model.ctext2 != null)
            {
                strSql1.Append("ctext2,");
                strSql2.Append("'" + model.ctext2 + "',");
            }
            if (model.cdigest != null)
            {
                strSql1.Append("cdigest,");
                strSql2.Append("'" + model.cdigest + "',");
            }
            if (model.ccode != null)
            {
                strSql1.Append("ccode,");
                strSql2.Append("'" + model.ccode + "',");
            }
            if (model.cexch_name != null)
            {
                strSql1.Append("cexch_name,");
                strSql2.Append("'" + model.cexch_name + "',");
            }
            if (model.md != null)
            {
                strSql1.Append("md,");
                strSql2.Append("" + model.md + ",");
            }
            if (model.mc != null)
            {
                strSql1.Append("mc,");
                strSql2.Append("" + model.mc + ",");
            }
            if (model.md_f != null)
            {
                strSql1.Append("md_f,");
                strSql2.Append("" + model.md_f + ",");
            }
            if (model.mc_f != null)
            {
                strSql1.Append("mc_f,");
                strSql2.Append("" + model.mc_f + ",");
            }
            if (model.nfrat != null)
            {
                strSql1.Append("nfrat,");
                strSql2.Append("" + model.nfrat + ",");
            }
            if (model.nd_s != null)
            {
                strSql1.Append("nd_s,");
                strSql2.Append("" + model.nd_s + ",");
            }
            if (model.nc_s != null)
            {
                strSql1.Append("nc_s,");
                strSql2.Append("" + model.nc_s + ",");
            }
            if (model.csettle != null)
            {
                strSql1.Append("csettle,");
                strSql2.Append("'" + model.csettle + "',");
            }
            if (model.cn_id != null)
            {
                strSql1.Append("cn_id,");
                strSql2.Append("'" + model.cn_id + "',");
            }
            if (model.dt_date != null)
            {
                strSql1.Append("dt_date,");
                strSql2.Append("'" + model.dt_date + "',");
            }
            if (model.cdept_id != null)
            {
                strSql1.Append("cdept_id,");
                strSql2.Append("'" + model.cdept_id + "',");
            }
            if (model.cperson_id != null)
            {
                strSql1.Append("cperson_id,");
                strSql2.Append("'" + model.cperson_id + "',");
            }
            if (model.ccus_id != null)
            {
                strSql1.Append("ccus_id,");
                strSql2.Append("'" + model.ccus_id + "',");
            }
            if (model.csup_id != null)
            {
                strSql1.Append("csup_id,");
                strSql2.Append("'" + model.csup_id + "',");
            }
            if (model.citem_id != null)
            {
                strSql1.Append("citem_id,");
                strSql2.Append("'" + model.citem_id + "',");
            }
            if (model.citem_class != null)
            {
                strSql1.Append("citem_class,");
                strSql2.Append("'" + model.citem_class + "',");
            }
            if (model.cname != null)
            {
                strSql1.Append("cname,");
                strSql2.Append("'" + model.cname + "',");
            }
            if (model.ccode_equal != null)
            {
                strSql1.Append("ccode_equal,");
                strSql2.Append("'" + model.ccode_equal + "',");
            }
            if (model.iflagbank != null)
            {
                strSql1.Append("iflagbank,");
                strSql2.Append("" + model.iflagbank + ",");
            }
            if (model.iflagPerson != null)
            {
                strSql1.Append("iflagPerson,");
                strSql2.Append("" + model.iflagPerson + ",");
            }
            if (model.bdelete != null)
            {
                strSql1.Append("bdelete,");
                strSql2.Append("" + (model.bdelete ? 1 : 0) + ",");
            }
            if (model.coutaccset != null)
            {
                strSql1.Append("coutaccset,");
                strSql2.Append("'" + model.coutaccset + "',");
            }
            if (model.ioutyear != null)
            {
                strSql1.Append("ioutyear,");
                strSql2.Append("" + model.ioutyear + ",");
            }
            if (model.coutsysname != null)
            {
                strSql1.Append("coutsysname,");
                strSql2.Append("'" + model.coutsysname + "',");
            }
            if (model.coutsysver != null)
            {
                strSql1.Append("coutsysver,");
                strSql2.Append("'" + model.coutsysver + "',");
            }
            if (model.doutbilldate != null)
            {
                strSql1.Append("doutbilldate,");
                strSql2.Append("'" + model.doutbilldate + "',");
            }
            if (model.ioutperiod != null)
            {
                strSql1.Append("ioutperiod,");
                strSql2.Append("" + model.ioutperiod + ",");
            }
            if (model.coutsign != null)
            {
                strSql1.Append("coutsign,");
                strSql2.Append("'" + model.coutsign + "',");
            }
            if (model.coutno_id != null)
            {
                strSql1.Append("coutno_id,");
                strSql2.Append("'" + model.coutno_id + "',");
            }
            if (model.doutdate != null)
            {
                strSql1.Append("doutdate,");
                strSql2.Append("'" + model.doutdate + "',");
            }
            if (model.coutbillsign != null)
            {
                strSql1.Append("coutbillsign,");
                strSql2.Append("'" + model.coutbillsign + "',");
            }
            if (model.coutid != null)
            {
                strSql1.Append("coutid,");
                strSql2.Append("'" + model.coutid + "',");
            }
            if (model.bvouchedit != null)
            {
                strSql1.Append("bvouchedit,");
                strSql2.Append("" + (model.bvouchedit ? 1 : 0) + ",");
            }
            if (model.bvouchAddordele != null)
            {
                strSql1.Append("bvouchAddordele,");
                strSql2.Append("" + (model.bvouchAddordele ? 1 : 0) + ",");
            }
            if (model.bvouchmoneyhold != null)
            {
                strSql1.Append("bvouchmoneyhold,");
                strSql2.Append("" + (model.bvouchmoneyhold ? 1 : 0) + ",");
            }
            if (model.bvalueedit != null)
            {
                strSql1.Append("bvalueedit,");
                strSql2.Append("" + (model.bvalueedit ? 1 : 0) + ",");
            }
            if (model.bcodeedit != null)
            {
                strSql1.Append("bcodeedit,");
                strSql2.Append("" + (model.bcodeedit ? 1 : 0) + ",");
            }
            if (model.ccodecontrol != null)
            {
                strSql1.Append("ccodecontrol,");
                strSql2.Append("'" + model.ccodecontrol + "',");
            }
            if (model.bPCSedit != null)
            {
                strSql1.Append("bPCSedit,");
                strSql2.Append("" + (model.bPCSedit ? 1 : 0) + ",");
            }
            if (model.bDeptedit != null)
            {
                strSql1.Append("bDeptedit,");
                strSql2.Append("" + (model.bDeptedit ? 1 : 0) + ",");
            }
            if (model.bItemedit != null)
            {
                strSql1.Append("bItemedit,");
                strSql2.Append("" + (model.bItemedit ? 1 : 0) + ",");
            }
            if (model.bCusSupInput != null)
            {
                strSql1.Append("bCusSupInput,");
                strSql2.Append("" + (model.bCusSupInput ? 1 : 0) + ",");
            }
            if (model.cDefine1 != null)
            {
                strSql1.Append("cDefine1,");
                strSql2.Append("'" + model.cDefine1 + "',");
            }
            if (model.cDefine2 != null)
            {
                strSql1.Append("cDefine2,");
                strSql2.Append("'" + model.cDefine2 + "',");
            }
            if (model.cDefine3 != null)
            {
                strSql1.Append("cDefine3,");
                strSql2.Append("'" + model.cDefine3 + "',");
            }
            if (model.cDefine4 != null)
            {
                strSql1.Append("cDefine4,");
                strSql2.Append("'" + model.cDefine4 + "',");
            }
            if (model.cDefine5 != null)
            {
                strSql1.Append("cDefine5,");
                strSql2.Append("" + model.cDefine5 + ",");
            }
            if (model.cDefine6 != null)
            {
                strSql1.Append("cDefine6,");
                strSql2.Append("'" + model.cDefine6 + "',");
            }
            if (model.cDefine7 != null)
            {
                strSql1.Append("cDefine7,");
                strSql2.Append("" + model.cDefine7 + ",");
            }
            if (model.cDefine8 != null)
            {
                strSql1.Append("cDefine8,");
                strSql2.Append("'" + model.cDefine8 + "',");
            }
            if (model.cDefine9 != null)
            {
                strSql1.Append("cDefine9,");
                strSql2.Append("'" + model.cDefine9 + "',");
            }
            if (model.cDefine10 != null)
            {
                strSql1.Append("cDefine10,");
                strSql2.Append("'" + model.cDefine10 + "',");
            }
            if (model.cDefine11 != null)
            {
                strSql1.Append("cDefine11,");
                strSql2.Append("'" + model.cDefine11 + "',");
            }
            if (model.cDefine12 != null)
            {
                strSql1.Append("cDefine12,");
                strSql2.Append("'" + model.cDefine12 + "',");
            }
            if (model.cDefine13 != null)
            {
                strSql1.Append("cDefine13,");
                strSql2.Append("'" + model.cDefine13 + "',");
            }
            if (model.cDefine14 != null)
            {
                strSql1.Append("cDefine14,");
                strSql2.Append("'" + model.cDefine14 + "',");
            }
            if (model.cDefine15 != null)
            {
                strSql1.Append("cDefine15,");
                strSql2.Append("" + model.cDefine15 + ",");
            }
            if (model.cDefine16 != null)
            {
                strSql1.Append("cDefine16,");
                strSql2.Append("" + model.cDefine16 + ",");
            }
            if (model.dReceive != null)
            {
                strSql1.Append("dReceive,");
                strSql2.Append("'" + model.dReceive + "',");
            }
            if (model.cWLDZFlag != null)
            {
                strSql1.Append("cWLDZFlag,");
                strSql2.Append("'" + model.cWLDZFlag + "',");
            }
            if (model.dWLDZTime != null)
            {
                strSql1.Append("dWLDZTime,");
                strSql2.Append("'" + model.dWLDZTime + "',");
            }
            if (model.bFlagOut != null)
            {
                strSql1.Append("bFlagOut,");
                strSql2.Append("" + (model.bFlagOut ? 1 : 0) + ",");
            }
            if (model.iBG_OverFlag != null)
            {
                strSql1.Append("iBG_OverFlag,");
                strSql2.Append("" + model.iBG_OverFlag + ",");
            }
            if (model.cBG_Auditor != null)
            {
                strSql1.Append("cBG_Auditor,");
                strSql2.Append("'" + model.cBG_Auditor + "',");
            }
            if (model.dBG_AuditTime != null)
            {
                strSql1.Append("dBG_AuditTime,");
                strSql2.Append("'" + model.dBG_AuditTime + "',");
            }
            if (model.cBG_AuditOpinion != null)
            {
                strSql1.Append("cBG_AuditOpinion,");
                strSql2.Append("'" + model.cBG_AuditOpinion + "',");
            }
            if (model.bWH_BgFlag != null)
            {
                //strSql1.Append("bWH_BgFlag,");
                //strSql2.Append("" + (model.bWH_BgFlag ? 1 : 0) + ",");
            }
            if (model.ssxznum != null)
            {
                strSql1.Append("ssxznum,");
                strSql2.Append("" + model.ssxznum + ",");
            }
            if (model.CErrReason != null)
            {
                strSql1.Append("CErrReason,");
                strSql2.Append("'" + model.CErrReason + "',");
            }
            if (model.BG_AuditRemark != null)
            {
                strSql1.Append("BG_AuditRemark,");
                strSql2.Append("'" + model.BG_AuditRemark + "',");
            }
            if (model.cBudgetBuffer != null)
            {
                strSql1.Append("cBudgetBuffer,");
                strSql2.Append("'" + model.cBudgetBuffer + "',");
            }
            if (model.iBG_ControlResult != null)
            {
                strSql1.Append("iBG_ControlResult,");
                strSql2.Append("" + model.iBG_ControlResult + ",");
            }
            if (model.NCVouchID != null)
            {
                strSql1.Append("NCVouchID,");
                strSql2.Append("'" + model.NCVouchID + "',");
            }
            if (model.daudit_date != null)
            {
                strSql1.Append("daudit_date,");
                strSql2.Append("'" + model.daudit_date + "',");
            }
            if (model.RowGuid != null)
            {
                strSql1.Append("RowGuid,");
                strSql2.Append("'" + model.RowGuid + "',");
            }
            if (model.cBankReconNo != null)
            {
                strSql1.Append("cBankReconNo,");
                strSql2.Append("'" + model.cBankReconNo + "',");
            }
            if (model.iyear != null)
            {
                strSql1.Append("iyear,");
                strSql2.Append("" + model.iyear + ",");
            }
            if (model.iYPeriod != null)
            {
                strSql1.Append("iYPeriod,");
                strSql2.Append("" + model.iYPeriod + ",");
            }
            if (model.wllqDate != null)
            {
                strSql1.Append("wllqDate,");
                strSql2.Append("'" + model.wllqDate + "',");
            }
            if (model.wllqPeriod != null)
            {
                strSql1.Append("wllqPeriod,");
                strSql2.Append("" + model.wllqPeriod + ",");
            }
            if (model.tvouchtime != null)
            {
                strSql1.Append("tvouchtime,");
                strSql2.Append("'" + model.tvouchtime + "',");
            }
            if (model.cblueoutno_id != null)
            {
                strSql1.Append("cblueoutno_id,");
                strSql2.Append("'" + model.cblueoutno_id + "',");
            }
            if (model.ccodeexch_equal != null)
            {
                strSql1.Append("ccodeexch_equal,");
                strSql2.Append("'" + model.ccodeexch_equal + "',");
            }
            strSql.Append("insert into GL_accvouch(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            return(strSql.ToString());
        }
Example #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string[] s       = lookUpEditPeriod.Text.Trim().Split('.');
                int      iYear   = BaseFunction.ReturnInt(s[0]);
                int      iPeriod = BaseFunction.ReturnInt(s[1]);

                string        sVoucher = "";
                string        sErr     = "";
                int           iCount   = 0;
                SqlConnection conn     = new SqlConnection(Conn);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();

                try
                {
                    string sSQL = "SELECT * FROM dbo.GL_mend WHERE iyear = aaaaaa AND iperiod = bbbbbb";
                    sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                    sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Failed to obtain module status");
                    }
                    if (BaseFunction.ReturnBool(dt.Rows[0]["bflag"]))
                    {
                        throw new Exception("General ledger");
                    }

                    string sino_id = "";
                    long   i_id    = -1;

                    sSQL = @"
select bflag from gl_mend where iyear = aaaaaa and iperiod = bbbbbb
";
                    sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                    sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                    DataTable dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (BaseFunction.ReturnBool(dtTemp.Rows[0]["bflag"]))
                    {
                        throw new Exception("The current date has been checked out");
                    }

                    sSQL = @"
select * 
from _AmountOfExchangeProfitAndLoss
where iyear = aaaaaa and iperiod = bbbbbb
";
                    sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                    sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        if (DialogResult.Yes != MessageBox.Show("The document has been generated. Will it continue?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk))
                        {
                            throw new Exception("User cancelled");
                        }

                        i_id = BaseFunction.ReturnLong(dt.Rows[0]["i_id"]);

                        sSQL = @"
delete _AmountOfExchangeProfitAndLoss where iyear = aaaaaa and iperiod = bbbbbb
";
                        sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                        sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    if (sino_id != "")
                    {
                        sSQL = @"
select *
from GL_accvouch 
where csign = 'AP' and iyear = aaaaaa and iperiod = bbbbbb and ino_id = 'cccccc' and isnull(iflag,0) = 0 and i_id = 'dddddd'
";
                        sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                        sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                        sSQL = sSQL.Replace("cccccc", sino_id);
                        sSQL = sSQL.Replace("dddddd", i_id.ToString());
                        dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        if (dt != null && dt.Rows.Count > 0)
                        {
                            throw new Exception("Accounting vouchers already exist");
                        }
                    }

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        Model._AmountOfExchangeProfitAndLoss mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._AmountOfExchangeProfitAndLoss();
                        mod.iYear      = iYear;
                        mod.iPeriod    = iPeriod;
                        mod.AutoID     = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColAutoID));
                        mod.cCode      = gridView1.GetRowCellValue(i, gridColcCode).ToString().Trim();
                        mod.irowno     = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColirowno));
                        mod.cExch_Name = gridView1.GetRowCellValue(i, gridColcExch_Name).ToString().Trim();
                        mod.dDate      = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridColdDate));

                        mod.cInvCode = gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim();
                        mod.cInvName = gridView1.GetRowCellValue(i, gridColcInvName).ToString().Trim();
                        mod.cInvStd  = gridView1.GetRowCellValue(i, gridColcInvStd).ToString().Trim();
                        mod.iOriSum  = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiOriSum));
                        mod.nflat    = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColnflat));
                        mod.nflat2   = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColnflat2));
                        mod.AmountOfExchangeProfitAndLoss = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColAmountOfExchangeProfitAndLoss));
                        mod.i_ID    = -1;
                        mod.redi_ID = -1;

                        if (mod.nflat == 0 || mod.nflat2 == 0)
                        {
                            throw new Exception("Please set exchange rate");
                        }

                        DAL._AmountOfExchangeProfitAndLoss dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._AmountOfExchangeProfitAndLoss();
                        sSQL = dal.Add(mod);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    if (MessageBox.Show("Whether to generate accounting vouchers?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                    {
                        sSQL = @"
select * from _Code where VouchType = 'Exchange gain or loss'
";
                        dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dt == null || dt.Rows.Count == 0)
                        {
                            throw new Exception("Please set aounting subject [_Code.Exchange gain or loss]");
                        }
                        string sKMD = dt.Rows[0]["Debtor"].ToString().Trim();
                        string sKMC = dt.Rows[0]["Creditor"].ToString().Trim();
                        string sZY  = dt.Rows[0]["Remark"].ToString().Trim();
                        if (sKMD == "" || sKMC == "")
                        {
                            throw new Exception("Please set aounting subject [_Code.Exchange gain or loss]");
                        }
                        sSQL = @"
select sum(AmountOfExchangeProfitAndLoss) as AmountOfExchangeProfitAndLoss ,rd.cVenCode
from _AmountOfExchangeProfitAndLoss a
	left join RdRecord01 rd on a.cCode = rd.cCode
where a.iyear = aaaaaa and a.iperiod = bbbbbb
group by rd.cVenCode
";
                        sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                        sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                        DataTable dtSum = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dtSum == null || dtSum.Rows.Count == 0)
                        {
                            throw new Exception("No data");
                        }

                        sSQL = "select isnull(max(ino_id),0)  from GL_accvouch where iyear = aaaaaa AND iperiod = bbbbbb and csign = 'AP'";
                        sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                        sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                        DataTable dtinoid = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        int       ino_id  = BaseFunction.ReturnInt(dtinoid.Rows[0][0]) + 1;

                        decimal dSum = 0;

                        #region 生成凭证
                        sVoucher = sVoucher + "AP-" + ino_id.ToString().PadLeft(4, '0') + "\n";

                        #region 借方
                        for (int i = 0; i < dtSum.Rows.Count; i++)
                        {
                            decimal dMoney = BaseFunction.ReturnDecimal(dtSum.Rows[i]["AmountOfExchangeProfitAndLoss"], 2);
                            dSum = dSum + dMoney;
                        }

                        Model.GL_accvouch model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
                        model.iperiod    = iPeriod;
                        model.csign      = "AP";
                        model.isignseq   = 2;
                        model.ino_id     = ino_id;
                        model.inid       = 1;
                        model.dbill_date = BaseFunction.ReturnDate(sLogDate);
                        model.idoc       = -1;
                        model.cbill      = sUserName;
                        model.ibook      = 0;
                        model.cdigest    = sZY;
                        model.ccode      = sKMD;
                        //model.cDefine1 = sDocment2;
                        model.md    = dSum;
                        model.mc    = 0;
                        model.md_f  = 0;
                        model.mc_f  = 0;
                        model.nfrat = 0;
                        model.nd_s  = 0;
                        model.nc_s  = 0;
                        //model.csettle = "";     //结算方式
                        //model.cn_id
                        //model.dt_date =

                        model.ccode_equal = sKMC;;
                        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        = BaseFunction.ReturnInt(BaseFunction.ReturnDate(iYear.ToString() + "-" + iPeriod.ToString() + "-01").ToString("yyyyMM"));
                        model.tvouchtime      = DateTime.Now;
                        model.ccodeexch_equal = sKMC;

                        model.csup_id = dtSum.Rows[0]["cVenCode"].ToString().Trim();

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

                        for (int i = 0; i < dtSum.Rows.Count; i++)
                        {
                            #region 贷方
                            model            = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
                            model.iperiod    = iPeriod;
                            model.csign      = "AP";
                            model.isignseq   = 2;
                            model.ino_id     = ino_id;
                            model.inid       = 2;
                            model.dbill_date = BaseFunction.ReturnDate(sLogDate);
                            model.idoc       = -1;
                            model.cbill      = sUserName;
                            model.ibook      = 0;
                            model.cdigest    = sZY;
                            model.ccode      = sKMC;
                            //model.cDefine1 = sDocment2;
                            model.md    = 0;
                            model.mc    = BaseFunction.ReturnDecimal(dtSum.Rows[i]["AmountOfExchangeProfitAndLoss"], 2);
                            model.md_f  = 0;
                            model.mc_f  = 0;
                            model.nfrat = 0;
                            model.nd_s  = 0;
                            model.nc_s  = 0;
                            //model.csettle = "";     //结算方式
                            //model.cn_id
                            //model.dt_date =

                            model.ccode_equal     = sKMD;;
                            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        = BaseFunction.ReturnInt(BaseFunction.ReturnDate(iYear.ToString() + "-" + iPeriod.ToString() + "-01").ToString("yyyyMM"));
                            model.tvouchtime      = DateTime.Now;
                            model.ccodeexch_equal = sKMD;

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

                        #endregion

                        sSQL   = @"
select i_id from GL_accvouch where iyear = {0} and iperiod = {1} and csign = '{2}' and ino_id = {3}
";
                        sSQL   = string.Format(sSQL, model.iyear, model.iperiod, model.csign, model.ino_id);
                        dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        i_id   = BaseFunction.ReturnLong(dtTemp.Rows[0]["i_id"]);

                        sSQL = @"
update _AmountOfExchangeProfitAndLoss set csign = 'AP',i_id = 'dddddddd',ino_id = 'eeeeee'
where  iyear = bbbbbbbb and iperiod = cccccccc
";
                        sSQL = sSQL.Replace("bbbbbbbb", model.iyear.ToString());
                        sSQL = sSQL.Replace("cccccccc", model.iperiod.ToString());
                        sSQL = sSQL.Replace("dddddddd", i_id.ToString().Trim());
                        sSQL = sSQL.Replace("eeeeee", model.ino_id.ToString().Trim());
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }
                    tran.Commit();

                    MessageBox.Show("Sucess\n" + sVoucher);


                    label1.Text             = "";
                    gridControl1.DataSource = null;
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "Err";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Example #4
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("请加载数据");
                }

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    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("总账已结账");
                    }

                    int iCount = 0;

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        bool b = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColbChoose));
                        if (!b)
                        {
                            continue;
                        }

                        //int i_id_from = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColi_id));

                        string scsign = gridView1.GetRowCellValue(i, gridColcsign).ToString().Trim();
                        int    ino_id = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColino_id));
                        sSQL = "select * from {4}..GL_accvouch where csign = '{0}' and ino_id = '{1}' and iyear = {2} and iPeriod = {3} ";
                        sSQL = string.Format(sSQL, scsign, ino_id, iYear, iMonth, sDataFrom);
                        DataTable dtGL_accvouch = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        for (int j = 0; j < dtGL_accvouch.Rows.Count; j++)
                        {
                            //  , , , , , ccheck, cbook, ibook, ccashier, iflag, ,
                            //iBG_OverFlag, cBG_Auditor, dBG_AuditTime, cBG_AuditOpinion, bWH_BgFlag, ssxznum, CErrReason, BG_AuditRemark,
                            //cBudgetBuffer, iBG_ControlResult, NCVouchID, daudit_date, RowGuid, cBankReconNo, , , wllqDate,
                            //wllqPeriod, tvouchtime, cblueoutno_id,

                            Model.GL_accvouch mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
                            mod.iperiod    = BaseFunction.ReturnInt(dtGL_accvouch.Rows[j]["iperiod"]);
                            mod.csign      = dtGL_accvouch.Rows[j]["csign"].ToString().Trim();
                            mod.isignseq   = BaseFunction.ReturnInt(dtGL_accvouch.Rows[j]["isignseq"]);
                            mod.ino_id     = BaseFunction.ReturnInt(dtGL_accvouch.Rows[j]["ino_id"]);
                            mod.inid       = BaseFunction.ReturnInt(dtGL_accvouch.Rows[j]["inid"]);
                            mod.dbill_date = BaseFunction.ReturnDate(dtGL_accvouch.Rows[j]["dbill_date"]);
                            mod.idoc       = BaseFunction.ReturnInt(dtGL_accvouch.Rows[j]["idoc"]);
                            mod.cbill      = dtGL_accvouch.Rows[j]["cbill"].ToString().Trim();
                            mod.ibook      = 0;
                            mod.iflag      = BaseFunction.ReturnInt(dtGL_accvouch.Rows[j]["iflag"]);
                            mod.ctext1     = dtGL_accvouch.Rows[j]["ctext1"].ToString().Trim();
                            mod.ctext2     = dtGL_accvouch.Rows[j]["ctext2"].ToString().Trim();
                            mod.cdigest    = dtGL_accvouch.Rows[j]["cdigest"].ToString().Trim();
                            mod.ccode      = dtGL_accvouch.Rows[j]["ccode"].ToString().Trim();

                            sSQL = @"
SELECT cast(0 as bit) as choose,b.iID
    ,a.ccode as 会计科目,a.ccode_name, b.对照科目,'edit' as iSave,b.Remark 
FROM code a LEFT JOIN [_科目对照] b ON a.ccode = b.会计科目
WHERE ISNULL(bend ,0) = 1 and a.iyear = {0} and b.对照科目 = '{1}'
ORDER BY a.ccode,b.iID
";
                            sSQL = string.Format(sSQL, iYear, mod.ccode);
                            DataTable dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                            if (dtCode == null || dtCode.Rows.Count == 0)
                            {
                                throw new Exception("请设置科目对照:" + mod.ccode);
                            }
                            mod.ccode           = dtCode.Rows[0]["会计科目"].ToString().Trim();
                            mod.cexch_name      = dtGL_accvouch.Rows[j]["cexch_name"].ToString().Trim();
                            mod.md              = BaseFunction.ReturnDecimal(dtGL_accvouch.Rows[j]["md"]);
                            mod.mc              = BaseFunction.ReturnDecimal(dtGL_accvouch.Rows[j]["mc"]);
                            mod.md_f            = BaseFunction.ReturnDecimal(dtGL_accvouch.Rows[j]["md_f"]);
                            mod.mc_f            = BaseFunction.ReturnDecimal(dtGL_accvouch.Rows[j]["mc_f"]);
                            mod.nfrat           = BaseFunction.ReturnDecimal(dtGL_accvouch.Rows[j]["nfrat"]);
                            mod.nd_s            = BaseFunction.ReturnDecimal(dtGL_accvouch.Rows[j]["nd_s"]);
                            mod.nc_s            = BaseFunction.ReturnDecimal(dtGL_accvouch.Rows[j]["nc_s"]);
                            mod.csettle         = dtGL_accvouch.Rows[j]["csettle"].ToString().Trim();
                            mod.cn_id           = dtGL_accvouch.Rows[j]["cn_id"].ToString().Trim();
                            mod.dt_date         = BaseFunction.ReturnDate(dtGL_accvouch.Rows[j]["dt_date"]);
                            mod.iyear           = BaseFunction.ReturnInt(dtGL_accvouch.Rows[j]["iyear"]);
                            mod.iYPeriod        = BaseFunction.ReturnInt(dtGL_accvouch.Rows[j]["iYPeriod"]);
                            mod.cDefine15       = BaseFunction.ReturnInt(dtGL_accvouch.Rows[j]["i_id"]);
                            mod.ccodeexch_equal = dtGL_accvouch.Rows[j]["ccodeexch_equal"].ToString().Trim();
                            mod.ccode_equal     = dtGL_accvouch.Rows[j]["ccode_equal"].ToString().Trim();

                            //, , , , , , , , , , , , , , cdept_id, cperson_id,
                            //ccus_id, csup_id, citem_id, citem_class, cname, , iflagbank, iflagPerson, bdelete, coutaccset, ioutyear,
                            //coutsysname, coutsysver, doutbilldate, ioutperiod, coutsign, coutno_id, doutdate, coutbillsign, coutid, bvouchedit,
                            //bvouchAddordele, bvouchmoneyhold, bvalueedit, bcodeedit, ccodecontrol, bPCSedit, bDeptedit, bItemedit,
                            //bCusSupInput, cDefine1, cDefine2, cDefine3, cDefine4, cDefine5, cDefine6, cDefine7, cDefine8, cDefine9, cDefine10,
                            //cDefine11, cDefine12, cDefine13, cDefine14, , cDefine16, dReceive, cWLDZFlag, dWLDZTime, bFlagOut,



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

                        //                        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"]);
                        //                            }
                    }
                    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();
            }
        }
Example #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                int     iCount = 0;
                decimal d借sum  = 0;
                decimal d贷sum  = 0;

                string sErr = "";

                int iYear  = BaseFunction.ReturnInt(txtYear.Text.Trim());
                int iMonth = BaseFunction.ReturnInt(txtMonth.Text.Trim());
                int i年期间   = BaseFunction.ReturnInt(Convert.ToDateTime(iYear.ToString() + "-" + iMonth.ToString() + "-01").ToString("yyyyMM"));

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    if (gridView1.RowCount == 0)
                    {
                        throw new Exception("请查询可导入凭证");
                    }
                    DataTable dt币种 = new DataTable();



                    string sSQL = "";
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        bool b = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridCol选择));
                        if (!b)
                        {
                            continue;
                        }

                        d借sum = d借sum + BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol借方));
                        d贷sum = d贷sum + BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol贷方));

                        bool bCheck = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridCol供应商核算));
                        if (bCheck)
                        {
                            string sCheck = gridView1.GetRowCellValue(i, gridCol供应商编码).ToString().Trim();
                            if (sCheck == "")
                            {
                                sErr = sErr + "行" + (i + 1).ToString() + " 供应商不能为空\n";
                            }
                        }

                        bCheck = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridCol客户核算));
                        if (bCheck)
                        {
                            string sCheck = gridView1.GetRowCellValue(i, gridCol客户编码).ToString().Trim();
                            if (sCheck == "")
                            {
                                sErr = sErr + "行" + (i + 1).ToString() + " 客户不能为空\n";
                            }
                        }

                        bCheck = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridCol部门核算));
                        if (bCheck)
                        {
                            string sCheck = gridView1.GetRowCellValue(i, gridCol部门编码).ToString().Trim();
                            if (sCheck == "")
                            {
                                sErr = sErr + "行" + (i + 1).ToString() + " 部门不能为空\n";
                            }
                        }

                        decimal d外币借方 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol外币借方));
                        decimal d外币贷方 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol外币贷方));
                        decimal d汇率   = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol汇率));
                        string  s币种   = gridView1.GetRowCellValue(i, gridCol币种).ToString().Trim();
                        if (d外币借方 != 0 || d外币贷方 != 0)
                        {
                            if (s币种 == "")
                            {
                                sErr = sErr + "行" + (i + 1).ToString() + " 币种不能为空\n";
                            }
                            if (d汇率 == 0)
                            {
                                sErr = sErr + "行" + (i + 1).ToString() + " 汇率不能为0\n";
                            }
                        }
                    }

                    if (d借sum != d贷sum)
                    {
                        throw new Exception("借贷不平");
                    }

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

                    DataTable dt凭证 = (DataTable)gridControl1.DataSource;
                    sSQL = "select isnull(max(ino_id),0)  from GL_accvouch where iyear = aaaaaa AND iperiod = bbbbbb";
                    sSQL = sSQL.Replace("aaaaaa", txtYear.Text.ToString());
                    sSQL = sSQL.Replace("bbbbbb", txtMonth.Text.ToString());
                    DataTable dtinoid = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    int       ino_id  = BaseFunction.ReturnInt(dtinoid.Rows[0][0]);

                    ArrayList aList = new ArrayList();


                    for (int j = 0; j < gridView1.RowCount; j++)
                    {
                        Model.GL_accvouch model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
                        model.iperiod = BaseFunction.ReturnInt(txtMonth.Text.Trim());

                        string sSignSeq = gridView1.GetRowCellValue(j, gridCol凭证类别).ToString().Trim();
                        model.csign = gridView1.GetRowCellValue(j, gridCol凭证类别).ToString().Trim();

                        if (sSignSeq == "现")
                        {
                            model.isignseq = 1;
                        }
                        if (sSignSeq == "银")
                        {
                            model.isignseq = 2;
                        }
                        if (sSignSeq == "转")
                        {
                            model.isignseq = 3;
                        }
                        if (sSignSeq == "记")
                        {
                            model.isignseq = 4;
                        }
                        model.ino_id     = BaseFunction.ReturnInt(gridView1.GetRowCellValue(j, gridCol凭证号));
                        model.inid       = BaseFunction.ReturnInt(gridView1.GetRowCellValue(j, gridCol行号));;
                        model.dbill_date = BaseFunction.ReturnDate(gridView1.GetRowCellValue(j, gridCol制单日期));
                        model.idoc       = -1;
                        model.cbill      = gridView1.GetRowCellValue(j, gridCol制单人).ToString().Trim();
                        model.ibook      = 0;
                        model.cdigest    = gridView1.GetRowCellValue(j, gridCol摘要).ToString().Trim();
                        model.ccode      = gridView1.GetRowCellValue(j, gridCol会计科目).ToString().Trim();
                        model.md         = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(j, gridCol借方));
                        model.mc         = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(j, gridCol贷方));
                        model.md_f       = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(j, gridCol外币借方));
                        model.mc_f       = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(j, gridCol外币贷方));
                        model.nfrat      = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(j, gridCol汇率));
                        model.nd_s       = 0;
                        model.nc_s       = 0;
                        //model.csettle = "";     //结算方式
                        //model.cn_id
                        //model.dt_date =

                        DataRow[] dr凭证;
                        if (model.md > 0)
                        {
                            string s = "贷方>0 and 凭证类别 = '" + model.csign + "' and 凭证号 = '" + gridView1.GetRowCellValue(j, gridCol凭证号).ToString() + "'";
                            dr凭证 = dt凭证.Select(s);
                        }
                        else
                        {
                            string s = "借方>0 and 凭证类别 = '" + model.csign + "' and 凭证号 = '" + gridView1.GetRowCellValue(j, gridCol凭证号).ToString() + "'";
                            dr凭证 = dt凭证.Select(s);
                        }
                        string s对方科目 = "";
                        for (int k = 0; k < dr凭证.Length; k++)
                        {
                            if (s对方科目 == "")
                            {
                                s对方科目 = dr凭证[k]["会计科目"].ToString().Trim();
                            }
                            else
                            {
                                if (s对方科目.IndexOf(dr凭证[k]["会计科目"].ToString().Trim()) < 0)
                                {
                                    s对方科目 = s对方科目 + "," + dr凭证[k]["会计科目"].ToString().Trim();
                                }
                            }
                        }

                        if (s对方科目.Length <= 50)
                        {
                            model.ccode_equal = s对方科目;
                        }
                        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           = BaseFunction.ReturnInt(txtYear.Text.Trim());
                        model.iYPeriod        = i年期间;
                        model.tvouchtime      = DateTime.Now;

                        //if (s对方科目.Length <= 100)
                        //{
                        model.ccodeexch_equal = s对方科目;
                        //}
                        if (gridView1.GetRowCellValue(j, gridCol客户编码).ToString() != "")
                        {
                            model.ccus_id = gridView1.GetRowCellValue(j, gridCol客户编码).ToString();
                        }
                        if (gridView1.GetRowCellValue(j, gridCol供应商编码).ToString() != "")
                        {
                            model.csup_id = gridView1.GetRowCellValue(j, gridCol供应商编码).ToString();
                        }


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

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

                    if (iCount > 0)
                    {
                        tran.Commit();
                        MessageBox.Show("保存成功");
                    }
                    else
                    {
                        throw new Exception("没有数据");
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "提示";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Example #6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView6.FocusedRowHandle -= 1;
                    gridView6.FocusedRowHandle += 1;
                }
                catch { }

                int     iCount = 0;
                decimal d借sum  = 0;
                decimal d贷sum  = 0;

                string sErr = "";

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    if (gridView6.RowCount == 0)
                    {
                        throw new Exception("请查询可导入凭证");
                    }

                    ArrayList aList_Doc = new ArrayList();
                    for (int i = 0; i < gridView6.RowCount; i++)
                    {
                        bool b = BaseFunction.ReturnBool(gridView6.GetRowCellValue(i, gridCol选择));
                        if (!b)
                        {
                            continue;
                        }

                        string sDocNO = gridView6.GetRowCellDisplayText(i, gridColDocumentNo).ToString().Trim();

                        if (sDocNO == "DBSRMB00793")
                        {
                        }

                        bool bExists = false;
                        for (int j = 0; j < aList_Doc.Count; j++)
                        {
                            if (sDocNO == aList_Doc[j].ToString().Trim())
                            {
                                bExists = true;
                                break;
                            }
                        }

                        if (bExists)
                        {
                            continue;
                        }

                        aList_Doc.Add(sDocNO);

                        decimal dC = 0;
                        decimal dD = 0;
                        for (int j = i; j < gridView6.RowCount; j++)
                        {
                            string sDocNO2 = gridView6.GetRowCellDisplayText(j, gridColDocumentNo).ToString().Trim();

                            if (sDocNO == sDocNO2)
                            {
                                dC = dC + BaseFunction.ReturnDecimal(gridView6.GetRowCellValue(j, gridCol借方), 6);
                                dD = dD + BaseFunction.ReturnDecimal(gridView6.GetRowCellValue(j, gridCol贷方), 6);
                            }
                        }

                        if (dC != dD)
                        {
                            sErr = sErr + "行 " + (i + 1).ToString() + " DocumentNo  " + sDocNO + " 借贷不平\n";
                            continue;
                        }
                    }

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


                    DataTable dt币种 = new DataTable();

                    string sSQL = "SELECT * FROM dbo.GL_mend WHERE iyear = aaaaaa AND iperiod = bbbbbb";
                    sSQL = sSQL.Replace("aaaaaa", dateEdit1.DateTime.Year.ToString());
                    sSQL = sSQL.Replace("bbbbbb", dateEdit1.DateTime.Month.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("总账已结账");
                    }

                    for (int i = 0; i < gridView6.RowCount; i++)
                    {
                        bool b = BaseFunction.ReturnBool(gridView6.GetRowCellValue(i, gridCol选择));
                        if (!b)
                        {
                            continue;
                        }

                        d借sum = d借sum + BaseFunction.ReturnDecimal(gridView6.GetRowCellValue(i, gridCol借方));
                        d贷sum = d贷sum + BaseFunction.ReturnDecimal(gridView6.GetRowCellValue(i, gridCol贷方));
                    }

                    if (d借sum != d贷sum)
                    {
                        throw new Exception("借贷不平");
                    }

                    DataTable dt凭证 = (DataTable)gridControl6.DataSource;
                    sSQL = "select isnull(max(ino_id),0)  from GL_accvouch where iyear = aaaaaa AND iperiod = bbbbbb and csign = '记'";
                    sSQL = sSQL.Replace("aaaaaa", dateEdit1.DateTime.Year.ToString());
                    sSQL = sSQL.Replace("bbbbbb", dateEdit1.DateTime.Month.ToString());
                    DataTable dtinoid = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    int       ino_id  = BaseFunction.ReturnInt(dtinoid.Rows[0][0]);

                    ArrayList aList = new ArrayList();
                    for (int i = 0; i < gridView6.RowCount; i++)
                    {
                        bool b = BaseFunction.ReturnBool(gridView6.GetRowCellValue(i, gridCol选择));
                        if (!b)
                        {
                            continue;
                        }
                        if (BaseFunction.ReturnDate(gridView6.GetRowCellValue(i, gridCol制单日期)).Year != dateEdit1.DateTime.Year)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "制单日期不在账期内\n";
                        }
                        if (BaseFunction.ReturnDate(gridView6.GetRowCellValue(i, gridCol制单日期)).Month != dateEdit1.DateTime.Month)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "制单日期不在账期内\n";
                        }

                        string sDocment = gridView6.GetRowCellValue(i, gridColDocumentNo).ToString().ToLower().Trim();
                        bool   bExists  = false;
                        for (int j = 0; j < aList.Count; j++)
                        {
                            if (sDocment == aList[j].ToString().ToLower().Trim())
                            {
                                bExists = true;
                                break;
                            }
                        }
                        if (bExists)
                        {
                            continue;
                        }

                        aList.Add(sDocment);

                        int inid = 0;
                        ino_id = ino_id + 1;
                        for (int j = 0; j < gridView6.RowCount; j++)
                        {
                            string sDocment2 = gridView6.GetRowCellValue(j, gridColDocumentNo).ToString().Trim().ToLower();
                            if (sDocment != sDocment2)
                            {
                                continue;
                            }

                            inid += 1;
                            Model.GL_accvouch model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
                            model.iperiod    = dateEdit1.DateTime.Month;
                            model.csign      = gridView6.GetRowCellValue(j, gridCol凭证类别).ToString().Trim();
                            model.isignseq   = 4;
                            model.ino_id     = ino_id;
                            model.inid       = inid;
                            model.dbill_date = BaseFunction.ReturnDate(gridView6.GetRowCellValue(j, gridCol制单日期));
                            model.idoc       = -1;
                            model.cbill      = gridView6.GetRowCellValue(j, gridCol制单人).ToString().Trim();
                            model.ibook      = 0;

                            string s摘要 = gridView6.GetRowCellValue(j, gridCol摘要).ToString().Trim();
                            if (s摘要.Length > 60)
                            {
                                s摘要 = s摘要.Substring(0, 60);
                            }
                            model.cdigest  = s摘要;
                            model.ccode    = gridView6.GetRowCellValue(j, gridCol会计科目).ToString().Trim();
                            model.cDefine1 = sDocment2;
                            model.md       = BaseFunction.ReturnDecimal(gridView6.GetRowCellValue(j, gridCol借方));
                            model.mc       = BaseFunction.ReturnDecimal(gridView6.GetRowCellValue(j, gridCol贷方));
                            model.md_f     = BaseFunction.ReturnDecimal(gridView6.GetRowCellValue(j, gridCol外币借方));
                            model.mc_f     = BaseFunction.ReturnDecimal(gridView6.GetRowCellValue(j, gridCol外币贷方));
                            model.nfrat    = BaseFunction.ReturnDecimal(gridView6.GetRowCellValue(j, gridCol汇率));
                            model.nd_s     = 0;
                            model.nc_s     = 0;
                            //model.csettle = "";     //结算方式
                            //model.cn_id
                            //model.dt_date =

                            DataRow[] dr凭证;
                            if (model.md > 0)
                            {
                                string s = "贷方>0 and 凭证类别 = '" + model.csign + "' and DocumentNo = '" + gridView6.GetRowCellValue(j, gridColDocumentNo).ToString() + "'";
                                dr凭证 = dt凭证.Select(s);
                            }
                            else
                            {
                                string s = "借方>0 and 凭证类别 = '" + model.csign + "' and DocumentNo = '" + gridView6.GetRowCellValue(j, gridColDocumentNo).ToString() + "'";
                                dr凭证 = dt凭证.Select(s);
                            }
                            string s对方科目 = "";
                            for (int k = 0; k < dr凭证.Length; k++)
                            {
                                if (s对方科目 == "")
                                {
                                    s对方科目 = dr凭证[k]["会计科目"].ToString().Trim();
                                }
                                else
                                {
                                    string sTemp = s对方科目 + "," + dr凭证[k]["会计科目"].ToString().Trim();
                                    if (sTemp.Length < 50)
                                    {
                                        if (s对方科目.IndexOf(dr凭证[k]["会计科目"].ToString().Trim()) < 0)
                                        {
                                            s对方科目 = s对方科目 + "," + dr凭证[k]["会计科目"].ToString().Trim();
                                        }
                                    }
                                }
                            }

                            if (s对方科目.Length > 50)
                            {
                                s对方科目 = s对方科目.Substring(0, 50);
                            }
                            model.ccode_equal     = s对方科目;
                            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           = dateEdit1.DateTime.Year;
                            model.iYPeriod        = BaseFunction.ReturnInt(dateEdit1.DateTime.ToString("yyyyMM"));
                            model.tvouchtime      = DateTime.Now;
                            model.ccodeexch_equal = s对方科目;
                            if (gridView6.GetRowCellValue(j, gridCol客户编码).ToString() != "")
                            {
                                model.ccus_id = gridView6.GetRowCellValue(j, gridCol客户编码).ToString();
                            }
                            if (gridView6.GetRowCellValue(j, gridCol供应商编码).ToString() != "")
                            {
                                model.csup_id = gridView6.GetRowCellValue(j, gridCol供应商编码).ToString();
                            }


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

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

                    if (iCount > 0)
                    {
                        tran.Commit();
                        MessageBox.Show("保存成功");
                        btnSel_Click(null, null);
                    }
                    else
                    {
                        throw new Exception("没有数据");
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "提示";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Example #7
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch DataRowToModel(DataRow row)
 {
     UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
     if (row != null)
     {
         if (row["i_id"] != null && row["i_id"].ToString() != "")
         {
             model.i_id = int.Parse(row["i_id"].ToString());
         }
         if (row["iperiod"] != null && row["iperiod"].ToString() != "")
         {
             model.iperiod = int.Parse(row["iperiod"].ToString());
         }
         if (row["csign"] != null)
         {
             model.csign = row["csign"].ToString();
         }
         if (row["isignseq"] != null && row["isignseq"].ToString() != "")
         {
             model.isignseq = int.Parse(row["isignseq"].ToString());
         }
         if (row["ino_id"] != null && row["ino_id"].ToString() != "")
         {
             model.ino_id = int.Parse(row["ino_id"].ToString());
         }
         if (row["inid"] != null && row["inid"].ToString() != "")
         {
             model.inid = int.Parse(row["inid"].ToString());
         }
         if (row["dbill_date"] != null && row["dbill_date"].ToString() != "")
         {
             model.dbill_date = DateTime.Parse(row["dbill_date"].ToString());
         }
         if (row["idoc"] != null && row["idoc"].ToString() != "")
         {
             model.idoc = int.Parse(row["idoc"].ToString());
         }
         if (row["cbill"] != null)
         {
             model.cbill = row["cbill"].ToString();
         }
         if (row["ccheck"] != null)
         {
             model.ccheck = row["ccheck"].ToString();
         }
         if (row["cbook"] != null)
         {
             model.cbook = row["cbook"].ToString();
         }
         if (row["ibook"] != null && row["ibook"].ToString() != "")
         {
             model.ibook = int.Parse(row["ibook"].ToString());
         }
         if (row["ccashier"] != null)
         {
             model.ccashier = row["ccashier"].ToString();
         }
         //if (row["iflag"] != null && row["iflag"].ToString() != "")
         //{
         //    model.iflag = int.Parse(row["iflag"].ToString());
         //}
         if (row["ctext1"] != null)
         {
             model.ctext1 = row["ctext1"].ToString();
         }
         if (row["ctext2"] != null)
         {
             model.ctext2 = row["ctext2"].ToString();
         }
         if (row["cdigest"] != null)
         {
             model.cdigest = row["cdigest"].ToString();
         }
         if (row["ccode"] != null)
         {
             model.ccode = row["ccode"].ToString();
         }
         if (row["cexch_name"] != null)
         {
             model.cexch_name = row["cexch_name"].ToString();
         }
         if (row["md"] != null && row["md"].ToString() != "")
         {
             model.md = decimal.Parse(row["md"].ToString());
         }
         if (row["mc"] != null && row["mc"].ToString() != "")
         {
             model.mc = decimal.Parse(row["mc"].ToString());
         }
         if (row["md_f"] != null && row["md_f"].ToString() != "")
         {
             model.md_f = decimal.Parse(row["md_f"].ToString());
         }
         if (row["mc_f"] != null && row["mc_f"].ToString() != "")
         {
             model.mc_f = decimal.Parse(row["mc_f"].ToString());
         }
         if (row["nfrat"] != null && row["nfrat"].ToString() != "")
         {
             model.nfrat = decimal.Parse(row["nfrat"].ToString());
         }
         if (row["nd_s"] != null && row["nd_s"].ToString() != "")
         {
             model.nd_s = decimal.Parse(row["nd_s"].ToString());
         }
         if (row["nc_s"] != null && row["nc_s"].ToString() != "")
         {
             model.nc_s = decimal.Parse(row["nc_s"].ToString());
         }
         if (row["csettle"] != null)
         {
             model.csettle = row["csettle"].ToString();
         }
         if (row["cn_id"] != null)
         {
             model.cn_id = row["cn_id"].ToString();
         }
         if (row["dt_date"] != null && row["dt_date"].ToString() != "")
         {
             model.dt_date = DateTime.Parse(row["dt_date"].ToString());
         }
         if (row["cdept_id"] != null)
         {
             model.cdept_id = row["cdept_id"].ToString();
         }
         if (row["cperson_id"] != null)
         {
             model.cperson_id = row["cperson_id"].ToString();
         }
         if (row["ccus_id"] != null)
         {
             model.ccus_id = row["ccus_id"].ToString();
         }
         if (row["csup_id"] != null)
         {
             model.csup_id = row["csup_id"].ToString();
         }
         if (row["citem_id"] != null)
         {
             model.citem_id = row["citem_id"].ToString();
         }
         if (row["citem_class"] != null)
         {
             model.citem_class = row["citem_class"].ToString();
         }
         if (row["cname"] != null)
         {
             model.cname = row["cname"].ToString();
         }
         if (row["ccode_equal"] != null)
         {
             model.ccode_equal = row["ccode_equal"].ToString();
         }
         if (row["iflagbank"] != null && row["iflagbank"].ToString() != "")
         {
             model.iflagbank = int.Parse(row["iflagbank"].ToString());
         }
         if (row["iflagPerson"] != null && row["iflagPerson"].ToString() != "")
         {
             model.iflagPerson = int.Parse(row["iflagPerson"].ToString());
         }
         if (row["bdelete"] != null && row["bdelete"].ToString() != "")
         {
             if ((row["bdelete"].ToString() == "1") || (row["bdelete"].ToString().ToLower() == "true"))
             {
                 model.bdelete = true;
             }
             else
             {
                 model.bdelete = false;
             }
         }
         if (row["coutaccset"] != null)
         {
             model.coutaccset = row["coutaccset"].ToString();
         }
         if (row["ioutyear"] != null && row["ioutyear"].ToString() != "")
         {
             model.ioutyear = int.Parse(row["ioutyear"].ToString());
         }
         if (row["coutsysname"] != null)
         {
             model.coutsysname = row["coutsysname"].ToString();
         }
         if (row["coutsysver"] != null)
         {
             model.coutsysver = row["coutsysver"].ToString();
         }
         if (row["doutbilldate"] != null && row["doutbilldate"].ToString() != "")
         {
             model.doutbilldate = DateTime.Parse(row["doutbilldate"].ToString());
         }
         if (row["ioutperiod"] != null && row["ioutperiod"].ToString() != "")
         {
             model.ioutperiod = int.Parse(row["ioutperiod"].ToString());
         }
         if (row["coutsign"] != null)
         {
             model.coutsign = row["coutsign"].ToString();
         }
         if (row["coutno_id"] != null)
         {
             model.coutno_id = row["coutno_id"].ToString();
         }
         if (row["doutdate"] != null && row["doutdate"].ToString() != "")
         {
             model.doutdate = DateTime.Parse(row["doutdate"].ToString());
         }
         if (row["coutbillsign"] != null)
         {
             model.coutbillsign = row["coutbillsign"].ToString();
         }
         if (row["coutid"] != null)
         {
             model.coutid = row["coutid"].ToString();
         }
         if (row["bvouchedit"] != null && row["bvouchedit"].ToString() != "")
         {
             if ((row["bvouchedit"].ToString() == "1") || (row["bvouchedit"].ToString().ToLower() == "true"))
             {
                 model.bvouchedit = true;
             }
             else
             {
                 model.bvouchedit = false;
             }
         }
         if (row["bvouchAddordele"] != null && row["bvouchAddordele"].ToString() != "")
         {
             if ((row["bvouchAddordele"].ToString() == "1") || (row["bvouchAddordele"].ToString().ToLower() == "true"))
             {
                 model.bvouchAddordele = true;
             }
             else
             {
                 model.bvouchAddordele = false;
             }
         }
         if (row["bvouchmoneyhold"] != null && row["bvouchmoneyhold"].ToString() != "")
         {
             if ((row["bvouchmoneyhold"].ToString() == "1") || (row["bvouchmoneyhold"].ToString().ToLower() == "true"))
             {
                 model.bvouchmoneyhold = true;
             }
             else
             {
                 model.bvouchmoneyhold = false;
             }
         }
         if (row["bvalueedit"] != null && row["bvalueedit"].ToString() != "")
         {
             if ((row["bvalueedit"].ToString() == "1") || (row["bvalueedit"].ToString().ToLower() == "true"))
             {
                 model.bvalueedit = true;
             }
             else
             {
                 model.bvalueedit = false;
             }
         }
         if (row["bcodeedit"] != null && row["bcodeedit"].ToString() != "")
         {
             if ((row["bcodeedit"].ToString() == "1") || (row["bcodeedit"].ToString().ToLower() == "true"))
             {
                 model.bcodeedit = true;
             }
             else
             {
                 model.bcodeedit = false;
             }
         }
         if (row["ccodecontrol"] != null)
         {
             model.ccodecontrol = row["ccodecontrol"].ToString();
         }
         if (row["bPCSedit"] != null && row["bPCSedit"].ToString() != "")
         {
             if ((row["bPCSedit"].ToString() == "1") || (row["bPCSedit"].ToString().ToLower() == "true"))
             {
                 model.bPCSedit = true;
             }
             else
             {
                 model.bPCSedit = false;
             }
         }
         if (row["bDeptedit"] != null && row["bDeptedit"].ToString() != "")
         {
             if ((row["bDeptedit"].ToString() == "1") || (row["bDeptedit"].ToString().ToLower() == "true"))
             {
                 model.bDeptedit = true;
             }
             else
             {
                 model.bDeptedit = false;
             }
         }
         if (row["bItemedit"] != null && row["bItemedit"].ToString() != "")
         {
             if ((row["bItemedit"].ToString() == "1") || (row["bItemedit"].ToString().ToLower() == "true"))
             {
                 model.bItemedit = true;
             }
             else
             {
                 model.bItemedit = false;
             }
         }
         if (row["bCusSupInput"] != null && row["bCusSupInput"].ToString() != "")
         {
             if ((row["bCusSupInput"].ToString() == "1") || (row["bCusSupInput"].ToString().ToLower() == "true"))
             {
                 model.bCusSupInput = true;
             }
             else
             {
                 model.bCusSupInput = false;
             }
         }
         if (row["cDefine1"] != null)
         {
             model.cDefine1 = row["cDefine1"].ToString();
         }
         if (row["cDefine2"] != null)
         {
             model.cDefine2 = row["cDefine2"].ToString();
         }
         if (row["cDefine3"] != null)
         {
             model.cDefine3 = row["cDefine3"].ToString();
         }
         if (row["cDefine4"] != null && row["cDefine4"].ToString() != "")
         {
             model.cDefine4 = DateTime.Parse(row["cDefine4"].ToString());
         }
         if (row["cDefine5"] != null && row["cDefine5"].ToString() != "")
         {
             model.cDefine5 = int.Parse(row["cDefine5"].ToString());
         }
         if (row["cDefine6"] != null && row["cDefine6"].ToString() != "")
         {
             model.cDefine6 = DateTime.Parse(row["cDefine6"].ToString());
         }
         if (row["cDefine7"] != null && row["cDefine7"].ToString() != "")
         {
             model.cDefine7 = decimal.Parse(row["cDefine7"].ToString());
         }
         if (row["cDefine8"] != null)
         {
             model.cDefine8 = row["cDefine8"].ToString();
         }
         if (row["cDefine9"] != null)
         {
             model.cDefine9 = row["cDefine9"].ToString();
         }
         if (row["cDefine10"] != null)
         {
             model.cDefine10 = row["cDefine10"].ToString();
         }
         if (row["cDefine11"] != null)
         {
             model.cDefine11 = row["cDefine11"].ToString();
         }
         if (row["cDefine12"] != null)
         {
             model.cDefine12 = row["cDefine12"].ToString();
         }
         if (row["cDefine13"] != null)
         {
             model.cDefine13 = row["cDefine13"].ToString();
         }
         if (row["cDefine14"] != null)
         {
             model.cDefine14 = row["cDefine14"].ToString();
         }
         if (row["cDefine15"] != null && row["cDefine15"].ToString() != "")
         {
             model.cDefine15 = int.Parse(row["cDefine15"].ToString());
         }
         if (row["cDefine16"] != null && row["cDefine16"].ToString() != "")
         {
             model.cDefine16 = decimal.Parse(row["cDefine16"].ToString());
         }
         if (row["dReceive"] != null && row["dReceive"].ToString() != "")
         {
             model.dReceive = DateTime.Parse(row["dReceive"].ToString());
         }
         if (row["cWLDZFlag"] != null)
         {
             model.cWLDZFlag = row["cWLDZFlag"].ToString();
         }
         if (row["dWLDZTime"] != null && row["dWLDZTime"].ToString() != "")
         {
             model.dWLDZTime = DateTime.Parse(row["dWLDZTime"].ToString());
         }
         if (row["bFlagOut"] != null && row["bFlagOut"].ToString() != "")
         {
             if ((row["bFlagOut"].ToString() == "1") || (row["bFlagOut"].ToString().ToLower() == "true"))
             {
                 model.bFlagOut = true;
             }
             else
             {
                 model.bFlagOut = false;
             }
         }
         if (row["iBG_OverFlag"] != null && row["iBG_OverFlag"].ToString() != "")
         {
             model.iBG_OverFlag = int.Parse(row["iBG_OverFlag"].ToString());
         }
         if (row["cBG_Auditor"] != null)
         {
             model.cBG_Auditor = row["cBG_Auditor"].ToString();
         }
         if (row["dBG_AuditTime"] != null && row["dBG_AuditTime"].ToString() != "")
         {
             model.dBG_AuditTime = DateTime.Parse(row["dBG_AuditTime"].ToString());
         }
         if (row["cBG_AuditOpinion"] != null)
         {
             model.cBG_AuditOpinion = row["cBG_AuditOpinion"].ToString();
         }
         if (row["bWH_BgFlag"] != null && row["bWH_BgFlag"].ToString() != "")
         {
             if ((row["bWH_BgFlag"].ToString() == "1") || (row["bWH_BgFlag"].ToString().ToLower() == "true"))
             {
                 model.bWH_BgFlag = true;
             }
             else
             {
                 model.bWH_BgFlag = false;
             }
         }
         if (row["ssxznum"] != null && row["ssxznum"].ToString() != "")
         {
             model.ssxznum = int.Parse(row["ssxznum"].ToString());
         }
         if (row["CErrReason"] != null)
         {
             model.CErrReason = row["CErrReason"].ToString();
         }
         if (row["BG_AuditRemark"] != null)
         {
             model.BG_AuditRemark = row["BG_AuditRemark"].ToString();
         }
         if (row["cBudgetBuffer"] != null)
         {
             model.cBudgetBuffer = row["cBudgetBuffer"].ToString();
         }
         if (row["iBG_ControlResult"] != null && row["iBG_ControlResult"].ToString() != "")
         {
             model.iBG_ControlResult = int.Parse(row["iBG_ControlResult"].ToString());
         }
         if (row["NCVouchID"] != null)
         {
             model.NCVouchID = row["NCVouchID"].ToString();
         }
         if (row["daudit_date"] != null && row["daudit_date"].ToString() != "")
         {
             model.daudit_date = DateTime.Parse(row["daudit_date"].ToString());
         }
         if (row["RowGuid"] != null)
         {
             model.RowGuid = row["RowGuid"].ToString();
         }
         if (row["cBankReconNo"] != null)
         {
             model.cBankReconNo = row["cBankReconNo"].ToString();
         }
         if (row["iyear"] != null && row["iyear"].ToString() != "")
         {
             model.iyear = int.Parse(row["iyear"].ToString());
         }
         if (row["iYPeriod"] != null && row["iYPeriod"].ToString() != "")
         {
             model.iYPeriod = int.Parse(row["iYPeriod"].ToString());
         }
         if (row["wllqDate"] != null && row["wllqDate"].ToString() != "")
         {
             model.wllqDate = DateTime.Parse(row["wllqDate"].ToString());
         }
         if (row["wllqPeriod"] != null && row["wllqPeriod"].ToString() != "")
         {
             model.wllqPeriod = int.Parse(row["wllqPeriod"].ToString());
         }
         if (row["tvouchtime"] != null && row["tvouchtime"].ToString() != "")
         {
             model.tvouchtime = DateTime.Parse(row["tvouchtime"].ToString());
         }
         if (row["cblueoutno_id"] != null)
         {
             model.cblueoutno_id = row["cblueoutno_id"].ToString();
         }
         if (row["ccodeexch_equal"] != null)
         {
             model.ccodeexch_equal = row["ccodeexch_equal"].ToString();
         }
     }
     return(model);
 }
Example #8
0
        private void btnCreateRedVoucher_Click(object sender, EventArgs e)
        {
            try
            {
                int iRow = gridView1.FocusedRowHandle;
                if (iRow < 0)
                {
                    throw new Exception("Please choose data");
                }

                int iCou = 0;

                int iYearSource   = BaseFunction.ReturnInt(gridView1.GetRowCellValue(iRow, gridColiYear));
                int iPeriodSource = BaseFunction.ReturnInt(gridView1.GetRowCellValue(iRow, gridColiPeriod));

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();

                try
                {
                    string[] s       = lLoginPeriod.Text.Trim().Split('.');
                    int      iYear   = BaseFunction.ReturnInt(s[0]);
                    int      iPeriod = BaseFunction.ReturnInt(s[1]);

                    string sSQL = @"
SELECT bflag 
FROM dbo.GL_mend 
WHERE iyear = aaaaaa AND iperiod = bbbbbb";
                    sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                    sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Failed to obtain module status");
                    }
                    if (BaseFunction.ReturnBool(dt.Rows[0]["bflag"]))
                    {
                        throw new Exception("The current date has been checked out");
                    }


                    #region 生成红冲凭证

                    sSQL = @"
select *
from GL_accvouch 
where iyear = aaaaaa and iperiod = bbbbbb  and isnull(iflag,0) = 0
    and ino_id = 'cccccc' and csign = 'dddddd'
    ";
                    sSQL = sSQL.Replace("aaaaaa", iYearSource.ToString());
                    sSQL = sSQL.Replace("bbbbbb", iPeriodSource.ToString());

                    string sGLVoucherNO = gridView1.GetRowCellValue(iRow, gridColGLVoucherNO).ToString().Trim();
                    if (sGLVoucherNO == "")
                    {
                        throw new Exception("Please choose source");
                    }

                    string[] sGlSource = sGLVoucherNO.Split('-');
                    sSQL = sSQL.Replace("cccccc", sGlSource[1]);
                    sSQL = sSQL.Replace("dddddd", sGlSource[0]);

                    dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        MessageBox.Show("No data.Please manually generate the red document");
                    }
                    else
                    {
                        string sGLRedVouch = gridView1.GetRowCellValue(iRow, gridColRedGLVoucherNO).ToString().Trim();
                        if (sGLRedVouch != "")
                        {
                            sGlSource = sGLRedVouch.Split('-');

                            sSQL = @"
select *
from GL_accvouch 
where csign = 'AP' and iyear = aaaaaa and iperiod = bbbbbb and isnull(iflag,0) = 0
    and ino_id = 'cccccc' and csign = 'dddddd'
";
                            sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                            sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                            sSQL = sSQL.Replace("cccccc", sGlSource[1]);
                            sSQL = sSQL.Replace("dddddd", sGlSource[0]);
                            dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            if (dt != null && dt.Rows.Count > 0)
                            {
                                throw new Exception("Accounting vouchers already exist");
                            }
                        }

                        sSQL = "select isnull(max(ino_id),0) as ino_id from GL_accvouch where iyear = aaaaaa AND iperiod = bbbbbb and csign = 'AP'";
                        sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                        sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                        DataTable dtinoid = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        int       ino_id  = BaseFunction.ReturnInt(dtinoid.Rows[0]["ino_id"]);
                        ino_id += 1;
                        string sVoucher = "AP-" + ino_id.ToString().PadLeft(4, '0') + "\n";
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            Model.GL_accvouch mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
                            DAL.GL_accvouch   dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.GL_accvouch();

                            mod = dal.DataRowToModel(dt.Rows[i]);

                            mod.ino_id   = ino_id;
                            mod.iyear    = iYear;
                            mod.iperiod  = iPeriod;
                            mod.iYPeriod = BaseFunction.ReturnInt(BaseFunction.ReturnDate(iYearSource.ToString() + "-" + iPeriod.ToString() + "-01").ToString("yyyyMM"));
                            mod.md       = -1 * mod.md;
                            mod.mc       = -1 * mod.mc;
                            mod.md_f     = -1 * mod.md_f;
                            mod.md_f     = -1 * mod.md_f;

                            sSQL  = dal.Add(mod);
                            iCou += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        if (iCou > 0)
                        {
                            sSQL = @"
select *
from GL_accvouch
where iyear = {0} and iPeriod = {1} and csign = '{2}' and ino_id = {3}
";
                            sSQL = string.Format(sSQL, iYear.ToString(), iPeriod.ToString(), "AP", ino_id);
                            DataTable dtGL = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            sSQL = @"
update [dbo].[_AmountOfExchangeProfitAndLoss] set [RedcSign] = 'aaaaaaaa',[Redi_id] = bbbbbbbb,[Redino_id] = 'iiiiiiii'
	,[SourceiYear] =cccccccc ,[SourceiPeriod] = dddddddd,[SourcecSign] = 'eeeeeeee',[Sourceino_id] = ffffffff
where iYear = gggggggg and iPeriod = hhhhhhhh
";
                            sSQL = sSQL.Replace("aaaaaaaa", sGlSource[0]);
                            sSQL = sSQL.Replace("bbbbbbbb", dtGL.Rows[0]["i_id"].ToString());
                            sSQL = sSQL.Replace("cccccccc", iYearSource.ToString());
                            sSQL = sSQL.Replace("dddddddd", iPeriodSource.ToString());
                            sSQL = sSQL.Replace("eeeeeeee", sGlSource[0]);
                            sSQL = sSQL.Replace("ffffffff", sGlSource[1]);
                            sSQL = sSQL.Replace("gggggggg", iYear.ToString());
                            sSQL = sSQL.Replace("hhhhhhhh", iPeriod.ToString());
                            sSQL = sSQL.Replace("iiiiiiii", BaseFunction.ReturnInt(sVoucher.Split('-')[1]).ToString().Trim());
                            int iCount = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            if (iCount == 0)
                            {
                                throw new Exception("Please CreateVoucher first");
                            }
                        }
                    }


                    #endregion

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

                        MessageBox.Show("Sucess");
                        btnQuery_Click(null, null);
                    }
                    else
                    {
                        throw new Exception("Err:no data");
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "Err";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }
Example #9
0
        private void btnCreateVoucher_Click(object sender, EventArgs e)
        {
            try
            {
                int iRow = gridView1.FocusedRowHandle;
                if (iRow < 0)
                {
                    throw new Exception("Please choose data");
                }

                int iYear   = BaseFunction.ReturnInt(gridView1.GetRowCellValue(iRow, gridColiYear));
                int iPeriod = BaseFunction.ReturnInt(gridView1.GetRowCellValue(iRow, gridColiPeriod));

                string sVoucher = "";

                int           iCount = 0;
                SqlConnection conn   = new SqlConnection(Conn);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();

                try
                {
                    string sSQL = "SELECT bflag FROM dbo.GL_mend WHERE iyear = aaaaaa AND iperiod = bbbbbb";
                    sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                    sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Failed to obtain module status");
                    }
                    if (BaseFunction.ReturnBool(dt.Rows[0]["bflag"]))
                    {
                        throw new Exception("The current date has been checked out");
                    }

                    sSQL = @"
select *
from GL_accvouch gl  inner join _AmountOfExchangeProfitAndLoss b 
	on gl.iyear = b.iYear and gl.iperiod = b.iPeriod and gl.i_id = b.i_id and gl.csign = b.csign
where gl.csign = 'AP' and gl.iyear = aaaaaa and gl.iperiod = bbbbbb and isnull(gl.iflag,0) = 0
";
                    sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                    sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    if (dt != null && dt.Rows.Count > 0)
                    {
                        throw new Exception("Accounting vouchers already exist");
                    }


                    sSQL = @"
select * from _Code where VouchType = 'Exchange gain or loss'
";
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Please set aounting subject [_Code.Exchange gain or loss]");
                    }
                    string sKMD = dt.Rows[0]["Debtor"].ToString().Trim();
                    string sKMC = dt.Rows[0]["Creditor"].ToString().Trim();
                    string sZY  = dt.Rows[0]["Remark"].ToString().Trim();
                    if (sKMD == "" || sKMC == "")
                    {
                        throw new Exception("Please set aounting subject [_Code.Exchange gain or loss]");
                    }


                    sSQL = "select isnull(max(ino_id),0)  from GL_accvouch where iyear = aaaaaa AND iperiod = bbbbbb and csign = 'AP'";
                    sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                    sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                    DataTable dtinoid = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    int       ino_id  = BaseFunction.ReturnInt(dtinoid.Rows[0][0]) + 1;

                    sSQL = @"
select sum(AmountOfExchangeProfitAndLoss) as AmountOfExchangeProfitAndLoss ,rd.cVenCode
from _AmountOfExchangeProfitAndLoss a
	left join RdRecord01 rd on a.cCode = rd.cCode
where a.iyear = aaaaaa and a.iperiod = bbbbbb
group by rd.cVenCode
";
                    sSQL = sSQL.Replace("aaaaaa", iYear.ToString());
                    sSQL = sSQL.Replace("bbbbbb", iPeriod.ToString());
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Please do the math first");
                    }

                    decimal dSum = 0;// BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(iRow, gridColAmountOfExchangeProfitAndLoss), 2);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        dSum = dSum + BaseFunction.ReturnDecimal(dt.Rows[i]["AmountOfExchangeProfitAndLoss"], 2);
                    }

                    sVoucher = sVoucher + "AP-" + ino_id.ToString().PadLeft(4, '0') + "\n";
                    #region 生成凭证
                    #region 借方
                    Model.GL_accvouch model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
                    model.iperiod    = iPeriod;
                    model.csign      = "AP";
                    model.isignseq   = 2;
                    model.ino_id     = ino_id;
                    model.inid       = 1;
                    model.dbill_date = BaseFunction.ReturnDate(sLogDate);
                    model.idoc       = -1;
                    model.cbill      = sUserName;
                    model.ibook      = 0;
                    model.cdigest    = sZY;
                    model.ccode      = sKMD;
                    //model.cDefine1 = sDocment2;
                    model.md    = BaseFunction.ReturnDecimal(dSum, 2);
                    model.mc    = 0;
                    model.md_f  = 0;
                    model.mc_f  = 0;
                    model.nfrat = 0;
                    model.nd_s  = 0;
                    model.nc_s  = 0;
                    //model.csettle = "";     //结算方式
                    //model.cn_id
                    //model.dt_date =

                    model.ccode_equal = sKMC;;
                    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        = BaseFunction.ReturnInt(BaseFunction.ReturnDate(iYear.ToString() + "-" + iPeriod.ToString() + "-01").ToString("yyyyMM"));
                    model.tvouchtime      = DateTime.Now;
                    model.ccodeexch_equal = sKMC;

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

                    #region 贷方
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        model            = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.GL_accvouch();
                        model.iperiod    = iPeriod;
                        model.csign      = "AP";
                        model.isignseq   = 2;
                        model.ino_id     = ino_id;
                        model.inid       = 2;
                        model.dbill_date = BaseFunction.ReturnDate(sLogDate);
                        model.idoc       = -1;
                        model.cbill      = sUserName;
                        model.ibook      = 0;
                        model.cdigest    = sZY;
                        model.ccode      = sKMC;
                        //model.cDefine1 = sDocment2;
                        model.md    = 0;
                        model.mc    = BaseFunction.ReturnDecimal(dt.Rows[i]["AmountOfExchangeProfitAndLoss"], 2);
                        model.md_f  = 0;
                        model.mc_f  = 0;
                        model.nfrat = 0;
                        model.nd_s  = 0;
                        model.nc_s  = 0;
                        //model.csettle = "";     //结算方式
                        //model.cn_id
                        //model.dt_date =

                        model.ccode_equal     = sKMD;;
                        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        = BaseFunction.ReturnInt(BaseFunction.ReturnDate(iYear.ToString() + "-" + iPeriod.ToString() + "-01").ToString("yyyyMM"));
                        model.tvouchtime      = DateTime.Now;
                        model.ccodeexch_equal = sKMD;

                        model.csup_id = dt.Rows[i]["cVenCode"].ToString().Trim();

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

                    #endregion

                    sSQL = @"
select *
from GL_accvouch
where iyear = {0} and iPeriod = {1} and csign = '{2}' and ino_id = {3}
";
                    sSQL = string.Format(sSQL, model.iyear, model.iperiod, model.csign, model.ino_id);
                    DataTable dtGL = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    long      i_id = BaseFunction.ReturnLong(dtGL.Rows[0]["i_id"]);

                    sSQL = @"
update _AmountOfExchangeProfitAndLoss set csign = 'AP',i_id = 'dddddddd',ino_id = 'eeeeee'
where  iyear = bbbbbbbb and iperiod = cccccccc
";
                    sSQL = sSQL.Replace("bbbbbbbb", model.iyear.ToString());
                    sSQL = sSQL.Replace("cccccccc", model.iperiod.ToString());
                    sSQL = sSQL.Replace("dddddddd", i_id.ToString().Trim());
                    sSQL = sSQL.Replace("eeeeee", model.ino_id.ToString().Trim());
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    tran.Commit();

                    MessageBox.Show("Sucess\n" + sVoucher);
                    btnQuery_Click(null, null);
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "Err";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }