Example #1
0
        public bool InsertAdjustmentVoucher(adjustmentvoucher header, List<adjustmentvoucherdetail> details)
        {
            try
            {

                //creating a adjustmentvoucherheader
                entity.adjustmentvouchers.Add(header);
                entity.SaveChanges();

                //creating adjustmentdetails
                foreach (adjustmentvoucherdetail d in details)
                {
                    int tranID = d.ADVID;
                    d.ADVID = header.ADVID;
                    entity.adjustmentvoucherdetails.Add(d);

                     //Update Transaction
                    var query = from t in entity.transactions
                                where t.TransItemID == d.ADVItemID && t.TransID == tranID
                                select t;
                    transaction tran = query.FirstOrDefault();
                    tran.TransCode = "ADF";

                    entity.SaveChanges();
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                AdjustmentService service = new AdjustmentService();
                adjustmentvoucher adjVoucher = new adjustmentvoucher();

                adjVoucher.ADVDate = DateTime.Today;
                int userID = Convert.ToInt32(Session["userid"].ToString());
                adjVoucher.ADVIOrderByEmpID = userID;
               // adjVoucher.ADVApprovedByEMpID = 2;
                adjVoucher.ADVStatus = "Pending";
                double totalPrice = 0;
                List<adjustmentvoucherdetail> detailList = new List<adjustmentvoucherdetail>();

                foreach (GridViewRow i in dgvAdjustmentVoucher.Rows)
                {
                    adjustmentvoucherdetail adjVoucher_details = new adjustmentvoucherdetail();
                    adjVoucher_details.ADVID = Convert.ToInt32(i.Cells[6].Text.ToString());
                    adjVoucher_details.ADVItemID = Convert.ToInt32(i.Cells[0].Text.ToString());
                    adjVoucher_details.ADVItemUnitCost = 0;
                    adjVoucher_details.ADVQuantAdj = Convert.ToInt32(i.Cells[2].Text.ToString());

                    TextBox t = (TextBox)i.FindControl("txtReason");
                    int itemafter = Convert.ToInt32(i.Cells[5].Text.ToString());
                    int quantbefore = itemafter + adjVoucher_details.ADVQuantAdj;
                    adjVoucher_details.ADVReason = t.Text.ToString();
                    adjVoucher_details.ADVItemUnitCost = Convert.ToInt32(i.Cells[3].Text.ToString());
                    adjVoucher_details.ADVQuantBefore = quantbefore;
                    adjVoucher_details.ADVQuantAfter = Convert.ToInt32(i.Cells[5].Text.ToString());
                    adjVoucher_details.ADVAdjustedCost = Convert.ToInt32(i.Cells[4].Text.ToString());

                    detailList.Add(adjVoucher_details);

                    totalPrice = totalPrice + adjVoucher_details.ADVAdjustedCost;
                }

                service.saveAdjustmentVoucher(adjVoucher, detailList ,totalPrice);

                Response.Redirect("ViewStockAdjustmentList.aspx");

            }
            catch (Exception ex)
            {
                Label1.Text = "Un expected error occurs! please contact to admin";
            }
        }
Example #3
0
        public bool saveAdjustmentVoucher(adjustmentvoucher a ,List<adjustmentvoucherdetail> d ,double totalprice)
        {
            try
            {
                rep.InsertAdjustmentVoucher(a, d);

                if (totalprice < 250)
                {
                    List<storeemp> supervisors = selectStoreSupervisor();
                    foreach (storeemp emp in supervisors)
                    {
                        MailMessage mail = new MailMessage();
                        mail.From = new MailAddress("*****@*****.**");
                        //mail.To.Add(new MailAddress(emailID));
                        mail.To.Add(new MailAddress(emp.StoreEmpEmail));
                        mail.Subject = "Adjustment Voucher :";
                        String Header = "<head>"
                                + "<title>Adjustment voucher to approve</title>"
                                + "<meta charset=\"UTF-8\">"
                                + " <meta name=\"viewport\" content=\"width=device-width\">"
                                + " <link rel=\"stylesheet\" href=\"http://bootswatch.com/flatly/bootstrap.css\">"
                                + " <link rel=\"stylesheet\" href=\"http://bootswatch.com/assets/css/bootswatch.min.css\">"
                                + " </head>";
                        String BodyStart = "<body>";
                        String BodyContent = "There is new adjustment voucher to approve.";
                        String BodyEnd = "</body>";

                        mail.Body = Header + BodyStart + BodyContent + BodyEnd;

                        mail.IsBodyHtml = true;

                        SmtpClient sc = new SmtpClient();
                        sc.Host = "smtp.gmail.com";
                        sc.Port = 25;
                        sc.Credentials = new System.Net.NetworkCredential("*****@*****.**", "12345678!");
                        sc.EnableSsl = true;
                        sc.Send(mail);
                    }
                }
                else if (totalprice >= 250)
                {
                    storeemp manager = selectManager();
                    MailMessage mail = new MailMessage();
                    mail.From = new MailAddress("*****@*****.**");
                    //mail.To.Add(new MailAddress(emailID));
                    mail.To.Add(new MailAddress(manager.StoreEmpEmail));
                    mail.Subject = "Adjustment Voucher:";
                    String Header = "<head>"
                            + "<title>Adjustment voucher to approve</title>"
                            + "<meta charset=\"UTF-8\">"
                            + " <meta name=\"viewport\" content=\"width=device-width\">"
                            + " <link rel=\"stylesheet\" href=\"http://bootswatch.com/flatly/bootstrap.css\">"
                            + " <link rel=\"stylesheet\" href=\"http://bootswatch.com/assets/css/bootswatch.min.css\">"
                            + " </head>";
                    String BodyStart = "<body>";
                    String BodyContent = "There is new adjustment voucher to approve.";
                    String BodyEnd = "</body>";

                    mail.Body = Header + BodyStart + BodyContent + BodyEnd;

                    mail.IsBodyHtml = true;

                    SmtpClient sc = new SmtpClient();
                    sc.Host = "smtp.gmail.com";
                    sc.Port = 25;
                    sc.Credentials = new System.Net.NetworkCredential("*****@*****.**", "12345678!");
                    sc.EnableSsl = true;
                    sc.Send(mail);

                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }