Esempio n. 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}");
            }
        }
Esempio n. 2
0
        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}");
                        }
                    }
                }
            }
        }
Esempio n. 3
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}");
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        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}");
                        }
                    }
                }
            }
        }
Esempio n. 5
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}");
                        }
                    }
                }
            }
        }
Esempio n. 6
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}");
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        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}");
                }
            }
        }
Esempio n. 8
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}");
                }
            }
        }
Esempio n. 9
0
        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}");
                }
            }
        }