protected void Button2_Click(object sender, EventArgs e) { var folder = Server.MapPath("~/Images/company/"); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } bId = Convert.ToInt32(ViewState["bid"]); string dgImg; try { if (FileUpload1.FileName != "") { dgImg = Server.MapPath(@"Images/company/" + FileUpload1.FileName); FileUpload1.SaveAs(dgImg); } using (AdvInvSystemEntities comp = new AdvInvSystemEntities()) { Brand bd = new Brand(); bd = (from b in comp.Brands where b.BrandId == bId select b).FirstOrDefault(); bd.CompanyName = compNm.Text; bd.ContactPerson = compPers.Text; bd.ContactNumber = cellNm.Text; if (FileUpload1.FileName != "") { bd.Logo = "images/company/" + FileUpload1.FileName; } comp.SaveChanges(); } Response.Redirect(Request.RawUrl); } catch (Exception) { } }
protected void Button1_Click(object sender, EventArgs e) { using (AdvInvSystemEntities dbobj = new AdvInvSystemEntities()) { Customer cs = new Customer(); cs.CustomerName = NmTxt.Text; cs.CellNumber = CellTxt.Text; cs.Address = AddTxt.Text; cs.Balance = Convert.ToInt32(BalTxt.Text); cs.Type = DropDownList1.SelectedItem.Value; dbobj.Customers.Add(cs); dbobj.SaveChanges(); } NmTxt.Text = ""; CellTxt.Text = ""; AddTxt.Text = ""; BalTxt.Text = "0"; }
protected void updateBtn_Click(object sender, EventArgs e) { if (PMDropdownlist.SelectedIndex != 0 && ProductList.SelectedIndex != 0) { prodId = Convert.ToInt32(ViewState["ProdId"]); locId = Convert.ToInt32(PMDropdownlist.SelectedItem.Value); try { using (AdvInvSystemEntities dbobj = new AdvInvSystemEntities()) { if (Qnty.Text != "") { var prodStock = (from pd in dbobj.Stocks where pd.ProductId == prodId && pd.LocationId == locId select pd).FirstOrDefault(); prodStock.Quantity += Convert.ToInt32(Qnty.Text); dbobj.SaveChanges(); Product pd1 = new Product(); pd1 = (from p in dbobj.Products where p.ProductId == prodId select p).FirstOrDefault(); if (SPrice.Text != "") { pd1.SalePrice = Convert.ToInt32(SPrice.Text); } if (PPrice.Text != "") { pd1.PurchasePrice = Convert.ToInt32(PPrice.Text); } dbobj.SaveChanges(); AddStock addSt = new AddStock(); addSt.Quantity = Convert.ToInt32(Qnty.Text); addSt.ProductId = prodId; if (SPrice.Text != "") { addSt.SalePrice = Convert.ToInt32(SPrice.Text); } if (PPrice.Text != "") { addSt.PurcPrice = Convert.ToInt32(PPrice.Text); } addSt.UserId = Convert.ToInt32(Session["UserId"]); TimeZoneInfo tzi; DateTime dtTz; tzi = TimeZoneInfo.FindSystemTimeZoneById("Pakistan Standard Time"); dtTz = TimeZoneInfo.ConvertTime(DateTime.Now, tzi); addSt.Time = dtTz.ToString("h:mm:ss tt"); addSt.Date = System.DateTime.Now; addSt.BranchId = locId; dbobj.AddStocks.Add(addSt); dbobj.SaveChanges(); } } } catch (Exception ex) { } Response.Redirect(Request.RawUrl); } }