Example #1
0
 private void cmiDownload_Click(object sender, EventArgs e)
 {
     try
     {
         if (picShow.Image != null)
         {
             saveFileDialog1.FileName = "pic.jpg";
             saveFileDialog1.Title    = "图片下载";
             if (saveFileDialog1.FileName != string.Empty && saveFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 string outpath          = saveFileDialog1.FileName;
                 System.IO.FileStream fs = new System.IO.FileStream(outpath, System.IO.FileMode.Create);
                 byte[] imageByte        = UCTemplatePic.ImageToByte(picShow.Image);
                 for (int i = 0; i < imageByte.Length; i++)
                 {
                     fs.WriteByte(imageByte[i]);
                 }
                 fs.Close();
                 ShowInfoMessage("文件下载成功");
             }
         }
     }
     catch (Exception E)
     {
         this.ShowMessage(E.Message);
     }
 }
Example #2
0
        /// <summary>
        /// 修改图片
        /// </summary>
        void UpdateImage()
        {
            if (UCInputMainType == 1)//数据库交互模式
            {
                string sql = "";

                switch (UCInputDBSaveType)
                {
                case 1:    //存储在同一张表内
                    sql = "UPDATE " + UCDBTableName + " SET " + UCDBPicFieldName + "=@" + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != string.Empty)
                    {
                        sql += "," + UCDBSmallPicFieldName + "=@" + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + UCDBRemarkFieldName;
                        sql += "=" + SysString.ToDBString(txtRemark.Text.Trim());
                    }
                    if (UCDBMainIDFieldName != string.Empty)
                    {
                        sql += "," + UCDBMainIDFieldName + "=" + UCDataID;
                    }
                    if (UCDBStyleNoFieldName != string.Empty)
                    {
                        sql += "," + UCDBStyleNoFieldName + "=" + SysString.ToDBString(UCDataStyleNo);
                    }
                    sql += " WHERE ID=" + UCDataID;

                    break;

                case 2:    //存储在独立的数据表内
                    sql = "UPDATE " + UCDBTableName + " SET " + UCDBPicFieldName + "=@" + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != string.Empty)
                    {
                        sql += "," + UCDBSmallPicFieldName + "=@" + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + UCDBRemarkFieldName;
                        sql += "=" + SysString.ToDBString(txtRemark.Text.Trim());
                    }
                    if (UCDBMainIDFieldName != string.Empty)
                    {
                        sql += "," + UCDBMainIDFieldName + "=" + UCDataID;
                    }
                    if (UCDBStyleNoFieldName != string.Empty)
                    {
                        sql += "," + UCDBStyleNoFieldName + "=" + SysString.ToDBString(UCDataStyleNo);
                    }
                    sql += " WHERE ID=" + saveIDs[saveImageIndex];

                    break;
                }

                int len = 1;
                if (UCDBSmallPicFieldName != string.Empty)
                {
                    len = 2;
                }
                object[,] obja = new object[2, len];
                obja[0, 0]     = "@" + UCDBPicFieldName;
                obja[1, 0]     = UCTemplatePic.ImageToByte(UCTemplatePic.ZoomImage(picShow.Image, UCUIPicWidth, UCUIPicHeight));
                if (UCDBSmallPicFieldName != string.Empty)
                {
                    obja[0, 1] = "@" + UCDBSmallPicFieldName;
                    obja[1, 1] = UCTemplatePic.ImageToByte(UCTemplatePic.ZoomImage(picShow.Image, UCUISmallPicWidth, UCUISmallPicHeight));
                }
                PicExecuteNonQuery(sql, obja); //SysUtils.ExecuteNonQuery
            }
            else if (UCInputMainType == 2)     //仅是图片交互模式
            {
                //代码待补充
                if (m_UCDataLstImage.Count > 0)
                {
                    if (m_UCDataLstImage.Count > saveImageIndex)
                    {
                        m_UCDataLstImage[saveImageIndex] = UCTemplatePic.ZoomImage(picShow.Image, UCUIPicWidth, UCUIPicHeight);
                    }
                    if (m_UCDataLstSmallImage.Count > saveImageIndex)
                    {
                        m_UCDataLstSmallImage[saveImageIndex] = UCTemplatePic.ZoomImage(picShow.Image, UCUISmallPicWidth, UCUISmallPicHeight);
                    }
                }
                else
                {
                    InsertImage();
                }
            }
        }
Example #3
0
        /// <summary>
        /// 插入图片
        /// </summary>
        /// <returns>返回ID</returns>
        int  InsertImage()
        {
            int outI = 0;

            if (UCInputMainType == 1)//数据库交互模式
            {
                string sql = "";
                switch (UCInputDBSaveType)
                {
                case 1:    //存储在同一张表内,依旧使用Update方法
                    sql = "UPDATE " + UCDBTableName + " SET " + UCDBPicFieldName + "=@" + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != string.Empty)
                    {
                        sql += "," + UCDBSmallPicFieldName + "=@" + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + UCDBRemarkFieldName;
                        sql += "=" + SysString.ToDBString(txtRemark.Text.Trim());
                    }
                    if (UCDBMainIDFieldName != string.Empty)
                    {
                        sql += "," + UCDBMainIDFieldName + "=" + UCDataID;
                    }
                    if (UCDBStyleNoFieldName != string.Empty)
                    {
                        sql += "," + UCDBStyleNoFieldName + "=" + SysString.ToDBString(UCDataStyleNo);
                    }
                    sql += " WHERE ID=" + UCDataID;
                    outI = UCDataID;
                    break;

                case 2:    //存储在独立的数据表内

                    sql = "SELECT MAX(ID) ID FROM " + UCDBTableName;
                    DataTable dt = PicFill(sql);
                    if (dt.Rows.Count != 0)
                    {
                        outI = SysConvert.ToInt32(dt.Rows[0]["ID"]) + 1;
                    }


                    sql = "INSERT INTO " + UCDBTableName + " (ID," + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != "")
                    {
                        sql += "," + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + UCDBRemarkFieldName;
                    }
                    sql += "," + UCDBMainIDFieldName;
                    if (UCDBStyleNoFieldName != string.Empty)
                    {
                        sql += "," + UCDBStyleNoFieldName;
                    }
                    sql += ") VALUES(";
                    sql += outI.ToString() + ",";  //ID
                    sql += @"@" + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != "")
                    {
                        sql += "," + @"@" + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + SysString.ToDBString(txtRemark.Text.Trim());
                    }
                    sql += "," + SysString.ToDBString(UCDataID.ToString());
                    if (UCDBStyleNoFieldName != string.Empty)
                    {
                        sql += "," + SysString.ToDBString(UCDataStyleNo);
                    }
                    sql += ")";
                    break;
                }

                int len = 1;
                if (UCDBSmallPicFieldName != string.Empty)
                {
                    len = 2;
                }
                object[,] obja = new object[2, len];
                obja[0, 0]     = "@" + UCDBPicFieldName;
                obja[1, 0]     = UCTemplatePic.ImageToByte(UCTemplatePic.ZoomImage(picShow.Image, UCUIPicWidth, UCUIPicHeight));
                if (UCDBSmallPicFieldName != string.Empty)
                {
                    obja[0, 1] = "@" + UCDBSmallPicFieldName;
                    obja[1, 1] = UCTemplatePic.ImageToByte(UCTemplatePic.ZoomImage(picShow.Image, UCUISmallPicWidth, UCUISmallPicHeight));
                }
                PicExecuteNonQuery(sql, obja); //SysUtils.ExecuteNonQuery
            }
            else if (UCInputMainType == 2)     //仅是图片交互模式
            {
                //代码待补充
                m_UCDataLstImage.Add(UCTemplatePic.ZoomImage(picShow.Image, UCUIPicWidth, UCUIPicHeight));

                m_UCDataLstSmallImage.Add(UCTemplatePic.ZoomImage(picShow.Image, UCUISmallPicWidth, UCUISmallPicHeight));
            }

            return(outI);
        }