Esempio n. 1
0
        void btn_Click(object sender, EventArgs e)
        {
            //批量保存数据。
            GENoNames   ens = new GENoNames(this.RefNo, "sdsd");
            QueryObject qo  = new QueryObject(ens);

            qo.DoQuery("No", 10, this.PageIdx, false);
            foreach (GENoName myen in ens)
            {
                string no    = myen.No;
                string name1 = this.Pub1.GetTextBoxByID("TB_" + myen.No).Text;
                if (name1 == "")
                {
                    continue;
                }
                BP.DA.DBAccess.RunSQL("update " + this.RefNo + " set Name='" + name1 + "' WHERE no='" + no + "'");
            }


            BP.En.GENoName en   = new GENoName(this.RefNo, "sd");
            string         name = this.Pub1.GetTextBoxByID("TB_Name").Text.Trim();

            if (name.Length > 0)
            {
                en.Name = name;
                en.No   = en.GenerNewNo;
                en.Insert();
                this.Response.Redirect("SFTableEditData.aspx?RefNo=" + this.RefNo + "&PageIdx=" + this.PageIdx, true);
            }
        }
Esempio n. 2
0
        public void BindSFTable()
        {
            SFTable sf      = new SFTable(this.RefNo);
            var     canEdit = sf.FK_SFDBSrc == "local"; //todo:此处判断不准确,需更加精确的判断??

            this.Title = (canEdit ? "编辑:" : "查看:") + sf.Name;
            this.Pub1.AddTable("class='table' cellpadding='1' cellspacing='1' border='1' style='width:100%'");
            this.Pub1.AddTR();
            this.Pub1.AddTDGroupTitle("style='width:80px;text-align:center'", "编号");
            this.Pub1.AddTDGroupTitle("名称");

            if (canEdit)
            {
                this.Pub1.AddTDGroupTitle("style='width:80px'", "操作");
            }

            this.Pub1.AddTREnd();

            GENoNames   ens = new GENoNames(sf.No, sf.Name);
            QueryObject qo  = new QueryObject(ens);

            try
            {
                this.Pub2.BindPageIdxEasyUi(qo.GetCount(), "SFTableEditData.aspx?RefNo=" + this.RefNo, this.PageIdx);
            }
            catch
            {
                sf.CheckPhysicsTable();
                this.Pub2.BindPageIdxEasyUi(qo.GetCount(), "SFTableEditData.aspx?RefNo=" + this.RefNo, this.PageIdx);
            }

            qo.DoQuery("No", 10, this.PageIdx, false);

            foreach (GENoName en in ens)
            {
                this.Pub1.AddTR();
                this.Pub1.AddTDIdx(en.No);
                TextBox tb = new TextBox();
                tb.ID   = "TB_" + en.No;
                tb.Text = en.Name;
                tb.Style.Add("width", "99%");
                tb.ReadOnly = !canEdit;

                this.Pub1.AddTD(tb);

                if (canEdit)
                {
                    this.Pub1.AddTD("<a href=\"javascript:Del('" + this.RefNo + "','" + this.PageIdx + "','" + en.No + "')\" class='easyui-linkbutton' data-options=\"iconCls:'icon-delete'\" >删除</a>");
                }

                this.Pub1.AddTREnd();
            }

            if (canEdit)
            {
                GENoName newen = new GENoName(sf.No, sf.Name);
                this.Pub1.AddTR();
                this.Pub1.AddTDIdx("新记录");
                TextBox tb1 = new TextBox();
                tb1.ID   = "TB_Name";
                tb1.Text = newen.Name;
                tb1.Style.Add("width", "99%");

                this.Pub1.AddTD(tb1);

                var btn = new LinkBtn(false, NamesOfBtn.Save, "保存");
                btn.Click += new EventHandler(btn_Click);

                this.Pub1.AddTD(btn);
                this.Pub1.AddTREnd();
            }

            this.Pub1.AddTableEnd();

            //this.Pub3.AddTable();
            //this.Pub3.AddTRSum();
            //this.Pub3.AddTD("编号");
            //this.Pub3.AddTD("名称");
            //this.Pub3.AddTD("");
            //this.Pub3.AddTREnd();

            //GENoName newen = new GENoName(sf.No, sf.Name);
            //this.Pub3.AddTRSum();
            //this.Pub3.AddTD(newen.GenerNewNo);
            //TextBox tbn = new TextBox();
            //tbn.ID = "TB_Name";

            //this.Pub3.AddTD(tbn);
            //Button btn = new Button();
            //btn.Text = "增加";
            //btn.Click += new EventHandler(btn_Click);
            //this.Pub3.AddTD(btn);
            //this.Pub3.AddTREnd();
            //this.Pub3.AddTableEnd();
        }
Esempio n. 3
0
        void btn_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            try
            {
                BP.Web.Controls.DDL DDL_ImpWay            = (BP.Web.Controls.DDL) this.Pub1.FindControl("DDL_ImpWay");
                System.Web.UI.WebControls.FileUpload fuit = (System.Web.UI.WebControls.FileUpload) this.Pub1.FindControl("fup");
                if (DDL_ImpWay.SelectedIndex == 0)
                {
                    this.Alert("请选择导入方式.");
                    return;
                }

                string tempPath = this.Request.PhysicalApplicationPath + "\\Temp\\";
                if (System.IO.Directory.Exists(tempPath) == false)
                {
                    System.IO.Directory.CreateDirectory(tempPath);
                }

                MapDtl dtl = new MapDtl(this.FK_MapDtl);

                //求出扩展名.
                string fileName = fuit.FileName.ToLower();
                if (fileName.Contains(".xls") == false)
                {
                    this.Alert("上传的文件必须是excel文件.");
                    return;
                }
                string ext = ".xls";
                if (fileName.Contains(".xlsx"))
                {
                    ext = ".xlsx";
                }

                //保存临时文件.
                string file = tempPath + WebUser.No + ext;
                fuit.SaveAs(file);

                GEDtls dtls = new GEDtls(this.FK_MapDtl);
                System.Data.DataTable dt = BP.DA.DBLoad.GetTableByExt(file);

                file = this.Request.PhysicalApplicationPath + "\\DataUser\\DtlTemplete\\" + this.FK_MapDtl + ext;
                if (System.IO.File.Exists(file) == false)
                {
                    if (ext == ".xlsx")
                    {
                        file = this.Request.PhysicalApplicationPath + "\\DataUser\\DtlTemplete\\" + this.FK_MapDtl + ".xls";
                    }
                    else
                    {
                        file = this.Request.PhysicalApplicationPath + "\\DataUser\\DtlTemplete\\" + this.FK_MapDtl + ".xls";
                    }
                }

                System.Data.DataTable dtTemplete = BP.DA.DBLoad.GetTableByExt(file);

                #region 检查两个文件是否一致。
                foreach (DataColumn dc in dtTemplete.Columns)
                {
                    bool isHave = false;
                    foreach (DataColumn mydc in dt.Columns)
                    {
                        if (dc.ColumnName == mydc.ColumnName)
                        {
                            isHave = true;
                            break;
                        }
                    }
                    if (isHave == false)
                    {
                        throw new Exception("@您导入的excel文件不符合系统要求的格式,请下载模版文件重新填入。");
                    }
                }
                #endregion 检查两个文件是否一致。

                #region 生成要导入的属性.

                BP.En.Attrs attrs    = dtls.GetNewEntity.EnMap.Attrs;
                BP.En.Attrs attrsExp = new BP.En.Attrs();
                foreach (DataColumn dc in dtTemplete.Columns)
                {
                    foreach (Attr attr in attrs)
                    {
                        if (attr.UIVisible == false)
                        {
                            continue;
                        }

                        if (attr.IsRefAttr)
                        {
                            continue;
                        }

                        if (attr.Desc == dc.ColumnName.Trim())
                        {
                            attrsExp.Add(attr);
                            break;
                        }
                    }
                }
                #endregion 生成要导入的属性.

                #region 执行导入数据.
                if (DDL_ImpWay.SelectedIndex == 1)
                {
                    BP.DA.DBAccess.RunSQL("DELETE FROM " + dtl.PTable + " WHERE RefPK='" + this.WorkID + "'");
                }

                int    i   = 0;
                Int64  oid = BP.DA.DBAccess.GenerOID("Dtl", dt.Rows.Count);
                string rdt = BP.DA.DataType.CurrentData;

                string errMsg = "";
                foreach (DataRow dr in dt.Rows)
                {
                    GEDtl dtlEn = dtls.GetNewEntity as GEDtl;
                    dtlEn.ResetDefaultVal();

                    foreach (BP.En.Attr attr in attrsExp)
                    {
                        if (attr.UIVisible == false || dr[attr.Desc] == DBNull.Value)
                        {
                            continue;
                        }
                        string val = dr[attr.Desc].ToString();
                        if (val == null)
                        {
                            continue;
                        }
                        val = val.Trim();
                        switch (attr.MyFieldType)
                        {
                        case FieldType.Enum:
                        case FieldType.PKEnum:
                            SysEnums ses     = new SysEnums(attr.UIBindKey);
                            bool     isHavel = false;
                            foreach (SysEnum se in ses)
                            {
                                if (val == se.Lab)
                                {
                                    val     = se.IntKey.ToString();
                                    isHavel = true;
                                    break;
                                }
                            }
                            if (isHavel == false)
                            {
                                errMsg += "@数据格式不规范,第(" + i + ")行,列(" + attr.Desc + "),数据(" + val + ")不符合格式,改值没有在枚举列表里.";
                                val     = attr.DefaultVal.ToString();
                            }
                            break;

                        case FieldType.FK:
                        case FieldType.PKFK:
                            Entities ens = null;
                            if (attr.UIBindKey.Contains("."))
                            {
                                ens = BP.En.ClassFactory.GetEns(attr.UIBindKey);
                            }
                            else
                            {
                                ens = new GENoNames(attr.UIBindKey, "desc");
                            }

                            ens.RetrieveAll();
                            bool isHavelIt = false;
                            foreach (Entity en in ens)
                            {
                                if (val == en.GetValStrByKey("Name"))
                                {
                                    val       = en.GetValStrByKey("No");
                                    isHavelIt = true;
                                    break;
                                }
                            }
                            if (isHavelIt == false)
                            {
                                errMsg += "@数据格式不规范,第(" + i + ")行,列(" + attr.Desc + "),数据(" + val + ")不符合格式,改值没有在外键数据列表里.";
                            }
                            break;

                        default:
                            break;
                        }

                        if (attr.MyDataType == BP.DA.DataType.AppBoolean)
                        {
                            if (val.Trim() == "是" || val.Trim().ToLower() == "yes")
                            {
                                val = "1";
                            }

                            if (val.Trim() == "否" || val.Trim().ToLower() == "no")
                            {
                                val = "0";
                            }
                        }

                        dtlEn.SetValByKey(attr.Key, val);
                    }
                    dtlEn.RefPKInt = (int)this.WorkID;
                    dtlEn.SetValByKey("RDT", rdt);
                    dtlEn.SetValByKey("Rec", WebUser.No);
                    i++;

                    dtlEn.InsertAsOID(oid);
                    oid++;
                }
                #endregion 执行导入数据.

                if (string.IsNullOrEmpty(errMsg) == true)
                {
                    this.Alert("共有(" + i + ")条数据导入成功。");
                }
                else
                {
                    this.Alert("共有(" + i + ")条数据导入成功,但是出现如下错误:" + errMsg);
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message.Replace("'", "‘");
                this.Alert(msg);
            }
        }
Esempio n. 4
0
        public void BindSFTable()
        {
            SFTable sf = new SFTable(this.RefNo);

            this.Pub1.AddTable();
            this.Pub1.AddCaptionLeft("编辑:" + sf.Name);
            this.Pub1.AddTR();
            this.Pub1.AddTDTitle("编号");
            this.Pub1.AddTDTitle("名称");
            this.Pub1.AddTDTitle("操作");
            this.Pub1.AddTREnd();

            GENoNames   ens = new GENoNames(sf.No, sf.Name);
            QueryObject qo  = new QueryObject(ens);

            try
            {
                this.Pub2.BindPageIdx(qo.GetCount(), 10, this.PageIdx, "SFTableEditData.aspx?RefNo=" + this.RefNo);
            }
            catch
            {
                sf.CheckPhysicsTable();
                this.Pub2.BindPageIdx(qo.GetCount(), 10, this.PageIdx, "SFTableEditData.aspx?RefNo=" + this.RefNo);
            }

            qo.DoQuery("No", 10, this.PageIdx, false);

            foreach (GENoName en in ens)
            {
                this.Pub1.AddTR();
                this.Pub1.AddTDDesc(en.No);
                TextBox tb = new TextBox();
                tb.ID   = "TB_" + en.No;
                tb.Text = en.Name;
                tb.Attributes["width"] = "500px";
                tb.Columns             = 80;

                this.Pub1.AddTD(tb);
                this.Pub1.AddTD("<a href=\"javascript:Del('" + this.RefNo + "','" + this.PageIdx + "','" + en.No + "')\" >删除</a>");
                this.Pub1.AddTREnd();
            }

            GENoName newen = new GENoName(sf.No, sf.Name);

            this.Pub1.AddTR();
            this.Pub1.AddTDDesc("新记录");
            TextBox tb1 = new TextBox();

            tb1.ID      = "TB_Name";
            tb1.Text    = newen.Name;
            tb1.Columns = 80;

            this.Pub1.AddTD(tb1);
            Button btn = new Button();

            btn.CssClass = "Btn";

            btn.Text   = "Save";
            btn.Click += new EventHandler(btn_Click);
            this.Pub1.AddTD(btn);
            this.Pub1.AddTREnd();
            this.Pub1.AddTableEnd();

            //this.Pub3.AddTable();
            //this.Pub3.AddTRSum();
            //this.Pub3.AddTD("编号");
            //this.Pub3.AddTD("名称");
            //this.Pub3.AddTD("");
            //this.Pub3.AddTREnd();

            //GENoName newen = new GENoName(sf.No, sf.Name);
            //this.Pub3.AddTRSum();
            //this.Pub3.AddTD(newen.GenerNewNo);
            //TextBox tbn = new TextBox();
            //tbn.ID = "TB_Name";

            //this.Pub3.AddTD(tbn);
            //Button btn = new Button();
            //btn.Text = "增加";
            //btn.Click += new EventHandler(btn_Click);
            //this.Pub3.AddTD(btn);
            //this.Pub3.AddTREnd();
            //this.Pub3.AddTableEnd();
        }