示例#1
0
        public int SaveGeneral()
        {
            int        Row = 0;
            DBCon      con = new DBCon();
            SqlCommand cmd = null;

            Accounts ACDetails = Accounts.GetAll().Where(w => (w.ACRLedgerId == CRLedgerId ||
                                                               w.ACRLedgerId == DRLedgerId) && w.EntryType == Entrytype).LastOrDefault();

            if (ACDetails != null)
            {
                EntryNo = ACDetails.EntryNo + 1;
            }
            else
            {
                EntryNo = EntryNo + 1;
            }
            Ledger LedgerDetails = Ledger.GetAll().Where(w => w.ID == CRLedgerId ||
                                                         w.ID == DRLedgerId).FirstOrDefault();

            if (CRAmount > 0)
            {
                CRLedgerId = CRLedgerId;
                DRLedgerId = 0;
            }
            else
            {
                DRLedgerId = CRLedgerId;
                CRLedgerId = 0;
            }

            if (this.Entrytype == "1")
            {
                this.Entrytype = "Payment";
            }
            if (this.Entrytype == "2")
            {
                this.Entrytype = "Receipt";
            }
            if (this.Entrytype == "3")
            {
                this.Entrytype = "Contra Entry";
            }
            if (this.Entrytype == "4")
            {
                this.Entrytype = "Journal Entry";
            }
            if (this.Entrytype == "5")
            {
                this.Entrytype = "Sale";
            }
            if (this.Entrytype == "6")
            {
                this.Entrytype = "Purchase";
            }

            try
            {
                string Quary = "";
                if (this.AID == 0)
                {
                    Quary = "Insert Into ACAccount Values (@Date,@DRAmount,@CRAmount,@Narration,@Balance,@CRGroupId,@OrgId,@DRGroupId,@CRLedgerId,@DRLedgerId,@EntryNo,@EntryType,@ReceiptID);SELECT SCOPE_IDENTITY();";
                }
                else
                {
                    Quary = "Update ACAccount Set Date=@Date,DRAmount=@DRAmount,CRAmount=@CRAmount,Narration=@Narration,Balance=@Balance,CRGroupId=@CRGroupId,OrgId=@OrgId,DRGroupId=@DRGroupId,CRLedgerId=@CRLedgerId,DRLedgerId=@DRLedgerId,EntryNo=@EntryNo,EntryType=@EntryType,ReceiptID=@ReceiptID where AID=@AID";
                }
                cmd = new SqlCommand(Quary, con.Con);
                cmd.Parameters.AddWithValue("@AID", this.AID);
                cmd.Parameters.AddWithValue("@Date", this.Date);
                cmd.Parameters.AddWithValue("@DRAmount", this.DRAmount);
                cmd.Parameters.AddWithValue("@CRAmount", this.CRAmount);
                cmd.Parameters.AddWithValue("@Narration", this.Narration);
                cmd.Parameters.AddWithValue("@Balance", this.Balance);
                cmd.Parameters.AddWithValue("@CRGroupId", LedgerDetails.ParentGroup);
                cmd.Parameters.AddWithValue("@OrgId", LedgerDetails.OrgId);
                cmd.Parameters.AddWithValue("@DRGroupId", LedgerDetails.ParentGroup);
                cmd.Parameters.AddWithValue("@CRLedgerId", this.CRLedgerId);
                cmd.Parameters.AddWithValue("@DRLedgerId", this.DRLedgerId);
                cmd.Parameters.AddWithValue("@EntryNo", this.EntryNo);
                cmd.Parameters.AddWithValue("@EntryType", this.Entrytype);
                cmd.Parameters.AddWithValue("@ReceiptID", this.ReceiptID);


                if (this.AID == 0)
                {
                    Row      = Convert.ToInt32(cmd.ExecuteScalar());
                    this.AID = Row;
                }
                else
                {
                    Row = cmd.ExecuteNonQuery();
                    //this.CategoryID = Row;
                }
            }
            catch (Exception e) { e.ToString(); }
            finally { cmd.Dispose(); con.Con.Close(); }
            return(Row);
        }