Пример #1
0
        private void Save()
        {
            // Process view
            FmViewTDS dataset = new FmViewTDS();
            dataset.FmViewDisplayTemp.Merge(fmViewDisplayTemp, true);
            dataset.FmViewConditionNew.Merge(fmViewConditionNew, true);
            dataset.FmViewSortTemp.Merge(fmViewSortTemp, true);

            FmViewDisplayTemp modelFmViewDisplayTemp = new FmViewDisplayTemp(dataset);
            FmViewConditionNew modelFmViewConditionNew = new FmViewConditionNew(dataset);
            FmViewSortTemp modelFmViewSortTemp = new FmViewSortTemp(dataset);

            // Get parameters
            int viewId = Int32.Parse(hdfViewId.Value);
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int loginId = Convert.ToInt32(Session["loginID"]);
            string name = tbxName.Text;
            string type = ddlType.SelectedValue;
            string logic = tbxLogic.Text;
            string sqlCommand = GetSqlCommand();
            string fmType = hdfFmType.Value;

            if (!(Convert.ToBoolean(Session["sgLFS_VIEWS_EDIT"])) && ((string)Request.QueryString["fm_type"] == "Services"))
            {
                if ((Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_VIEW"])) && ((string)Request.QueryString["fm_type"] == "Services"))
                {
                    type = "Personal";
                }
            }

            if (!(Convert.ToBoolean(Session["sgLFS_VIEWS_EDIT"])) && ((string)Request.QueryString["fm_type"] == "Units"))
            {
                if ((Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_UNITS_VIEW"])) && ((string)Request.QueryString["fm_type"] == "Units"))
                {
                    type = "Personal";
                }
            }

            // Save to database
            DB.Open();
            DB.BeginTransaction();

            try
            {
                // Update view table
                FmView fmView = new FmView(null);
                fmView.SaveForEdit(viewId, loginId, name, type, logic, sqlCommand, fmType, companyId, name, type);

                // Update other views table
                modelFmViewDisplayTemp.SaveForEdit();
                modelFmViewConditionNew.SaveForEdit(viewId, companyId, fmType);
                modelFmViewSortTemp.SaveForEdit();

                DB.CommitTransaction();
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }