Exemple #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            AGRODataContext db = new AGRODataContext(Server.MapPath("\\"));

            Inventory a = new Inventory()
            {
                IName  = TextBox5.Text,
                Count  = Convert.ToInt32(TextBox2.Text),
                Price  = Convert.ToDouble(TextBox3.Text),
                MPrice = Convert.ToDouble(TextBox4.Text)
            };

            db.Inventory.InsertOnSubmit(a);

            try
            {
                db.SubmitChanges();
                BindGrid();
            }

            catch (Exception exception)
            {
                Debug.WriteLine($"Somethig wrong: {exception.Message}");
            }
        }
        protected void WorkersTable_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Debug.WriteLine("WorkersTable_RowDeleting");

            if (e.Keys.Contains("IdW"))
            {
                var selectedWorkerId = (int)e.Keys["IdW"];
                Debug.WriteLine($"selectedWorkerId = {selectedWorkerId}");

                using (var db = new AGRODataContext(Server.MapPath("\\")))
                {
                    var deletingEntity = db.Workers.FirstOrDefault(w => w.IdW == selectedWorkerId);

                    if (deletingEntity != null)
                    {
                        db.Workers.DeleteOnSubmit(deletingEntity);
                        try
                        {
                            db.SubmitChanges();
                            BindGrid();
                        }
                        catch (Exception exception)
                        {
                            Debug.WriteLine($"Somethig wrong: {exception.Message}");
                        }
                    }
                }
            }
        }
Exemple #3
0
        protected void Button6_Click(object sender, EventArgs e)
        {
            bool isAuth;

            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                isAuth = db.Workers.Any(w => w.Login == LoginTbx.Text && w.Password == PwdTbx.Text);
            }

            if (isAuth)
            {
                Button1.Visible = true;
                Button2.Visible = true;
                Button3.Visible = true;
                Button4.Visible = true;
                Button5.Visible = true;
                Label2.Visible  = false;
                Auto.GetAuth().SetKey(true);
                LoginForm.Style.Add("display", "none");
            }
            else
            {
                Label2.Visible = true;
                Nonauto();
                Auto.GetAuth().SetKey(false);
            }
        }
Exemple #4
0
        protected void InventoryTable_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
        {
            Debug.WriteLine("InventoryTable_RowDeleting");

            if (e.Keys.Contains("IdI"))
            {
                var selectedInventoryId = (int)e.Keys["IdI"];
                Debug.WriteLine($"selectedInventoryId = {selectedInventoryId}");

                using (var db = new AGRODataContext(Server.MapPath("\\")))
                {
                    var deletingEntity = db.Inventory.FirstOrDefault(i => i.IdI == selectedInventoryId);

                    if (deletingEntity != null)
                    {
                        db.Inventory.DeleteOnSubmit(deletingEntity);
                        try
                        {
                            db.SubmitChanges();
                            BindGrid();
                        }
                        catch (Exception exception)
                        {
                            Debug.WriteLine($"Somethig wrong: {exception.Message}");
                        }
                    }
                }
            }
        }
 protected void Button2_Click(object sender, EventArgs e)
 {
     using (var db = new AGRODataContext(Server.MapPath("\\")))
     {
         var totals = db.Workers.Sum(w => w.Wage);
         TotalSalaryTbx.Text = totals.ToString();
     }
 }
 protected void Button2_Click(object sender, EventArgs e)
 {
     using (var db = new AGRODataContext(Server.MapPath("\\")))
     {
         var totals = db.Animals.Sum(a => a.MarketPrice * a.Count);
         TextBox4.Text = totals.ToString();
     }
 }
        protected void WorkersTable_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Debug.WriteLine("WorkersTable_RowUpdating");

            var rowIdx = e.RowIndex;

            if (e.Keys.Contains("IdW"))
            {
                var updatingWorkerId = (int)e.Keys["IdW"];
                Debug.WriteLine($"updatingWorkerId = {updatingWorkerId}");

                using (var db = new AGRODataContext(Server.MapPath("\\")))
                {
                    var updatingEntity = db.Workers.FirstOrDefault(w => w.IdW == updatingWorkerId);

                    if (updatingEntity != null)
                    {
                        var selectedRow = WorkersTable.Rows[rowIdx];

                        var fNameCtl = selectedRow.Cells[2].Controls[0] as TextBox;
                        var sNameCtl = selectedRow.Cells[3].Controls[0] as TextBox;
                        var tNameCtl = selectedRow.Cells[4].Controls[0] as TextBox;
                        var wageCtl  = selectedRow.Cells[5].Controls[0] as TextBox;
                        var invCtl   = selectedRow.Cells[6].FindControl("InvEditor") as DropDownList;
                        var placeCtl = selectedRow.Cells[7].FindControl("PlaceEditor") as DropDownList;
                        var loginCtl = selectedRow.Cells[8].Controls[0] as TextBox;
                        var pwdCtl   = selectedRow.Cells[9].Controls[0] as TextBox;

                        updatingEntity.FName = fNameCtl?.Text;
                        updatingEntity.TName = tNameCtl?.Text;
                        updatingEntity.SName = sNameCtl?.Text;
                        updatingEntity.Wage  = int.TryParse(wageCtl?.Text, out int _wage) ? _wage : (int?)null;
                        updatingEntity.Inv   = int.TryParse(invCtl?.SelectedValue, out int _inv)
                            ? _inv
                            : (int?)null;

                        updatingEntity.Place = int.TryParse(placeCtl?.SelectedValue, out int _place)
                            ? _place
                            : (int?)null;

                        updatingEntity.Login    = loginCtl?.Text;
                        updatingEntity.Password = pwdCtl?.Text;

                        try
                        {
                            db.SubmitChanges();
                            WorkersTable.EditIndex = -1;
                            BindGrid();
                        }
                        catch (Exception exception)
                        {
                            Debug.WriteLine($"Somethig wrong: {exception.Message}");
                        }
                    }
                }
            }
        }
        protected void Button2_Click1(object sender, EventArgs e)
        {
            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                var totals = db.Places.Sum(p => p.MPrice ?? 0);

                TextBox5.Text = totals.ToString(CultureInfo.InvariantCulture);
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            AGRODataContext db = new AGRODataContext(Server.MapPath("\\"));

            var sum = from w in db.Cultures select w.MarketPrice * w.Count;

            var totals = sum.Sum();

            TextBox4.Text = totals.ToString();
        }
Exemple #10
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            AGRODataContext db = new AGRODataContext(Server.MapPath("\\"));

            var sums = from s in db.Inventory select s.Count * s.MPrice;

            var totals = sums.Sum();

            TextBox1.Text = totals.ToString();
        }
Exemple #11
0
        public void BindGrid(string sortExpression = "", bool isSort = false)
        {
            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                IQueryable <PlaceAndCulture> query = db.Places
                                                     .Join(db.Cultures, p => p.PCulture, c => c.IdC, (p, c) => new PlaceAndCulture {
                    Place = p, Culture = c
                })
                                                     .Join(db.Animals, pc => pc.Place.PAnimals, a => a.IdA, (pc, a) => new PlaceAndCulture {
                    Place = pc.Place, Culture = pc.Culture, Animals = a
                });

                switch (sortExpression)
                {
                case "Pname":
                    query = GetSortExpression(query, pc => pc.Place.Pname, "Pname", isSort);
                    break;

                case "MPrice":
                    query = GetSortExpression(query, pc => pc.Place.MPrice, "MPrice", isSort);
                    break;

                case "PCulture":
                    query = GetSortExpression(query, pc => pc.Culture.Cname, "PCulture", isSort);
                    break;

                case "PAnimals":
                    query = GetSortExpression(query, pc => pc.Animals.AName, "PAnimals", isSort);
                    break;

                default:
                    query = GetSortExpression(query, pc => pc.Place.IdP, "IdP", isSort);
                    break;
                }

                var source = query
                             .Select(x => new
                {
                    Idp        = x.Place.IdP,
                    Pname      = x.Place.Pname,
                    MPrice     = x.Place.MPrice,
                    PCulture   = x.Culture.Cname,
                    PCultuteId = x.Culture.IdC,
                    PAnimals   = x.Animals.AName,
                    PAnimalsId = x.Animals.IdA
                })
                             .ToList();

                PlacesTable.DataSource = source;
                PlacesTable.DataBind();
            }
        }
 protected List <DropDownData> GetInventoryData()
 {
     using (var db = new AGRODataContext(Server.MapPath("\\")))
     {
         var source = db.Inventory.Select(i => new DropDownData
         {
             Id   = i.IdI,
             Text = i.IName
         })
                      .ToList();
         return(source);
     }
 }
