Example #1
0
        protected void btnSave_ServerClick(object sender, System.EventArgs e)
        {
            try
            {
                string Hint        = "";
                int    parentLayer = 0;

                if (!CheckValid(ref Hint, ref parentLayer))
                {
                    Response.Write(Rms.Web.JavaScript.Alert(true, Hint));
                    return;
                }

                string subjectCode    = this.txtSubjectCode.Value;
                string subjectSetCode = this.txtSubjectSetCode.Value;

                EntityData entity = SubjectDAO.GetSubjectByCode(this.txtOldSubjectCode.Value, subjectSetCode);
                DataRow    dr     = null;
                bool       IsNew  = false;

                if (entity.HasRecord())
                {
                    IsNew = false;
                    dr    = entity.CurrentRow;

                    //修改主键时,先删除,再新增
                    if (this.txtSubjectCode.Value != this.txtOldSubjectCode.Value)
                    {
                        dr.Delete();

                        IsNew = true;
                        dr    = entity.GetNewRecord();
                        dr["SubjectSetCode"] = subjectSetCode;
                    }
                }
                else
                {
                    IsNew = true;
                    dr    = entity.GetNewRecord();
                    dr["SubjectSetCode"] = subjectSetCode;
                }

                dr["SubjectName"] = this.txtSubjectName.Value;
                dr["SubjectCode"] = this.txtSubjectCode.Value;
                dr["Layer"]       = parentLayer + 1;

                if (this.CheckBoxIsDebit.Checked == true)
                {
                    dr["IsDebit"] = 1;
                }
                else
                {
                    dr["IsDebit"] = 0;
                }

                if (this.CheckBoxIsCrebit.Checked == true)
                {
                    dr["IsCrebit"] = 1;
                }
                else
                {
                    dr["IsCrebit"] = 0;
                }

                if (IsNew)
                {
                    entity.AddNewRecord(dr);
                }

                SubjectDAO.SubmitAllSubject(entity);
                this.txtOldSubjectCode.Value = this.txtSubjectCode.Value;

                entity.Dispose();
            }
            catch (Exception ex)
            {
                Response.Write(JavaScript.Alert(true, "保存失败:" + ex.Message));
                ApplicationLog.WriteLog(this.ToString(), ex, "");
                return;
            }

            GoBack();
        }