Пример #1
0
        public void LoadByPK(string id)
        {
            string sSql = "SELECT * FROM [Ledger] WHERE sLedgerId = @id";

            using (SqlCommand cmd = new SqlCommand(sSql, LocalAccess.l_Connection))
            {
                cmd.Parameters.Add(new SqlParameter("id", id));
                DataTable dt = new DataTable();
                using (SqlDataAdapter adp = new SqlDataAdapter(cmd))
                    adp.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    this.sLedgerId    = "" + dt.Rows[0]["sLedgerId"];
                    this.sCompanyCode = "" + dt.Rows[0]["sCompanyCode"];
                    this.dtLedgerDate = Convert.ToDateTime(dt.Rows[0]["dtLedgerDate"]);
                    this.sLedgerDocu  = "" + dt.Rows[0]["sLedgerDocu"];
                    this.sLedgerDesc  = "" + dt.Rows[0]["sLedgerDesc"];
                    this.LedgerRef    = "" + dt.Rows[0]["sLedgerRef"];
                    dtls = new List <LedgerDtlBL>();

                    sSql = "SELECT * FROM [LedgerDtl] WHERE sLedgerId = @id";
                    using (SqlCommand cmd2 = new SqlCommand(sSql, LocalAccess.l_Connection))
                    {
                        cmd2.Parameters.Add(new SqlParameter("id", id));
                        DataTable dt2 = new DataTable();
                        using (SqlDataAdapter adp = new SqlDataAdapter(cmd2))
                            adp.Fill(dt2);
                        foreach (DataRow dr2 in dt2.Rows)
                        {
                            LedgerDtlBL dtl = new LedgerDtlBL();
                            dtl.LedgerId          = "" + dr2["sLedgerId"];
                            dtl.AccountCode       = "" + dr2["sAccountCode"];
                            dtl.LedgerDescription = "" + dr2["sLedgerDescription"];
                            dtl.LedgerDebit       = Convert.ToDouble(dr2["nLedgerDebit"]);
                            dtl.LedgerCredit      = Convert.ToDouble(dr2["nLedgerCredit"]);
                            dtl.LedgerAmount      = Convert.ToDouble(dr2["nLedgerAmount"]);
                            dtls.Add(dtl);
                        }
                    }
                }
                else
                {
                    this.sLedgerId    = "";
                    this.sCompanyCode = "";
                    this.dtLedgerDate = new DateTime(1900, 1, 1);
                    this.sLedgerDocu  = "";
                    this.sLedgerDesc  = "";
                    this.LedgerRef    = "";
                    dtls = new List <LedgerDtlBL>();
                }
            }
        }
Пример #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateEntry())
            {
                return;
            }

            Layer.LedgerBL BL = new Layer.LedgerBL();

            if (this._IsAdd)
            {
                BL.LedgerId = DateTime.Now.ToString("yyyyMMddHHmmss");
            }
            else
            {
                BL.LedgerId = this.sLedgerId;
            }
            BL.CompanyCode = LocalAccess.l_CompanyCode;
            BL.LedgerDate  = Convert.ToDateTime(txtDate.Text);
            BL.LedgerDocu  = txtDocu.Text.Trim();
            BL.LedgerDesc  = txtDesc.Text.Trim();
            BL.LedgerRef   = txtRef.Text.Trim();

            BL.dtls = new List <Layer.LedgerDtlBL>();
            foreach (DataGridViewRow dr in grdDetail.Rows)
            {
                if (dr.IsNewRow)
                {
                    continue;
                }
                Layer.LedgerDtlBL dtl = new Layer.LedgerDtlBL();
                dtl.LedgerId          = BL.LedgerId;
                dtl.AccountCode       = "" + dr.Cells["cAccount"].Value;
                dtl.LedgerDescription = "" + dr.Cells["cDescription"].Value;
                dtl.LedgerDebit       = 0;
                dtl.LedgerCredit      = 0;
                dtl.LedgerAmount      = 0;
                try { dtl.LedgerDebit = Convert.ToDouble(dr.Cells["cDebit"].Value); }
                catch { }
                try { dtl.LedgerCredit = Convert.ToDouble(dr.Cells["cCredit"].Value); }
                catch { }
                try { dtl.LedgerAmount = Convert.ToDouble(dr.Cells["cAmount"].Value); }
                catch { }
                BL.dtls.Add(dtl);
            }
            if (this._IsAdd)
            {
                if (BL.Exist())
                {
                    MessageBox.Show("Document already exist.", "Add Ledger");
                    return;
                }
                BL.Insert();
                frmList.LoadEntry();
                //FormNew();
                txtDate.Focus();
                LoadDescriptionList();
                MessageBox.Show("Record Saved");
            }
            else
            {
                BL.UpdateByPK();
                this.Close();
                frmList.LoadEntry();
            }
        }