Exemple #13
0
 protected List <DropDownData> GetCultureData()
 {
     using (var db = new AGRODataContext(Server.MapPath("\\")))
     {
         var source = db.Cultures.Select(i => new DropDownData
         {
             Id   = i.IdC,
             Text = i.Cname
         })
                      .ToList();
         return(source);
     }
 }
Exemple #14
0
 protected List <DropDownData> GetAnimalsData()
 {
     using (var db = new AGRODataContext(Server.MapPath("\\")))
     {
         var source = db.Animals.Select(i => new DropDownData
         {
             Id   = i.IdA,
             Text = i.AName
         })
                      .ToList();
         return(source);
     }
 }
        protected List <DropDownData> GetDepartmentData()
        {
            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                var source = db.Places.Select(i => new DropDownData
                {
                    Id   = i.IdP,
                    Text = i.Pname
                })
                             .ToList();

                return(source);
            }
        }
Exemple #16
0
        public void BindGrid(string sortExpression = "", bool isSort = false)
        {
            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                IQueryable <Inventory> query = db.Inventory;

                switch (sortExpression)
                {
                case "IdI":
                    query = GetSortExpression(query, i => i.IdI, "IdI", isSort);
                    break;

                case "IName":
                    query = GetSortExpression(query, i => i.IName, "IName", isSort);
                    break;

                case "Price":
                    query = GetSortExpression(query, i => i.Price, "Price", isSort);
                    break;

                case "Count":
                    query = GetSortExpression(query, i => i.Count, "Count", isSort);
                    break;

                case "MPrice":
                    query = GetSortExpression(query, i => i.MPrice, "MPrice", isSort);
                    break;

                default:
                    query = GetSortExpression(query, i => i.IdI, "IdI", isSort);
                    break;
                }

                var source = query
                             .Select(x => new
                {
                    IdI    = x.IdI,
                    IName  = x.IName,
                    Price  = x.Price,
                    Count  = x.Count,
                    MPrice = x.MPrice
                })
                             .ToList();

                InventoryTable.DataSource = source;
                InventoryTable.DataBind();
            }
        }
Exemple #17
0
        protected void PlacesTable_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Debug.WriteLine("PlacesTable_RowUpdating");

            var rowIdx = e.RowIndex;

            if (e.Keys.Contains("IdP"))
            {
                var updatingPlaceId = (int)e.Keys["IdP"];
                Debug.WriteLine($"updatingPlaceId = {updatingPlaceId}");

                using (var db = new AGRODataContext(Server.MapPath("\\")))
                {
                    var updatingEntity = db.Places.FirstOrDefault(p => p.IdP == updatingPlaceId);

                    if (updatingEntity != null)
                    {
                        var selectedRow = PlacesTable.Rows[rowIdx];

                        var pNameCtl   = selectedRow.Cells[2].Controls[0] as TextBox;
                        var mPriceCtl  = selectedRow.Cells[3].Controls[0] as TextBox;
                        var cultureCtl = selectedRow.Cells[4].FindControl("CultureEditor") as DropDownList;
                        var animalsCtl = selectedRow.Cells[5].FindControl("AnimalsEditor") as DropDownList;

                        updatingEntity.Pname    = pNameCtl?.Text;
                        updatingEntity.MPrice   = int.TryParse(mPriceCtl?.Text, out int _mPrice) ? _mPrice : (int?)null;
                        updatingEntity.PCulture = int.TryParse(cultureCtl?.SelectedValue, out int _pCulture)
                            ? _pCulture
                            : (int?)null;
                        updatingEntity.PAnimals = int.TryParse(animalsCtl?.SelectedValue, out int _pAnimals)
                            ? _pAnimals
                            : (int?)null;

                        try
                        {
                            db.SubmitChanges();
                            PlacesTable.EditIndex = -1;
                            BindGrid();
                        }
                        catch (Exception exception)
                        {
                            Debug.WriteLine($"Somethig wrong: {exception.Message}");
                        }
                    }
                }
            }
        }
Exemple #18
0
        protected void InventoryTable_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
        {
            Debug.WriteLine("InventoryTable_RowUpdating");

            var rowIdx = e.RowIndex;

            if (e.Keys.Contains("IdI"))
            {
                var updatingInventoryId = (int)e.Keys["IdI"];
                Debug.WriteLine($"updatingInventoryId = {updatingInventoryId}");

                using (var db = new AGRODataContext(Server.MapPath("\\")))
                {
                    var updatingEntity = db.Inventory.FirstOrDefault(i => i.IdI == updatingInventoryId);

                    if (updatingEntity != null)
                    {
                        var selectedRow = InventoryTable.Rows[rowIdx];

                        var iNameCtl  = selectedRow.Cells[2].Controls[0] as TextBox;
                        var countCtl  = selectedRow.Cells[3].Controls[0] as TextBox;
                        var priceCtl  = selectedRow.Cells[4].Controls[0] as TextBox;
                        var mPriceCtl = selectedRow.Cells[5].Controls[0] as TextBox;

                        updatingEntity.IName = iNameCtl?.Text;
                        updatingEntity.Count = int.TryParse(countCtl?.Text, out int _count) ? _count : (int?)null;
                        updatingEntity.Price = double.TryParse(priceCtl?.Text, out double _price)
                            ? _price
                            : (double?)null;
                        updatingEntity.MPrice = double.TryParse(mPriceCtl?.Text, out double _mPrice)
                            ? _mPrice
                            : (double?)null;

                        try
                        {
                            db.SubmitChanges();
                            InventoryTable.EditIndex = -1;
                            BindGrid();
                        }
                        catch (Exception exception)
                        {
                            Debug.WriteLine($"Somethig wrong: {exception.Message}");
                        }
                    }
                }
            }
        }
        public void BindGrid(string sortExpression = "", bool isSort = false)
        {
            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                IQueryable <Animals> query = db.Animals;

                switch (sortExpression)
                {
                case "IdA":
                    query = GetSortExpression(query, a => a.IdA, "IdA", isSort);
                    break;

                case "AName":
                    query = GetSortExpression(query, a => a.AName, "AName", isSort);
                    break;

                case "MarketPrice":
                    query = GetSortExpression(query, a => a.MarketPrice, "MarketPrice", isSort);
                    break;

                case "Count":
                    query = GetSortExpression(query, a => a.Count, "Count", isSort);
                    break;

                default:
                    query = GetSortExpression(query, a => a.IdA, "IdA", isSort);
                    break;
                }

                var source = query
                             .Select(x => new
                {
                    IdA         = x.IdA,
                    AName       = x.AName,
                    MarketPrice = x.MarketPrice,
                    Count       = x.Count
                })
                             .ToList();

                AnimalsTable.DataSource = source;
                AnimalsTable.DataBind();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                var wage = double.TryParse(SalaryTbx.Text, out double _wage)
                    ? _wage
                    : (double?)null;

                var inv = int.TryParse(InventaryDropDown.SelectedValue, out int _inv)
                    ? _inv
                    : (int?)null;

                var place = int.TryParse(DepartmentDropDown.SelectedValue, out int _place)
                    ? _place
                    : (int?)null;

                var a = new Workers
                {
                    FName    = LastNameTbx.Text,
                    SName    = FirstNameTbx.Text,
                    TName    = SurnameTbx.Text,
                    Wage     = wage,
                    Inv      = inv,
                    Place    = place,
                    Login    = LoginTbx.Text,
                    Password = PwdTbx.Text
                };

                db.Workers.InsertOnSubmit(a);

                try
                {
                    db.SubmitChanges();
                    BindGrid();
                }
                catch (Exception exception)
                {
                    Debug.WriteLine($"Somethig wrong: {exception.Message}");
                }
            }
        }
        public void BindGrid(string sortExpression = "", bool isSort = false)
        {
            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                IQueryable <Cultures> query = db.Cultures;

                switch (sortExpression)
                {
                case "IdC":
                    query = GetSortExpression(query, c => c.IdC, "IdC", isSort);
                    break;

                case "Cname":
                    query = GetSortExpression(query, c => c.Cname, "Cname", isSort);
                    break;

                case "MarketPrice":
                    query = GetSortExpression(query, c => c.MarketPrice, "MarketPrice", isSort);
                    break;

                case "Count":
                    query = GetSortExpression(query, c => c.Count, "Count", isSort);
                    break;
                }

                var source = query
                             .Select(x => new
                {
                    Idc         = x.IdC,
                    Cname       = x.Cname,
                    MarketPrice = x.MarketPrice,
                    Count       = x.Count
                })
                             .ToList();
                CulturesTable.DataSource = source;
                CulturesTable.DataBind();
            }
        }
Exemple #22
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                var mPrice = double.TryParse(TextBox2.Text, out double _mPrice)
                    ? _mPrice
                    : (double?)null;

                var pCulture = int.TryParse(CultureDropDown.SelectedValue, out int _pCulture)
                    ? _pCulture
                    : (int?)null;

                var pAnimals = int.TryParse(AnimalsDropDown.SelectedValue, out int _pAnimals)
                    ? _pAnimals
                    : (int?)null;

                var place = new Places
                {
                    Pname    = TextBox1.Text.Trim(),
                    MPrice   = mPrice,
                    PCulture = pCulture,
                    PAnimals = pAnimals
                };

                db.Places.InsertOnSubmit(place);

                try
                {
                    db.SubmitChanges();
                    BindGrid();
                }

                catch (Exception exception)
                {
                    Debug.WriteLine($"Somethig wrong: {exception.Message}");
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                Animals a = new Animals
                {
                    AName       = TextBox1.Text,
                    MarketPrice = Convert.ToDouble(TextBox2.Text),
                    Count       = Convert.ToInt32(TextBox3.Text)
                };

                db.Animals.InsertOnSubmit(a);

                try
                {
                    db.SubmitChanges();
                    BindGrid();
                }
                catch (Exception exception)
                {
                    Debug.WriteLine($"Somethig wrong: {exception.Message}");
                }
            }
        }
        public void BindGrid(string sortExpression = "", bool isSort = false)
        {
            using (var db = new AGRODataContext(Server.MapPath("\\")))
            {
                IQueryable <WorkerAndPlace> query = db.Workers
                                                    .Join(db.Places, w => w.Place, p => p.IdP, (w, p) => new WorkerAndPlace {
                    Worker = w, Place = p
                })
                                                    .Join(db.Inventory, wp => wp.Worker.Inv, i => i.IdI, (wp, i) => new WorkerAndPlace {
                    Worker = wp.Worker, Place = wp.Place, Inventory = i
                });

                switch (sortExpression)
                {
                case "FName":
                    query = GetSortExpression(query, wp => wp.Worker.FName, "FName", isSort);
                    break;

                case "SName":
                    query = GetSortExpression(query, wp => wp.Worker.SName, "SName", isSort);
                    break;

                case "TName":
                    query = GetSortExpression(query, wp => wp.Worker.TName, "TName", isSort);
                    break;

                case "Wage":
                    query = GetSortExpression(query, wp => wp.Worker.Wage, "Wage", isSort);
                    break;

                case "Inv":
                    query = GetSortExpression(query, wp => wp.Inventory.IName, "Inv", isSort);
                    break;

                case "Place":
                    query = GetSortExpression(query, wp => wp.Place.Pname, "Place", isSort);
                    break;

                case "Login":
                    query = GetSortExpression(query, wp => wp.Worker.Login, "Login", isSort);
                    break;

                case "Password":
                    query = GetSortExpression(query, wp => wp.Worker.Password, "Password", isSort);
                    break;

                default:
                    query = GetSortExpression(query, wp => wp.Worker.IdW, "IdW", isSort);
                    break;
                }

                var source = query
                             .Select(x => new
                {
                    Idw      = x.Worker.IdW,
                    FName    = x.Worker.FName,
                    SName    = x.Worker.SName,
                    TName    = x.Worker.TName,
                    Wage     = x.Worker.Wage,
                    Inv      = x.Inventory.IName,
                    InvId    = x.Inventory.IdI,
                    Place    = x.Place.Pname,
                    PlaceId  = x.Place.IdP,
                    Login    = x.Worker.Login,
                    Password = x.Worker.Password
                })
                             .ToList();

                WorkersTable.DataSource = source;
                WorkersTable.DataBind();
            }
        }