Ejemplo n.º 1
0
    private static Packet writeMeasureFile(DM_ModelProject modelProject, DM_ModelPart modelPart, DM_WorkPlace modelWorkPalce, DM_ModelWorkshop modelWorkShop, DataTable dtPoint, DataTable dtInfo, string strProgressName, ref string strError)
    {
        DateTime dtNow = DateTime.Now;

        MeasureFile     file        = new MeasureFile();
        string          strFileName = FileFun.CreateFileName(dtNow, "MeasureFile.txt");
        string          strFilePath = HttpContext.Current.Server.MapPath("~") + "\\MeasureFile\\" + strFileName;
        MeasureFileHead head        = new MeasureFileHead();

        head.MeasureDate = dtNow.Year + "-" + dtNow.Month + "-" + dtNow.Day;
        head.MeasureTime = dtNow.Hour + ":" + dtNow.Minute + ":" + dtNow.Second;
        head.ProjectName = modelProject.ProjectName;
        head.ProjectNo   = modelProject.ProjectNo;
        head.PartName    = modelPart.PartName;
        head.PartNo      = modelPart.PartNO;
        head.SerNumber   = "";
        head.ComPonent   = "";
        head.Progress    = strProgressName;
        head.WorkPlace   = modelWorkPalce.WorkPlaceName;
        head.WorkShop    = modelWorkShop.WorkshopName;
        file.FileHead    = head;
        for (int i = 0; i < dtPoint.Rows.Count; i++)
        {
            string    strPointName = dtPoint.Rows[i]["PointName"].ToString();
            string    strPointID   = dtPoint.Rows[i]["PointID"].ToString();
            float     fMeas        = dtPoint.Rows[i]["Value"].ToString() == "" ? MeasureFileBase.GlobalData.NULL_NUM : Convert.ToSingle(dtPoint.Rows[i]["Value"]);
            DataRow[] nomRows      = dtInfo.Select("PointID = " + strPointID);
            float     fNom         = nomRows[0]["Nominal"].ToString() == "" ? MeasureFileBase.GlobalData.NULL_NUM : Convert.ToSingle(nomRows[0]["Nominal"]);
            float     fUpTol       = nomRows[0]["UpTol"].ToString() == "" ? MeasureFileBase.GlobalData.NULL_NUM : Convert.ToSingle(nomRows[0]["UpTol"]);
            float     fLowTol      = nomRows[0]["LowTol"].ToString() == "" ? MeasureFileBase.GlobalData.NULL_NUM : Convert.ToSingle(nomRows[0]["LowTol"]);

            MeasurePoint point = new MeasurePoint(strPointName, fMeas, fNom, fUpTol, fLowTol);
            file.AddPoint(point);
        }
        if (file.Save(strFilePath))
        {
            byte[] byFileData = null;
            using (FileStream fs = new FileStream(strFilePath, FileMode.Open, FileAccess.Read))
            {
                byFileData = new byte[(int)fs.Length];
                fs.Read(byFileData, 0, (int)fs.Length);
            }
            PacketTable table = new PacketTable();
            table.AddField("FileName", PacketTable.FieldType.TypeString);
            table.AddField("File", PacketTable.FieldType.TypeImage);
            table.MakeTable(1);
            table.SetValue(0, 0, strFileName);
            table.SetValue(0, 1, byFileData);
            PacketTable[] TableArray = new PacketTable[1];
            TableArray[0] = table;
            ServerConnection conn       = new ServerConnection();
            Packet           recvPacket = conn.ExecuteCommand(10001, TableArray);
            return(recvPacket);
        }
        else
        {
            strError = "生成文件或者上传文件出错!";
            return(null);
        }
    }
Ejemplo n.º 2
0
        //gvPic Controls
        #region gvPic Controls
        protected void gvPic_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string      sFunction = "gvPic_RowCommand";
            GridViewRow row       = ((GridView)sender).Rows[int.Parse(e.CommandArgument.ToString())];

            if (row != null)
            {
                FileFun fnFile = new FileFun();

                switch (e.CommandName)
                {
                    #region DownLoad
                case ("DownLoad"):
                    try
                    {
                        string strFileID   = row.Cells[3].Text.ToString().Trim();
                        string strFileName = row.Cells[1].Text.ToString().Trim();
                        byte[] stream      = fnFile.GetFLMFile(strFileID, strFileName, profile, "Y");

                        if (stream.Length > 0)
                        {
                            Response.Clear();
                            Response.Charset         = "BIG-5";
                            Response.ContentEncoding = Encoding.UTF7;
                            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8).Replace("+", "_"));
                            Response.ContentType = "applicant/octet-stream";
                            Page.Response.BinaryWrite(stream);
                            Page.Response.End();
                        }
                    }
                    catch (Exception ex)
                    {
                        new DBFun().DealLog(sFunction + "_DownLoad", "EOL_NO=" + lblNO.Text.ToString().Trim() + ", fail Msg=" + ex.ToString());
                        //Response.Write("Download Error :" + ex.Message);
                    }
                    break;

                    #endregion
                }
            }
        }