Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btn_Click(object sender, EventArgs e)
        {
            MapAttr mattr = new MapAttr(this.RefNo);

            if (this.Pub1.GetRadioButtonByID("RB_Way_0").Checked)
            {
                mattr.HisAutoFull = AutoFullWay.Way0;
            }

            // JS 方式。
            if (this.Pub1.GetRadioButtonByID("RB_Way_1").Checked)
            {
                mattr.HisAutoFull = AutoFullWay.Way1_JS;
                mattr.AutoFullDoc = this.Pub1.GetTextBoxByID("TB_JS").Text;

                /*检查字段是否填写正确.*/
                MapAttrs attrsofCheck = new MapAttrs(mattr.FK_MapData);
                string   docC         = mattr.AutoFullDoc;
                foreach (MapAttr attrC in attrsofCheck)
                {
                    if (attrC.IsNum == false)
                    {
                        continue;
                    }
                    docC = docC.Replace("@" + attrC.KeyOfEn, "");
                    docC = docC.Replace("@" + attrC.Name, "");
                }

                if (docC.Contains("@"))
                {
                    this.Alert("您填写的表达公式不正确,导致一些数值类型的字段没有被正确的替换。" + docC);
                    return;
                }
            }

            // 外键方式。
            if (this.Pub1.GetRadioButtonByID("RB_Way_2").Checked)
            {
                mattr.HisAutoFull = AutoFullWay.Way2_SQL;
                mattr.AutoFullDoc = this.Pub1.GetTextBoxByID("TB_SQL").Text;
            }

            // 本表单中外键列。
            string doc = "";

            if (this.Pub1.GetRadioButtonByID("RB_Way_3").Checked)
            {
                mattr.HisAutoFull = AutoFullWay.Way3_FK;
                MapData md    = new MapData(mattr.FK_MapData);
                Attrs   attrs = md.GenerHisMap().HisFKAttrs;
                foreach (Attr attr in attrs)
                {
                    if (attr.IsRefAttr)
                    {
                        continue;
                    }

                    if (this.Pub1.GetRadioButtonByID("RB_FK_" + attr.Key).Checked == false)
                    {
                        continue;
                    }
                    // doc = " SELECT " + this.Pub1.GetDDLByID("DDL_" + attr.Key).SelectedValue + " FROM " + attr.HisFKEn.EnMap.PhysicsTable + " WHERE NO=@" + attr.Key;
                    doc = "@AttrKey=" + attr.Key + "@Field=" + this.Pub1.GetDDLByID("DDL_" + attr.Key).SelectedValue + "@Table=" + attr.HisFKEn.EnMap.PhysicsTable;
                }
                mattr.AutoFullDoc = doc;
            }

            // 本表单中从表列。
            if (this.Pub1.GetRadioButtonByID("RB_Way_4").Checked)
            {
                MapDtls dtls = new MapDtls(mattr.FK_MapData);
                mattr.HisAutoFull = AutoFullWay.Way4_Dtl;
                foreach (MapDtl dtl in dtls)
                {
                    try
                    {
                        if (this.Pub1.GetRadioButtonByID("RB_" + dtl.No).Checked == false)
                        {
                            continue;
                        }
                    }
                    catch
                    {
                        continue;
                    }
                    //  doc = "SELECT " + this.Pub1.GetDDLByID( "DDL_"+dtl.No + "_Way").SelectedValue + "(" + this.Pub1.GetDDLByID("DDL_"+dtl.No+"_F").SelectedValue + ") FROM " + dtl.No + " WHERE REFOID=@OID";
                    doc = "@Table=" + dtl.No + "@Field=" + this.Pub1.GetDDLByID("DDL_" + dtl.No + "_F").SelectedValue + "@Way=" + this.Pub1.GetDDLByID("DDL_" + dtl.No + "_Way").SelectedValue;
                }
                mattr.AutoFullDoc = doc;
            }

            try
            {
                mattr.DoCheckFullWay();
                mattr.Update();
            }
            catch (Exception ex)
            {
                this.ResponseWriteRedMsg(ex);
                return;
            }

            this.Alert("保存成功");
            this.Pub1.Clear();
            Button btn = sender as Button;

            if (btn.ID.Contains("Close"))
            {
                this.WinClose();
                return;
            }
            else
            {
                this.Response.Redirect(this.Request.RawUrl, true);
            }
        }