Ejemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._高开返利核销单_SZ model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update _高开返利核销单_SZ set ");
            if (model.DLS != null)
            {
                strSql.Append("DLS='" + model.DLS + "',");
            }
            else
            {
                strSql.Append("DLS= null ,");
            }
            if (model.QY != null)
            {
                strSql.Append("QY='" + model.QY + "',");
            }
            else
            {
                strSql.Append("QY= null ,");
            }
            if (model.cCode != null)
            {
                strSql.Append("cCode='" + model.cCode + "',");
            }
            else
            {
                strSql.Append("cCode= null ,");
            }
            if (model.dtmDate != null)
            {
                strSql.Append("dtmDate='" + model.dtmDate + "',");
            }
            else
            {
                strSql.Append("dtmDate= null ,");
            }
            if (model.dMoney_kh != null)
            {
                strSql.Append("dMoney_kh=" + model.dMoney_kh + ",");
            }
            else
            {
                strSql.Append("dMoney_kh= null ,");
            }
            if (model.dMoney_fl != null)
            {
                strSql.Append("dMoney_fl='" + model.dMoney_fl + "',");
            }
            else
            {
                strSql.Append("dMoney_fl= null ,");
            }
            if (model.dMoney_kp != null)
            {
                strSql.Append("dMoney_kp=" + model.dMoney_kp + ",");
            }
            else
            {
                strSql.Append("dMoney_kp= null ,");
            }
            if (model.FLD_iID != null)
            {
                strSql.Append("FLD_iID=" + model.FLD_iID + ",");
            }
            else
            {
                strSql.Append("FLD_iID= null ,");
            }
            if (model.FLD_cCode != null)
            {
                strSql.Append("FLD_cCode='" + model.FLD_cCode + "',");
            }
            else
            {
                strSql.Append("FLD_cCode= null ,");
            }
            if (model.FLD_Money != null)
            {
                strSql.Append("FLD_Money=" + model.FLD_Money + ",");
            }
            else
            {
                strSql.Append("FLD_Money= null ,");
            }
            if (model.createUid != null)
            {
                strSql.Append("createUid='" + model.createUid + "',");
            }
            else
            {
                strSql.Append("createUid= null ,");
            }
            if (model.dtmCreate != null)
            {
                strSql.Append("dtmCreate='" + model.dtmCreate + "',");
            }
            else
            {
                strSql.Append("dtmCreate= null ,");
            }
            if (model.Remark != null)
            {
                strSql.Append("Remark='" + model.Remark + "',");
            }
            else
            {
                strSql.Append("Remark= null ,");
            }
            if (model.GUID != null)
            {
                strSql.Append("GUID='" + model.GUID + "',");
            }
            else
            {
                strSql.Append("GUID= null ,");
            }
            if (model.dtmSysCreatetime != null)
            {
                strSql.Append("dtmSysCreatetime='" + model.dtmSysCreatetime + "',");
            }
            else
            {
                strSql.Append("dtmSysCreatetime= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where iID=" + model.iID + "");
            return(strSql.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._高开返利核销单_SZ model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.DLS != null)
            {
                strSql1.Append("DLS,");
                strSql2.Append("'" + model.DLS + "',");
            }
            if (model.QY != null)
            {
                strSql1.Append("QY,");
                strSql2.Append("'" + model.QY + "',");
            }
            if (model.cCode != null)
            {
                strSql1.Append("cCode,");
                strSql2.Append("'" + model.cCode + "',");
            }
            if (model.dtmDate != null)
            {
                strSql1.Append("dtmDate,");
                strSql2.Append("'" + model.dtmDate + "',");
            }
            if (model.dMoney_kh != null)
            {
                strSql1.Append("dMoney_kh,");
                strSql2.Append("" + model.dMoney_kh + ",");
            }
            if (model.dMoney_fl != null)
            {
                strSql1.Append("dMoney_fl,");
                strSql2.Append("'" + model.dMoney_fl + "',");
            }
            if (model.dMoney_kp != null)
            {
                strSql1.Append("dMoney_kp,");
                strSql2.Append("" + model.dMoney_kp + ",");
            }
            if (model.FLD_iID != null)
            {
                strSql1.Append("FLD_iID,");
                strSql2.Append("" + model.FLD_iID + ",");
            }
            if (model.FLD_cCode != null)
            {
                strSql1.Append("FLD_cCode,");
                strSql2.Append("'" + model.FLD_cCode + "',");
            }
            if (model.FLD_Money != null)
            {
                strSql1.Append("FLD_Money,");
                strSql2.Append("" + model.FLD_Money + ",");
            }
            if (model.createUid != null)
            {
                strSql1.Append("createUid,");
                strSql2.Append("'" + model.createUid + "',");
            }
            if (model.dtmCreate != null)
            {
                strSql1.Append("dtmCreate,");
                strSql2.Append("'" + model.dtmCreate + "',");
            }
            if (model.Remark != null)
            {
                strSql1.Append("Remark,");
                strSql2.Append("'" + model.Remark + "',");
            }
            if (model.GUID != null)
            {
                strSql1.Append("GUID,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.dtmSysCreatetime != null)
            {
                strSql1.Append("dtmSysCreatetime,");
                strSql2.Append("'" + model.dtmSysCreatetime + "',");
            }
            strSql.Append("insert into _高开返利核销单_SZ(");
            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());
        }
Ejemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView返利单.FocusedRowHandle -= 1;
                    gridView返利单.FocusedRowHandle += 1;
                }
                catch { }

                if (txt开票金额.Text.Trim() == "" && BaseFunction.ReturnDecimal(txt开票金额.Text.Trim()) == 0)
                {
                    txt开票金额.Focus();
                    throw new Exception("请设置开票金额");
                }


                if (txt考核金额.Text.Trim() == "" && BaseFunction.ReturnDecimal(txt考核金额.Text.Trim()) == 0)
                {
                    txt考核金额.Focus();
                    throw new Exception("请设置考核金额");
                }

                if (txt费率.Text.Trim() == "" && BaseFunction.ReturnDecimal(txt费率.Text.Trim()) == 0)
                {
                    txt费率.Focus();
                    throw new Exception("请设置费率");
                }

                int    iCou   = 0;
                string sErr   = "";
                string s_Guid = Guid.NewGuid().ToString();

                Guid sGuid = Guid.NewGuid();

                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    int    iCode = 0;
                    string sSQL  = "";
                    if (txt单据号.Text.Trim() != "")
                    {
                        sSQL = @"
select * from [dbo].[_高开返利核销单_SZ] where cCode = '{0}' 
";
                        sSQL = string.Format(sSQL, txt单据号.Text.Trim());
                        DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dt == null || dt.Rows.Count == 0)
                        {
                            iCode = 0;
                        }
                        else
                        {
                            if (dt.Rows[0]["auditUid"].ToString().Trim() != "")
                            {
                                throw new Exception("单据已经审核");
                            }

                            sSQL = @"
delete [_高开返利核销单_SZ] where cCode = '{0}' 
";
                            sSQL = string.Format(sSQL, txt单据号.Text.Trim());
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }

                    sSQL = @"
