コード例 #1
0
ファイル: EditForm.cs プロジェクト: bidaad/ChandSanieh
    void EditForm_Init(object sender, EventArgs e)
    {
        Tools tools = new Tools();

        tools.AccessList = tools.GetAccessList(this.BaseID);
        if (!tools.HasAccess("Edit", this.BaseID))
        {
            Response.Redirect("~/Default.aspx");
        }


        #region Display Mandatory
        Label              lbl;
        string             ctrID, Property, FullPropName;
        string[]           sv = new string[] { };
        ContentPlaceHolder cphMandatory = ((ContentPlaceHolder)((Page)(HttpContext.Current.Handler)).Master.FindControl("cphMain"));
        PropertyInfo       pi, piMandatory;

        Type t;
        if (!BaseID.StartsWith("HC"))
        {
            t = System.Web.Compilation.BuildManager.GetType("BOL" + BaseID, true);
        }
        else
        {
            t = System.Web.Compilation.BuildManager.GetType("BOLHardCode", true);
        }
        IBaseBOL          CurObj = (IBaseBOL)Activator.CreateInstance(t);
        MemberInfo        miMandatory;
        ColumnAttribute   attMandatory;
        Type              type         = typeof(T).GetType();
        List <WebControl> listControls = new Tools().GetControls();
        foreach (WebControl wc in listControls)
        {
            Property = wc.ID.Substring(3, wc.ID.Length - 3);
            ctrID    = wc.ID.Substring(3, wc.ID.Length - 3);
            pi       = type.GetProperty(Property);
            lbl      = cphMandatory.FindControl("lbl" + ctrID) as Label;

            FullPropName = BaseID + "." + Property;
            piMandatory  = CurObj.GetType().GetProperty(ctrID);
            miMandatory  = CurObj.GetType().GetMember(ctrID)[0];
            attMandatory = (ColumnAttribute)System.Attribute.GetCustomAttribute(miMandatory, typeof(ColumnAttribute));
            sv           = Tools.SplitValue(attMandatory);
            if (sv[2] == "FALSE" && lbl != null)
            {
                lbl.Text = "<font style='color:red' title=\"اجباری\"> * </font> " + lbl.Text;
            }
        }

        #endregion Display Mandatory
        // base.OnInit(e);
    }
コード例 #2
0
ファイル: EditFormDetail.cs プロジェクト: bidaad/ChandSanieh
    void EditFormDetail_Init(object sender, EventArgs e)
    {
        #region Display Mandatory
        Label              lbl;
        string             ctrID, Property, FullPropName;
        string[]           sv = new string[] { };
        ContentPlaceHolder cphMandatory = ((ContentPlaceHolder)((Page)(HttpContext.Current.Handler)).Master.FindControl("cphMain"));
        PropertyInfo       pi, piMandatory;

        Type              t           = System.Web.Compilation.BuildManager.GetType("BOL" + BaseID, true);
        int[]             MasterCodes = { -1 };
        object[]          oArr        = { MasterCodes };
        IBaseBOL          CurObj      = (IBaseBOL)Activator.CreateInstance(t, oArr);
        MemberInfo        miMandatory;
        ColumnAttribute   attMandatory;
        Type              type         = typeof(T).GetType();
        List <WebControl> listControls = new Tools().GetControls();
        foreach (WebControl wc in listControls)
        {
            Property = wc.ID.Substring(3, wc.ID.Length - 3);
            ctrID    = wc.ID.Substring(3, wc.ID.Length - 3);
            pi       = type.GetProperty(Property);
            lbl      = cphMandatory.FindControl("lbl" + ctrID) as Label;

            FullPropName = BaseID + "." + Property;
            piMandatory  = CurObj.GetType().GetProperty(ctrID);
            miMandatory  = CurObj.GetType().GetMember(ctrID)[0];
            attMandatory = (ColumnAttribute)System.Attribute.GetCustomAttribute(miMandatory, typeof(ColumnAttribute));
            sv           = Tools.SplitValue(attMandatory);
            if (sv[2] == "FALSE" && lbl != null)
            {
                lbl.Text = "<font style='color:red' title=\"اجباری\"> * </font> " + lbl.Text;
            }
        }

        #endregion Display Mandatory
    }
コード例 #3
0
ファイル: EditForm.cs プロジェクト: bidaad/ChandSanieh
    protected int SaveControls(string AfterSaveUrl)
    {
        object ReturnValue = -1;

        try
        {
            Type     t      = System.Web.Compilation.BuildManager.GetType("BOL" + BaseID, true);
            IBaseBOL CurObj = (IBaseBOL)Activator.CreateInstance(t);

            #region Full Save Data
            if (!NewMode)
            {
                //CurObj.Code = Convert.ToInt32(Code);vvvv
                PropertyInfo CodeProperty = CurObj.GetType().GetProperty("Code");
                CodeProperty.SetValue(CurObj, Convert.ToInt32(Code), new object[] { });
            }
            #region Automatica Save Data
            List <Dictionary <Control, object> > ObjectList = new List <Dictionary <Control, object> >();
            List <WebControl> listControls = new Tools().GetControls();
            foreach (WebControl wc in listControls)
            {
                Tools.AddToDic(wc, "BOL" + BaseID, ObjectList);
            }
            #endregion
            #region Show Messages and save
            IList messages = Tools.TryGet(ObjectList, CurObj);
            if (messages.Count == 0)
            {
                //messages = CurObj.CheckBusinessRules();
                MethodInfo BusinessRulesMethod = CurObj.GetType().GetMethod("CheckBusinessRules");
                BusinessRulesMethod.Invoke(CurObj, new object[] { });

                if (messages.Count == 0)
                {
                    //CurObj.ObjectList = listControls;vvvvv
                    FieldInfo ObjectListField = CurObj.GetType().GetField("ObjectList");
                    ObjectListField.SetValue(CurObj, listControls);

                    //CurObj.SaveChanges(NewMode);vvvvvv
                    MethodInfo SaveChangesMethod = CurObj.GetType().GetMethod("SaveChanges");
                    ReturnValue = SaveChangesMethod.Invoke(CurObj, new object[] { NewMode });
                }
            }
            if (messages.Count == 0)
            {
                if (NewMode)
                {
                    messages.Add(Messages.ShowMessage(MessagesEnum.PrimaryInfomationSavedSuccessfuly));
                }
                else
                {
                    messages.Add(Messages.ShowMessage(MessagesEnum.SavedSuccessfuly));
                }
            }

            ShowResultMessages(messages, AfterSaveUrl);
            ObjectList.Clear();
            #endregion
            #endregion
        }
        catch (Exception exp)
        {
            //TODO: Handle
            //if (exp.Message == "NotValidFileExtenstion")
            throw (exp);
        }
        return((int)ReturnValue);
    }