public void UpdateBookReturn(Entities.booktran btTran, int TransID)
 {
     Entities.LibEntities dbCtx    = new Entities.LibEntities();
     Entities.booktran    bkUpdate = dbCtx.booktrans.First(b => b.TRANSID == TransID);
     bkUpdate.TRANSID    = btTran.TRANSID;
     bkUpdate.ReturnDate = btTran.ReturnDate;
     dbCtx.SaveChanges();
 }
 public void UpdateBookTrans(Entities.booktran btTran, int TransID)
 {
     Entities.LibEntities dbCtx    = new Entities.LibEntities();
     Entities.booktran    bkUpdate = dbCtx.booktrans.First(b => b.TRANSID == TransID);
     if (String.IsNullOrEmpty(btTran.MemberID))
     {
         bkUpdate.TRANSID    = btTran.TRANSID;
         bkUpdate.ReturnDate = btTran.ReturnDate;
         //bt.LendRate = Int32.Parse(ds.Rows[0]["LendRate"].ToString());
         bkUpdate.Fine   = btTran.Fine;
         bkUpdate.LibBal = btTran.LibBal;
         bkUpdate.MemBal = btTran.MemBal;
     }
     else
     {
         BaseRepository.CopyPropertyValues(btTran, bkUpdate);
     }
     dbCtx.SaveChanges();
 }
Exemple #3
0
        private void btn_Ret_Trans_Click(object sender, EventArgs e)
        {
            Entities.booktran bt = new Entities.booktran();
            StringBuilder     arBookid = new StringBuilder();
            String            strTemp = "";
            int?      strFine = 0;
            int?      strLendRate = 0;
            int?      strMemBalance = 0; int?strLibBalance = 0;
            bool      isMulLoan = false;
            DataTable ds = new DataTable();

            if (gridTrans.RowCount > 0)
            {
                for (int i = 0; i < gridTrans.RowCount; i++)
                {
                    if (gridTrans[0, i].EditedFormattedValue.ToString().Equals("True"))
                    {
                        isMulLoan = true;
                        ds        = transRep.GetTransIDDetails(Int32.Parse(gridTrans["TransID", i].Value.ToString()));
                        bt.BookID = ds.Rows[0]["BookID"].ToString();
                        if (arBookid.Length == 0)
                        {
                            strTemp = ds.Rows[0]["MemberID"].ToString();
                        }
                        else
                        {
                            if (strTemp != ds.Rows[0]["MemberID"].ToString())
                            {
                                MessageBox.Show("Return processing can be done only for one member at a time");
                                return;
                            }
                        }

                        bt.MemberID = ds.Rows[0]["MemberID"].ToString();
                        if (bt.MemberID.Equals(""))
                        {
                            MessageBox.Show("MemberID cannot be empty");
                            return;
                        }

                        bt.LendDate = DateTime.Parse(ds.Rows[0]["LendDate"].ToString());
                        bt.DueDate  = DateTime.Parse(ds.Rows[0]["DueDate"].ToString());

                        if (dateTransReturn.Checked)
                        {
                            bt.ReturnDate = DateTime.Parse(dateTransReturn.Text);
                        }
                        else
                        {
                            MessageBox.Show("Please specify a Return Date");
                            return;
                        }
                        bt.LendRate = Int32.Parse(ds.Rows[0]["LendRate"].ToString());
                        //DateTime countDate=DateTime.Today-DateTime.Parse(ds.Rows[0]["DueDate"].ToString());
                        //int suggFine = Int32.Parse((DateTime.Today - DateTime.Parse(ds.Rows[0]["DueDate"].ToString())).TotalDays.ToString());
                        //if (suggFine > 0)
                        //suggFine = Int32.Parse(((suggFine / 15) * bt.LendRate*0.75).ToString());
                        //bt.Fine = Int32.Parse(txtTransFine.Text);
                        bt.LibBal = Int32.Parse(txtLibBal.Text);
                        bt.MemBal = Int32.Parse(txtMemBal.Text);

                        //if (!bt.Fine.Equals(""))
                        //strFine = bt.Fine;// +strFine;
                        if (!bt.LendRate.Equals(""))
                        {
                            strLendRate = bt.LendRate + strLendRate;
                        }
                        if (!bt.MemBal.Equals(""))
                        {
                            strMemBalance = bt.MemBal; //+ strMemBalance;
                        }
                        if (!bt.LibBal.Equals(""))
                        {
                            strLibBalance = bt.LibBal; //+ strLibBalance;
                        }
                        //bt.LendRate = "";
                        //bt.Fine = "";
                        //bt.LibBal = "";
                        arBookid.Append(bt.BookID + ",");
                        //updateLoanReturn(bt, false, false);
                    }
                }
                if (isMulLoan)
                {
                    if (arBookid.Length > 0)
                    {
                        arBookid.Remove(arBookid.Length - 1, 1);
                    }
                    if (MessageBox.Show("Books Returned:" + arBookid.ToString() + "\nMemberID:" + bt.MemberID + "\nLend Rate:" + strLendRate + "\nMem Bal:" + strMemBalance + "\nLib Bal:" + strLibBalance, "Confirm Transaction", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        for (int i = 0; i < gridTrans.RowCount; i++)
                        {
                            //int tempID = 0;
                            if (gridTrans[0, i].EditedFormattedValue.ToString().Equals("True"))
                            {
                                Entities.booktran btTran = new booktran();
                                btTran.TRANSID    = Int32.Parse(gridTrans["TransID", i].Value.ToString());
                                btTran.ReturnDate = DateTime.Parse(dateTransReturn.Text);
                                //btTran.Fine = Int32.Parse(txtTransFine.Text);
                                //btTran.LibBal = Int32.Parse(txtLibBal.Text);
                                //btTran.MemBal = Int32.Parse(txtMemBal.Text);
                                transRep.UpdateBookReturn(btTran, Int32.Parse(gridTrans["TransID", i].Value.ToString()));
                                //tempID = i;
                            }
                            //if (tempID > 0)
                            //{
                            //    Entities.booktran btTran = new booktran();
                            //    btTran.TRANSID = Int32.Parse(gridTrans["TransID", tempID].Value.ToString());
                            //    bt.CreatedDate = DateTime.Now;
                            //    btTran.ReturnDate = DateTime.Parse(dateTransReturn.Text);
                            //    btTran.Fine = Int32.Parse(txtTransFine.Text);
                            //    btTran.LibBal = Int32.Parse(txtLibBal.Text);
                            //    btTran.MemBal = Int32.Parse(txtMemBal.Text);
                            //    transRep.UpdateBookTrans(btTran, Int32.Parse(gridTrans["TransID", tempID].Value.ToString()));
                            //}
                        }
                        gridTrans.DataSource = transRep.GetTransDetails();
                        gridTrans.Refresh();
                    }
                }
            }
        }
 public void InsertBookTrans(Entities.booktran tranObj)
 {
     Entities.LibEntities dbCtx = new Entities.LibEntities();
     dbCtx.booktrans.Add(tranObj);
     dbCtx.SaveChanges();
 }
Exemple #5
0
        private void btnLoan_Ret_Trans_Click(object sender, EventArgs e)
        {
            Entities.booktran bt = new Entities.booktran();

            StringBuilder arBookid = new StringBuilder();

            String strTemp     = "";
            int?   strFine     = 0;
            int?   strLendRate = 0;
            int?   strBalance  = 0;
            bool   isMulLoan   = false;

            if (gridTrans.RowCount > 0)
            {
                for (int i = 0; i < gridTrans.RowCount; i++)
                {
                    if (gridTrans[0, i].EditedFormattedValue.ToString().Equals("True"))
                    {
                        isMulLoan = true;
                        bt.BookID = gridTrans["BookID", i].Value.ToString();
                        if (arBookid.Length == 0)
                        {
                            strTemp = gridTrans["MemberID", i].Value.ToString();
                        }
                        else
                        {
                            if (strTemp != gridTrans["MemberID", i].Value.ToString())
                            {
                                MessageBox.Show("Loan processing can be done only for one member at a time");
                                return;
                            }
                        }

                        bt.MemberID = gridTrans["MemberID", i].Value.ToString();


                        if (bt.MemberID.Equals(""))
                        {
                            MessageBox.Show("MemberID cannot be empty");
                            return;
                        }

                        if (Int32.Parse(memRep.GetMemberIDDetails(bt.MemberID).Rows[0]["Status"].ToString()) < 1)
                        {
                            if (MessageBox.Show("Do you want to continue?", "Inactive Member", MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                return;
                            }
                        }
                        bt.LendDate = DateTime.Parse(gridTrans["LendDate", i].Value.ToString());
                        bt.DueDate  = DateTime.Parse(gridTrans["DueDate", i].Value.ToString());

                        if (dateTransReturn.Checked)
                        {
                            MessageBox.Show("You cannot specify Return date for Loan Processing");
                            return;
                        }

                        if (transRep.GetLoanDetailsBooksMem(bt.BookID, bt.MemberID, true).Rows.Count > 0)
                        {
                            MessageBox.Show("Bookid " + bt.BookID + " already loaned out");
                            return;
                        }

                        if (transRep.GetLoanDetailsBooksMem(bt.BookID, bt.MemberID).Rows.Count > 0)
                        {
                            if (MessageBox.Show("Do you want to continue?", bt.BookID + " already read by member", MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                return;
                            }
                        }

                        bt.LendRate    = Int32.Parse(gridTrans["LendRate", i].Value.ToString());
                        bt.Fine        = Int32.Parse(gridTrans["Fine", i].Value.ToString());
                        bt.LibBal      = Int32.Parse(gridTrans["LibBal", i].Value.ToString());
                        bt.MemBal      = Int32.Parse(gridTrans["MemBal", i].Value.ToString());
                        bt.RenewalDays = Int32.Parse(gridTrans["RenewalDays", i].Value.ToString());

                        if (!bt.Fine.Equals(""))
                        {
                            strFine = bt.Fine + strFine;
                        }
                        if (!bt.LendRate.Equals(""))
                        {
                            strLendRate = bt.LendRate + strLendRate;
                        }
                        if (!bt.MemBal.Equals(""))
                        {
                            strBalance = bt.MemBal + strBalance;
                        }

                        arBookid.Append(bt.BookID + ",");
                        //updateLoanReturn(bt, false, false);
                    }
                }
                if (isMulLoan)
                {
                    if (arBookid.Length > 0)
                    {
                        arBookid.Remove(arBookid.Length - 1, 1);
                    }
                    if (MessageBox.Show("Books Loaned:" + arBookid.ToString() + "\nMemberID:" + bt.MemberID + "\nLend Rate:" + strLendRate + "\nFine:" + strFine + "\nBalance:" + strBalance, "Confirm Transaction", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        for (int i = 0; i < gridTrans.RowCount; i++)
                        {
                            if (gridTrans[0, i].EditedFormattedValue.ToString().Equals("True"))
                            {
                                bt.BookID   = gridTrans["BookID", i].Value.ToString();
                                bt.MemberID = gridTrans["MemberID", i].Value.ToString();
                                bt.LendDate = DateTime.Parse(gridTrans["LendDate", i].Value.ToString());
                                bt.DueDate  = DateTime.Parse(gridTrans["DueDate", i].Value.ToString());
                                //bt.ReturnDate = DateTime.Parse(dateTransReturn.Text).ToShortDateString();
                                bt.CreatedDate = DateTime.Now;
                                bt.LendRate    = Int32.Parse(gridTrans["LendRate", i].Value.ToString());
                                bt.Fine        = Int32.Parse(gridTrans["Fine", i].Value.ToString());
                                bt.LibBal      = Int32.Parse(gridTrans["LibBal", i].Value.ToString());
                                bt.MemBal      = Int32.Parse(gridTrans["MemBal", i].Value.ToString());
                                bt.RenewalDays = Int32.Parse(gridTrans["RenewalDays", i].Value.ToString());
                                transRep.InsertBookTrans(bt);
                            }
                        }
                        gridTrans.DataSource = transRep.GetTransDetails();
                        gridTrans.Refresh();
                        //bt.LendDate = "";
                        //bt.DueDate = "";
                        //bt.ReturnDate = "";
                        //LibBookTrans lbt = new LibBookTrans();
                        //lbt.displayTrans(bt, gridTrans);
                    }
                }
                //else
                //{
                //    if (dateTransReturn.Checked)
                //    {
                //        MessageBox.Show("You cannot specify Return date for Loan Processing");
                //        return;
                //    }

                //    if (transRep.GetLoanDetailsBooksMem(bt.BookID, bt.MemberID, true).Rows.Count > 0)
                //    {
                //        MessageBox.Show("Bookid " + txtTransBookid.Text + " already loaned out");
                //        return;
                //    }
                //    if (MessageBox.Show("Books Loaned:" + txtTransBookid.Text + "\nMemberID:" + txtTransMemId.Text + "\nLend Rate:" + txtTransLendRate.Text + "\nFine:" + txtTransFine.Text + "\nBalance:" + txtMemBal.Text + "\nRenewal Days:" + txtRenewal.Text, "Confirm Transaction", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //    {
                //        bt.BookID = txtTransBookid.Text.ToString();
                //        bt.MemberID = txtTransMemId.Text;
                //        bt.LendDate = DateTime.Parse(dateTransLoan.Text);
                //        bt.DueDate = DateTime.Parse(dateTransDue.Text);
                //        bt.LendRate = Int32.Parse(txtTransLendRate.Text);
                //        bt.Fine = Int32.Parse(txtTransFine.Text);
                //        bt.LibBal = Int32.Parse(txtLibBal.Text);
                //        bt.MemBal = Int32.Parse(txtMemBal.Text);
                //        //bt.MemBal=txt
                //        bt.RenewalDays = Int32.Parse(txtRenewal.Text);
                //        transRep.InsertBookTrans(bt);
                //        gridTrans.DataSource = transRep.GetTransLoanDetails(bt.MemberID);
                //        //updateLoanReturn(bt, false, true);

                //        //bt.LendDate = "";
                //        //bt.DueDate = "";
                //        //bt.ReturnDate = "";

                //        //LibBookTrans lbt = new LibBookTrans();
                //        //lbt.displayTrans(bt, gridTrans);
                //    }
                //}
            }
        }