select max(cCode) as cCodeMax from [dbo].[_高开返利核销单_SZ] where cCode like '{0}%'
";
                    sSQL = string.Format(sSQL, dtm.DateTime.ToString("yyyyMM"));
                    DataTable dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtCode == null || dtCode.Rows.Count == 0 || dtCode.Rows[0]["cCodeMax"].ToString().Trim() == "")
                    {
                        iCode = 1;
                    }
                    else
                    {
                        string sCodeTemp = dtCode.Rows[0]["cCodeMax"].ToString().Trim();
                        string stemp     = sCodeTemp.Substring(6);
                        iCode = BaseFunction.ReturnInt(stemp) + 1;
                    }

                    string sCode = iCode.ToString().Trim();
                    sCode = dtm.DateTime.ToString("yyyyMM") + sCode.PadLeft(4, '0');

                    for (int i = 0; i < gridView返利单.RowCount; i++)
                    {
                        if (!BaseFunction.ReturnBool(gridView返利单.GetRowCellValue(i, gridColbchoose)))
                        {
                            continue;
                        }

                        Model._高开返利核销单_SZ model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._高开返利核销单_SZ();
                        model.DLS = lookUpEditcCusCode.EditValue.ToString().Trim();
                        if (lookUpEdit区域.EditValue != null)
                        {
                            model.QY = lookUpEdit区域.EditValue.ToString().Trim();
                        }
                        model.cCode     = sCode;
                        model.dtmDate   = DateTime.Today;
                        model.dMoney_kh = BaseFunction.ReturnDecimal(txt考核金额.Text.Trim());
                        model.dMoney_fl = BaseFunction.ReturnDecimal(txt费率.Text.Trim());
                        model.dMoney_kp = BaseFunction.ReturnDecimal(txt开票金额.Text.Trim());


                        model.FLD_iID = BaseFunction.ReturnLong(gridView返利单.GetRowCellValue(i, gridColFLD_iID));


                        model.FLD_cCode = gridView返利单.GetRowCellValue(i, gridColcCode).ToString().Trim();
                        model.FLD_Money = model.dMoney_kh; BaseFunction.ReturnDecimal(gridView返利单.GetRowCellValue(i, gridCol返利金额));
                        model.createUid = sUserID;
                        model.dtmCreate = DateTime.Now;
                        model.GUID      = sGuid;
                        model.DLS       = gridView返利单.GetRowCellValue(i, gridCol代理商编码).ToString().Trim();
                        model.Remark    = txt备注.Text.Trim();

                        DAL._高开返利核销单_SZ dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._高开返利核销单_SZ();
                        sSQL  = dal.Add(model);
                        iCou += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

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

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

                        MessageBox.Show("保存成功\n单据号:" + sCode);
                        txt单据号.Text = sCode;

                        SetEnable(false);
                    }
                    else
                    {
                        throw new Exception("请选择需要保存的数据");
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "保存失败";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }