Exemplo n.º 1
0
        /// <summary>
        /// 删除数据
        /// </summary>
        private void DeleteById()
        {
            int    id;
            string a = Request["id[]"];

            string[] temp = a.Split(',');
            for (int j = 0; j < temp.Length; j++)
            {
                id = Convert.ToInt32(temp[j]);
                DAL.WorkingArea.Delete(id);
                DAL.WorkingArea   dw       = new DAL.WorkingArea();
                Model.WorkingArea wa       = dw.GetModel(id);
                string            areaName = wa.AreaName;
                //DataSet ds = DAL.NewRTKUserPurview.GetList("1=1");
                //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                //{
                //    Model.NewRTKUserPurview mRTKUserPurview = DAL.NewRTKUserPurview.GetModel(ds.Tables[0].Rows[i]["UserName"].ToString());
                //    string AreaIDs = "";
                //    foreach (string Uid in mRTKUserPurview.AreaID.Split(';'))
                //    {
                //        if (Uid.Trim() != "")
                //        {
                //            if (Uid == areaName)
                //            {

                //            }
                //            else
                //            {
                //                AreaIDs += Uid + ";";
                //            }
                //        }
                //    }
                //    mRTKUserPurview.AreaID = AreaIDs;
                //    DAL.NewRTKUserPurview.Update(mRTKUserPurview);
                //}

                //DataSet ComUser = DAL.CompanyPurview.GetList("1=1");
                //for (int i = 0; i < ComUser.Tables[0].Rows.Count; i++)
                //{
                //    Model.CompanyPurview mCompanyPurview = DAL.CompanyPurview.GetModel(ComUser.Tables[0].Rows[i]["UserName"].ToString());
                //    string AreaIDs = "";
                //    foreach (string Uid in mCompanyPurview.AreaID.Split(';'))
                //    {
                //        if (Uid.Trim() != "")
                //        {
                //            if (Uid == areaName)
                //            {

                //            }
                //            else
                //            {
                //                AreaIDs += Uid + ";";
                //            }
                //        }
                //    }
                //    mCompanyPurview.AreaID = AreaIDs;
                //    DAL.CompanyPurview.Update(mCompanyPurview);
                //}
            }
        }
Exemplo n.º 2
0
        private int AddData()
        {
            string savepath = Server.MapPath("~/upload/WorkingArea/");
            string filename = Request.Files[0].FileName;

            try
            {
                Request.Files[0].SaveAs(savepath + filename);
            }
            catch
            {
                return(-1);
            }
            StreamReader sr = new StreamReader(savepath + filename);

            try
            {
                string data     = "";
                string linedata = sr.ReadLine();
                while (linedata != null && linedata.Trim() != "")
                {
                    string[] dds = linedata.Split(',');
                    if (data != "")
                    {
                        data = data + "," + dds[0].Trim() + "," + dds[1].Trim();
                    }
                    else
                    {
                        data = data + dds[0].Trim() + "," + dds[1].Trim();
                    }
                    linedata = sr.ReadLine();
                }
                Model.WorkingArea mwa = new Model.WorkingArea();
                mwa.AreaName   = Request["area"];
                mwa.AreaString = data;
                DAL.WorkingArea dw = new DAL.WorkingArea();
                if (dw.Exists(mwa.AreaName))
                {
                    return(-2);//已经存在改名称
                }
                DAL.WorkingArea dalwa = new DAL.WorkingArea();
                dalwa.Add(mwa);
                sr.Close();
                File.Delete(savepath + filename);
                return(0);
            }
            catch (Exception er)
            {
                sr.Close(); File.Delete(savepath + filename);
                return(1);//格式添加错误
            }
        }
Exemplo n.º 3
0
        private void UpdateData()
        {
            DAL.WorkingArea dalwa = new DAL.WorkingArea();
            int             id    = Convert.ToInt32(Request["ID"].ToString());

            DAL.WorkingArea   dw  = new DAL.WorkingArea();
            Model.WorkingArea mwa = DAL.WorkingArea.GetModel(id);
            mwa.AreaName = Request["AreaName"].Trim();
            flag         = 1;
            string[] area = Request["AreaString"].ToString().Split(',');
            foreach (string a in area)
            {
                try { Convert.ToDouble(a); }
                catch { flag = -1; return; }
            }
            mwa.AreaString = Request["AreaString"].Trim();
            DAL.WorkingArea.Update(mwa);
            Response.ContentType = "text/plain";
            Response.Write("0");
            Response.End();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 下载数据
        /// </summary>
        /// <param name="id">需要下载的ID</param>
        private void Download(int id)
        {
            DAL.WorkingArea   bllwa    = new DAL.WorkingArea();
            DAL.WorkingArea   dw       = new DAL.WorkingArea();
            Model.WorkingArea modelwa  = dw.GetModel(id);
            string            savepath = Server.MapPath("~/upload/WorkingArea/");
            string            filePath = savepath + modelwa.AreaName + ".txt";
            string            fileName = "WorkingArea_" + modelwa.AreaName + ".txt";
            StreamWriter      sw       = new StreamWriter(filePath, false);

            string[] strs = modelwa.AreaString.Split(',');
            for (int i = 0; i < (strs.Length) / 2; i++)
            {
                sw.WriteLine(strs[2 * i] + "," + strs[2 * i + 1]);
            }
            sw.Close();

            //提交结果给用户
            try
            {
                FileInfo fileInfo = new FileInfo(filePath);
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
                Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                Response.AddHeader("Content-Transfer-Encoding", "binary");
                //Response.ContentType = "text/plain";
                Response.ContentType     = "application/octet-stream";
                Response.ContentEncoding = System.Text.Encoding.Default;
                Response.WriteFile(fileInfo.FullName);
                Response.Flush();
                // Response.End();
            }
            catch (Exception er)
            {
                string text = er.Message;
                throw new Exception("处理过程中发生了错误!");
            }
        }