TIFF图像重命名与重新设计 [英] tiff image rename with resoulition

查看:96
本文介绍了TIFF图像重命名与重新设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用系统;
使用System.Configuration;
使用System.Data;
使用System.Data.OracleClient;
使用System.IO;
使用System.Net;
使用System.Net.Mail;
使用System.Windows.Forms;
使用Tela.OCLEVER.Common;
使用System.Diagnostics;
使用System.Collections.Generic;
使用System.Text;
使用System.Data.OleDb;
使用System.Data.Odbc;
使用System.Collections;
使用System.Drawing.Imaging;
使用System.Drawing;


名称空间Tela.OCLEVER.Prepping.MCI
{
公共局部类CCMDCNRenamingForm:Form
{
数据库db = new Database();
字符串batchNo_1 =";
字符串batchNo_2 =";
字符串batchNo_3 =";
字符串batchNo_4 =";
字符串batchNo_5 =";
字符串batchNo_6 =";
字符串batchNo_7 =";
字符串batchNo_9 =";
字符串batchNo_8 =";
字符串batchNo_10 =";
字符串batchNo_11 =";
字符串batchNo_12 =";
字符串batchNo_13 =";
字符串batchNo_14 =";
字符串batchNo_15 =";
字符串batchNo_16 =";
字符串batchNo_17 =";
字符串batchNo_18 =";
字符串batchNo_19 =";
字符串batchNo_20 =";
int cnt1 = 0;
int cnt2 = 0;
int cnt3 = 0;
int cnt4 = 0;
int cnt5 = 0;
int cnt6 = 0;
int cnt7 = 0;
int cnt8 = 0; int cnt9 = 0; int cnt10 = 0; int cnt11 = 0; int cnt12 = 0; int cnt13 = 0; int cnt14 = 0; int cnt15 = 0; int cnt16 = 0; int cnt17 = 0; int cnt18 = 0; int cnt19 = 0; int cnt20 = 0;
字符串cnt1_ =";
字符串cnt2_ =";
字符串cnt3_ =";
字符串cnt4_ =";
字符串cnt5_ =";
字符串cnt6_ =";
字符串cnt7_ =";
字符串cnt8_ =";字符串cnt9_ =";字符串cnt10_ =";字符串cnt11_ =";字符串cnt12_ =";字符串cnt13_ =";字符串cnt14_ =";字符串cnt15_ =";字符串cnt16_ =";字符串cnt17_ =";字符串cnt18_ =";字符串cnt19_ =";字符串cnt20_ =";




DataTable dt = new DataTable();
字符串FilePath =";
bool imagefound = false;
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"^(([1-9])|(0 [1-9])|(1 [0-2]))(( [0-9])|([0-2] [0-9])|(3 [0-1]))(([[0-9] [0-9])|([1-2] [ 0,9] [0-9] [0-9]))$);
公共CCMDCNRenamingForm()
{
InitializeComponent();
}



private void button1_Click(对象发送者,EventArgs e)
{
FolderBrowserDialog f =新的System.Windows.Forms.FolderBrowserDialog();
如果(f.ShowDialog()== DialogResult.OK)
{
txt_FolderPath.Text = f.SelectedPath;
}
}

字符串GETSR(int count)
{
字符串sr =";



如果(计数< == 100)
{
sr ="1000" + count.ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则,如果(sr.Length == 7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}

否则,如果(计数> 100&&计数< = 200)
{
sr ="2000" +(计数-100).ToString();

如果(sr.Length == 6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
否则,如果(计数> 200&&计数< = 300)
{
sr ="3000" +(计数-200).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
否则,如果(计数> 300&&计数< = 400)
{
sr ="4000" +(计数-300).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则,如果(sr.Length == 7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
否则,如果(计数> 400&&计数< = 500)
{
sr ="5000" +(计数-400).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
否则,如果(计数> 500&&计数< = 600)
{
sr ="6000" +(计数-500).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}

否则,如果(计数> 600&&< = 700)
{
sr ="7000" +(计数-600).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}


}

否则,如果(count> 700&& count&=; 800)
{
sr ="8000" +(计数-700).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
否则,如果(计数> 800&&计数< = 900)
{
sr ="9000" +(计数-800).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
否则,如果(计数> 900&&计数< = 1000)
{
sr ="10000" +(计数-900).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(0,2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(0,3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
否则,如果(sr.Length == 8)
{
sr = sr.Remove(0,4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
否则(计数> 1000&&计数< = 1100)
{
sr ="11000" +(计数-1000).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(0,2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则,如果(sr.Length == 7)
{
sr = sr.Remove(0,3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
否则,如果(sr.Length == 8)
{
sr = sr.Remove(0,4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
否则,如果(计数> 1100&&计数< = 1200)
{
sr ="12000" +(计数-1100).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(0,2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(0,3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
否则,如果(sr.Length == 8)
{
sr = sr.Remove(0,4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
否则(计数> 1200&&计数< = 1300)
{
sr ="13000" +(计数-1200).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(0,2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(0,3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
否则,如果(sr.Length == 8)
{
sr = sr.Remove(0,4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
否则(计数> 1300&&计数< = 1400)
{
sr ="14000" +(计数-1300).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(0,2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则,如果(sr.Length == 7)
{
sr = sr.Remove(0,3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
否则,如果(sr.Length == 8)
{
sr = sr.Remove(0,4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
否则,如果(计数> 1400&&计数< = 1500)
{
sr ="15000" +(计数-1400).ToString();
如果(sr.Length == 6)
{
sr = sr.Remove(0,2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
否则(sr.Length == 7)
{
sr = sr.Remove(0,3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
否则,如果(sr.Length == 8)
{
sr = sr.Remove(0,4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}

return sr;
}

bool checkvaliddate(string date1)
{
字符串年份= date1.Substring(0,4);
字符串月份= date1.Substring(4,2);
字符串日= date1.Substring(6,2);
date1 =月+日+年;
bool标志= false;
如果(regex.IsMatch(date1))
标志= true;
其他
标志=假;

返回标志;
}



void copyDirectory(字符串Src,字符串Dst)
{
字符串来源= Src;
字符串[]文件;
if(Dst [Dst.Length-1]!= Path.DirectorySeparatorChar)
Dst + = Path.DirectorySeparatorChar;
if(!Directory.Exists(Dst))
Directory.CreateDirectory(Dst);
Files = Directory.GetFileSystemEntries(Src);
foreach(文件中的字符串元素)
{
//子目录
if(Directory.Exists(Element))
copyDirectory(Element,Dst + Path.GetFileName(Element));
//目录中的文件
其他
File.Copy(Element,Path.Combine(Dst,Path.GetFileName(Element)),true);
}

}

公共无效reset()
{
batchNo_1 =";//,batchNo_1,batchNo_1,batchNo_1,batchNo_1 =";
batchNo_2 =";
batchNo_3 =";
batchNo_4 =";
batchNo_5 =";
batchNo_6 =";
batchNo_7 =";
batchNo_8 =";
batchNo_9 =";
batchNo_10 =";
batchNo_11 =";
batchNo_12 =";
batchNo_13 =";
batchNo_14 =";
batchNo_15 =";
batchNo_16 =";
batchNo_17 =";
batchNo_18 =";
batchNo_19 =";
batchNo_20 =";
cnt1 = 0;
cnt2 = 0;
cnt3 = 0;
cnt4 = 0;
cnt5 = 0;
cnt6 = 0;
cnt7 = 0;
cnt8 = 0;
cnt9 = 0;
cnt10 = 0;
cnt11 = 0;
cnt12 = 0;
cnt13 = 0;
cnt14 = 0;
cnt15 = 0;
cnt16 = 0;
cnt17 = 0;
cnt18 = 0;
cnt19 = 0;
cnt20 = 0;

cnt1_ =";
cnt2_ =";
cnt3_ =";
cnt4_ =";
cnt5_ =";
cnt6_ =";
cnt7_ =";
cnt8_ =";
cnt9_ =";
cnt10_ =";
cnt11_ =";
cnt12_ =";
cnt13_ =";
cnt14_ =";
cnt15_ =";
cnt16_ =";
cnt17_ =";
cnt18_ =";
cnt19_ =";
cnt20_ =";
}

私有void btn_submit_Click(对象发送者,EventArgs e)
{


btn_submit.Enabled = false;
btn_Cancal.Enabled = false;
btn_report.Enabled = false;
reset();
试试
{
如果(rdbadvanced.Checked == true)
{
如果(cmbdpi.SelectedItem.ToString()=="--- Select ---" || cmbheight.SelectedItem.ToString()=="--- Select ---" || cmbwidth.SelectedItem.ToString()= ="---选择---")
{
MessageBox.Show(请正确选择高级功能.","Error",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
返回;

}

}


if(comboBox1.Text!=-选择过程-")
{
如果(txt_FolderPath.Text ==")
{
MessageBox.Show(请选择文件夹",错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;
返回;
}

如果(comboBox1.SelectedItem.ToString()=="HCFA"&& comboBox2.SelectedItem.ToString()=="CCM")
{
字符串p_Type ="CCM1H";
字符串p_ID ="185";
RenameFunction(p_Type,p_ID);
返回;
}
如果(comboBox1.SelectedItem.ToString()=="UB"&& comboBox2.SelectedItem.ToString()=="CCM")
{
字符串p_Type ="CCM1U";
字符串p_ID ="78";
RenameFunction(p_Type,p_ID);
返回;
}
如果(comboBox1.SelectedItem.ToString()=="HCFA"&& comboBox2.SelectedItem.ToString()=="SSB")
{
字符串p_Type ="SSBNH";
字符串p_ID ="191";
RenameFunction(p_Type,p_ID);
返回;
}
如果(comboBox1.SelectedItem.ToString()=="HCFA Reprice"&& comboBox2.SelectedItem.ToString()=="SSB")
{
字符串p_Type ="SSBRH";
字符串p_ID ="191";
RenameFunction(p_Type,p_ID);
返回;

}
如果(comboBox1.SelectedItem.ToString()=="HCFA EOB"&& comboBox2.SelectedItem.ToString()=="SSB")
{
字符串p_Type ="SSBOH";
字符串p_ID ="191";
RenameFunction(p_Type,p_ID);
返回;

}

如果(comboBox1.SelectedItem.ToString()=="UB"&& comboBox2.SelectedItem.ToString()=="SSB")
{
字符串p_Type ="SSBNU";
字符串p_ID ="192";
RenameFunction(p_Type,p_ID);
返回;
}
如果(comboBox1.SelectedItem.ToString()=="UB Reprice"&& comboBox2.SelectedItem.ToString()=="SSB")
{
字符串p_Type ="SSBRU";
字符串p_ID ="192";
RenameFunction(p_Type,p_ID);
返回;
}
如果(comboBox1.SelectedItem.ToString()=="UB EOB"&& comboBox2.SelectedItem.ToString()=="SSB")
{
字符串p_Type ="SSBOU";
字符串p_ID ="192";
RenameFunction(p_Type,p_ID);
返回;

}
如果(comboBox1.SelectedItem.ToString()=="Dental"&& comboBox2.SelectedItem.ToString()=="SSB")
{
字符串p_Type ="SSBND";
字符串p_ID ="193";
RenameFunction(p_Type,p_ID);
返回;
}


}
其他
{
MessageBox.Show(请选择进程",错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
返回;
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

}

}
catch(ex ex例外)
{
MessageBox.Show(ex.Message.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
txt_FolderPath.Text =";
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;
progressBar1.Visible = false;

}



}

公共无效RenameFunction(字符串ptype,字符串p_ID)
{
Cursor.Current = Cursors.WaitCursor;
Application.DoEvents();
string [] GetBatchNames = Directory.GetDirectories(txt_FolderPath.Text);
字符串路径=";

如果(Directory.Exists(txt_FolderPath.Text))
{
字符串Orignal =";
Orignal = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"Orignal_Images");

copyDirectory(txt_FolderPath.Text,Orignal);
DirectoryInfo BatchName =新的DirectoryInfo(txt_FolderPath.Text);

FileInfo []图片名称= BatchName.GetFiles("*.tif",SearchOption.AllDirectories);
如果(Imagenames.Length> 0)
{

字符串DuplicateFolder =";
DuplicateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images");

如果(!Directory.Exists(DuplicateFolder))
{
Directory.CreateDirectory(DuplicateFolder);
}



create_batch_HCFA(ptype,p_ID);

字符串来源= txt_FolderPath.Text;
copyDirectory(Orignal,source);
Directory.Delete(Orignal,true);
MessageBox.Show(操作已完成.\ n总计-" +图像名称.长度+已处理图像.\ n已创建的批处理-\ n" + batchNo_1 +" + cnt1_ +"\ n" + batchNo_2 +" + cnt2_ +"\ n" + batchNo_3 +" + cnt3_ +"\ n" + batchNo_4 +" + cnt4_ +"\ n" + batchNo_5 +" + cnt5_ +"\ n" + batchNo_6 +""+ cnt6_ +" \ n"+ batchNo_7 +""+ cnt7_ +" \ n"+ batchNo_8 +""+ cnt8_ +" \ n"+ batchNo_9 +""+ cnt9_ +" \ n"+ batchNo_10 +""+ cnt10_ +"\ n" + batchNo_11 +" + cnt11_ +"\ n" + batchNo_12 +" + cnt12_ +"\ n" + batchNo_13 +" + cnt13_ +"\ n" + batchNo_14 +" + cnt14_ + "\ n" + batchNo_15 +" + cnt15_ +",图像重命名器",MessageBoxButtons.OK,MessageBoxIcon.Information);
//comboBox1.SelectedText =("--Select Process--");
Application.DoEvents();

txt_FolderPath.Text =";

Process.Start(DuplicateFolder);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

progressBar1.Visible = false;
返回;
}
其他
{
MessageBox.Show(所选文件夹中没有.tif图像",错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
txt_FolderPath.Text =";
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

progressBar1.Visible = false;
}
}

}

私有void Form1_Load(对象发送者,EventArgs e)
{
groupBox1.Enabled = false;

comboBox1.SelectedText =("---选择---");
comboBox2.SelectedText =("---选择---");
cmbheight.SelectedText =("--- Select ---");
cmbdpi.SelectedText =("--- Select ---");
cmbwidth.SelectedText =("--- Select ---");


progressBar1.Value = 0;
progressBar1.Visible = false;


}



静态图像FixedSize(图像imgPhoto,int宽度,int高度,字符串file_name,int dpi)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;

nPercentW =((float)Width/(float)sourceWidth);
nPercentH =((float)Height/(float)sourceHeight);
如果(nPercentH< nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width-(sourceWidth * nPercent))/2);
}
其他
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height-(sourceHeight * nPercent))/2);
}

int destWidth =(int)(sourceWidth * nPercent);
int destHeight =(int)(sourceHeight * nPercent);

位图bmPhoto =新位图(宽度,高度,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.Horizo​​ntalResolution,imgPhoto.VerticalResolution);
bmPhoto.SetResolution(dpi,dpi);
图形grPhoto = Graphics.FromImage(bmPhoto);
//grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto,新Rectangle(destX,destY,destWidth,destHeight),新Rectangle(sourceX,sourceY,sourceWidth,sourceHeight),GraphicsUnit.Pixel);
bmPhoto.Save(文件名);
grPhoto.Dispose();
返回bmPhoto;
}


公共无效create_batch_HCFA(字符串processType,字符串pId)
{
DirectoryInfo BatchName =新的DirectoryInfo(txt_FolderPath.Text);



FileInfo []图片名称= BatchName.GetFiles("*.tif",SearchOption.AllDirectories);
StringBuilder osb = new StringBuilder();
osb.AppendLine("DECLARE");
osb.AppendLine("vIMGID NUMBER;");
osb.Append("Begin");
如果(Imagenames.Length< 1500)
{



progressBar1.Value = 10;
progressBar1.Minimum = 0;
progressBar1.Maximum =图片名称.长度;
for(int i = 0; i< Imagenames.Length; i ++)
{

progressBar1.Value = i;

如果(i< 100)
{

字符串Batch_Folder =";

字符串Temp =";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),Temp);

如果(!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

字符串sr = GETSR(i + 1);
字符串源= Imagenames [i] .DirectoryName +"\\" + Imagenames [i] .Name;

字符串OutPutfileName = processType +"120118" +"00" + sr +".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),processType +"120118" +"001");
batchNo_1 = processType +"120118" +"001";
如果(!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder + ="\\" + OutPutfileName;

如果(rdbadvanced.Checked == true)
{
使用(位图bmp =(位图)Bitmap.FromFile(源))
{
FixedSize(bmp,Convert.ToInt32(cmbwidth.SelectedItem.ToString()),Convert.ToInt32(cmbheight.SelectedItem.ToString()),Batch_Folder,Convert.ToInt32(cmbdpi.SelectedItem.ToString())+ 1);
}

}
其他
{
File.Move(source,Batch_Folder);

}



progressBar1.Visible = true;
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME(PROCESS_ID,BATCHNO,OLD_IMAGENAME,NEW_IMAGENAME,SCAN_DATE)VALUES(" + pId +,""+ batchNo_1 +",""+图像名称[i] .ToString() +"," + OutPutfileName +"," + DateTime.Now.ToString("dd-MMM-yy")+''); \ n");
cnt1 ++;
cnt1_ =-" + cnt1.ToString()+图片.";


}
如果(i> = 100& i< 200)
{
//progressBar1.Value = 60;
字符串Batch_Folder =";

字符串Temp =";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),Temp);

如果(!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

字符串sr = GETSR(i + 1);
字符串源= Imagenames [i] .DirectoryName +"\\" + Imagenames [i] .Name;

字符串OutPutfileName = processType +"120118" +"00" + sr +".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),processType +"120118" +"002");
batchNo_2 = processType +"120118" +"002";
如果(!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder + ="\\" + OutPutfileName;
如果(rdbadvanced.Checked == true)
{
使用(位图bmp =(位图)Bitmap.FromFile(源))
{
FixedSize(bmp,Convert.ToInt32(cmbwidth.SelectedItem.ToString()),Convert.ToInt32(cmbheight.SelectedItem.ToString()),Batch_Folder,Convert.ToInt32(cmbdpi.SelectedItem.ToString())+ 1);
}

}
其他
{
File.Move(source,Batch_Folder);

}
//File.Move(source,Batch_Folder);
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME(PROCESS_ID,BATCHNO,OLD_IMAGENAME,NEW_IMAGENAME,SCAN_DATE)VALUES(" + pId +,""+ batchNo_2 +",""+图像名称[i] .ToString() +"," + OutPutfileName +"," + DateTime.Now.ToString("dd-MMM-yy")+''); \ n");
cnt2 ++;
cnt2_ =-" + cnt2.ToString()+图片.";
}
如果(i> = 200& i< 300)
{
//progressBar1.Value = 90;
字符串Batch_Folder =";

字符串Temp =";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),Temp);

如果(!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

字符串sr = GETSR(i + 1);
字符串源= Imagenames [i] .DirectoryName +"\\" + Imagenames [i] .Name;

字符串OutPutfileName = processType +"120118" +"00" + sr +".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),processType +"120118" +"003");
batchNo_3 = processType +"120118" +"003";
如果(!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder + ="\\" + OutPutfileName;

如果(rdbadvanced.Checked == true)
{
使用(位图bmp =(位图)Bitmap.FromFile(源))
{
FixedSize(bmp,Convert.ToInt32(cmbwidth.SelectedItem.ToString()),Convert.ToInt32(cmbheight.SelectedItem.ToString()),Batch_Folder,Convert.ToInt32(cmbdpi.SelectedItem.ToString())+ 1);
}

}
其他
{
File.Move(source,Batch_Folder);

}

osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME(PROCESS_ID,BATCHNO,OLD_IMAGENAME,NEW_IMAGENAME,SCAN_DATE)VALUES(" + pId +,""+ batchNo_3 +",""+图像名称[i] .ToString() +"," + OutPutfileName +"," + DateTime.Now.ToString("dd-MMM-yy")+''); \ n");
cnt3 ++;
cnt3_ =-" + cnt3.ToString()+图片.";
}
如果(i> = 300& i< 400)
{
//progressBar1.Value = 100;
字符串Batch_Folder =";

字符串Temp =";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),Temp);

如果(!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

字符串sr = GETSR(i + 1);
字符串源= Imagenames [i] .DirectoryName +"\\" + Imagenames [i] .Name;

字符串OutPutfileName = processType +"120118" +"00" + sr +".tif"; //+
batchNo_4 = processType +"120118" +"004";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),processType +"120118" +"004");

如果(!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder + ="\\" + OutPutfileName;

如果(rdbadvanced.Checked == true)
{
使用(位图bmp =(位图)Bitmap.FromFile(源))
{
FixedSize(bmp,Convert.ToInt32(cmbwidth.SelectedItem.ToString()),Convert.ToInt32(cmbheight.SelectedItem.ToString()),Batch_Folder,Convert.ToInt32(cmbdpi.SelectedItem.ToString())+ 1);
}

}
其他
{
File.Move(source,Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME(PROCESS_ID,BATCHNO,OLD_IMAGENAME,NEW_IMAGENAME,SCAN_DATE)VALUES(" + pId +,""+ batchNo_4 +",""+图像名称[i] .ToString() +"," + OutPutfileName +"," + DateTime.Now.ToString("dd-MMM-yy")+''); \ n");
cnt4 ++;
cnt4_ =-" + cnt4.ToString()+图片.";
}
如果(i> = 400& i< 500)
{
字符串Batch_Folder =";

字符串Temp =";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),Temp);

如果(!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

字符串sr = GETSR(i + 1);
字符串源= Imagenames [i] .DirectoryName +"\\" + Imagenames [i] .Name;

字符串OutPutfileName = processType +"120118" +"00" + sr +".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),processType +"120118" +"005");
batchNo_5 = processType +"120118" +"005";
如果(!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder + ="\\" + OutPutfileName;

如果(rdbadvanced.Checked == true)
{
使用(位图bmp =(位图)Bitmap.FromFile(源))
{
FixedSize(bmp,Convert.ToInt32(cmbwidth.SelectedItem.ToString()),Convert.ToInt32(cmbheight.SelectedItem.ToString()),Batch_Folder,Convert.ToInt32(cmbdpi.SelectedItem.ToString())+ 1);
}

}
其他
{
File.Move(source,Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME(PROCESS_ID,BATCHNO,OLD_IMAGENAME,NEW_IMAGENAME,SCAN_DATE)VALUES(" + pId +,""+ batchNo_5 +",""+图像名称[i] .ToString() +"," + OutPutfileName +"," + DateTime.Now.ToString("dd-MMM-yy")+''); \ n");
cnt5 ++;
cnt5_ =-" + cnt5.ToString()+图片.";
}
如果(i> = 500& i< 600)
{
字符串Batch_Folder =";

字符串Temp =";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),Temp);

如果(!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

字符串sr = GETSR(i + 1);
字符串源= Imagenames [i] .DirectoryName +"\\" + Imagenames [i] .Name;

字符串OutPutfileName = processType +"120118" +"00" + sr +".tif"; //+
batchNo_6 = processType +"120118" +"006";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),processType +"120118" +"006");

如果(!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder + ="\\" + OutPutfileName;

如果(rdbadvanced.Checked == true)
{
使用(位图bmp =(位图)Bitmap.FromFile(源))
{
FixedSize(bmp,Convert.ToInt32(cmbwidth.SelectedItem.ToString()),Convert.ToInt32(cmbheight.SelectedItem.ToString()),Batch_Folder,Convert.ToInt32(cmbdpi.SelectedItem.ToString())+ 1);
}

}
其他
{
File.Move(source,Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME(PROCESS_ID,BATCHNO,OLD_IMAGENAME,NEW_IMAGENAME,SCAN_DATE)VALUES(" + pId +,""+ batchNo_6 +",""+图像名称[i] .ToString() +"," + OutPutfileName +"," + DateTime.Now.ToString("dd-MMM-yy")+''); \ n");

cnt6 ++;
cnt6_ =-" + cnt6.ToString()+图片.";
}
如果(i> = 600& i< 700)
{
字符串Batch_Folder =";

字符串Temp =";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),Temp);

如果(!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

字符串sr = GETSR(i + 1);
字符串源= Imagenames [i] .DirectoryName +"\\" + Imagenames [i] .Name;

字符串OutPutfileName = processType +"120118" +"00" + sr +".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),processType +"120118" +"007");
batchNo_7 = processType +"120118" +"007";
如果(!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder + ="\\" + OutPutfileName;

如果(rdbadvanced.Checked == true)
{
使用(位图bmp =(位图)Bitmap.FromFile(源))
{
FixedSize(bmp,Convert.ToInt32(cmbwidth.SelectedItem.ToString()),Convert.ToInt32(cmbheight.SelectedItem.ToString()),Batch_Folder,Convert.ToInt32(cmbdpi.SelectedItem.ToString())+ 1);
}

}
其他
{
File.Move(source,Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME(PROCESS_ID,BATCHNO,OLD_IMAGENAME,NEW_IMAGENAME,SCAN_DATE)VALUES(" + pId +,""+ batchNo_7 +",""+图像名称[i] .ToString() +"," + OutPutfileName +"," + DateTime.Now.ToString("dd-MMM-yy")+''); \ n");
cnt7 ++;
cnt7_ =-" + cnt7.ToString()+图片.";
}
如果(i> = 700& i< 800)
{
字符串Batch_Folder =";

字符串Temp =";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),Temp);

如果(!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

字符串sr = GETSR(i + 1);
字符串源= Imagenames [i] .DirectoryName +"\\" + Imagenames [i] .Name;

字符串OutPutfileName = processType +"120118" +"00" + sr +".tif"; //+
batchNo_8 = processType +"120118" +"008";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),batchNo_8);

如果(!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder + ="\\" + OutPutfileName;

如果(rdbadvanced.Checked == true)
{
使用(位图bmp =(位图)Bitmap.FromFile(源))
{
FixedSize(bmp,Convert.ToInt32(cmbwidth.SelectedItem.ToString()),Convert.ToInt32(cmbheight.SelectedItem.ToString()),Batch_Folder,Convert.ToInt32(cmbdpi.SelectedItem.ToString())+ 1);
}

}
其他
{
File.Move(source,Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME(PROCESS_ID,BATCHNO,OLD_IMAGENAME,NEW_IMAGENAME,SCAN_DATE)VALUES(" + pId +,""+ batchNo_8 +"''," +图像名称[i] .ToString( )+'',""+ OutPutfileName +",""+ DateTime.Now.ToString(" dd-MMM-yy)+"''); \ n);
cnt8 ++;
cnt8_ =-" + cnt8.ToString()+图片.";

}
如果(i> = 800& i< 900)
{
字符串Batch_Folder =";

字符串Temp =";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"Renamed_Images"),Temp);

如果(!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; //+
batchNo_9 = processType +"120118" + "009";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_9);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_9 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt9++;
cnt9_ = " - " + cnt9.ToString() + " Images.";

}
if (i >= 900 && i < 1000)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_10 = processType +"120118" + "010";
string OutPutfileName = batchNo_10 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_10);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_10 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt10++;
cnt10_ = " - " + cnt10.ToString() + " Images.";

}


if (i >= 1000 && i < 1100)
{
// progressBar1.Value = 60;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_11 = processType +"120118" + "011";
string OutPutfileName = batchNo_11 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_11);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_11 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt11++;
cnt11_ = " - " + cnt11.ToString() + " Images.";
}
if (i >= 1100 && i < 1200)
{
// progressBar1.Value = 90;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_12 = processType +"120118" + "012";
string OutPutfileName = batchNo_12 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_12);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}

osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_12 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt12++;
cnt12_ = " - " + cnt12.ToString() + " Images.";
}
if (i >= 1200 && i < 1300)
{
//progressBar1.Value = 100;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_13 = processType +"120118" + "013";
string OutPutfileName = batchNo_13 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_13);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_13 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt13++;
cnt13_ = " - " + cnt13.ToString() + " Images.";
}
if (i >= 1300 && i < 1400)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_14 = processType +"120118" + "014";
string OutPutfileName = batchNo_14 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_14);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_14 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt14++;
cnt14_ = " - " + cnt14.ToString() + " Images.";
}
if (i >= 1400 && i < 1500)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_15 = processType +"120118" + "015";
string OutPutfileName = batchNo_15 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_15);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_15 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");

cnt15++;
cnt15_ = " - " + cnt15.ToString() + " Images.";
}



}
osb.Append("End;");
db.InsertDeleteUpdate(osb.ToString());



}
其他
{
MessageBox.Show("Image Should be less than 1500", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}

public void GenerateReport(string p_id_HCFA, string p_id_UB, string p_id_DENTAL, string PType)
{
string R_folder = "";

//if (p_id_HCFA != "" && p_id_UB == "" && p_id_DENTAL == "")
//{
// //p_id_UB = "," + p_id_UB + " ";

//}

//if (p_id_HCFA == "" && p_id_UB != "" && p_id_DENTAL == "")
//{
// //p_id_UB = "," + p_id_UB + " ";

//}
//if (p_id_HCFA == "" && p_id_UB == "" && p_id_DENTAL != "")
//{
// //p_id_DENTAL = "," + p_id_DENTAL + " ";

//}
if (p_id_HCFA != "" && p_id_UB != "" && p_id_DENTAL != "")
{
p_id_UB = "," + p_id_UB + " ";
p_id_DENTAL = "," + p_id_DENTAL + " ";
}
if (p_id_HCFA != "" && p_id_UB != "" && p_id_DENTAL == "")
{
p_id_UB = "," + p_id_UB + " ";

}







string query = "SELECT OLD_IMAGENAME,NEW_IMAGENAME FROM CCM_IMAGE_RENAME WHERE PROCESS_ID IN ( " + p_id_HCFA + " " + p_id_UB + " " + p_id_DENTAL + ") AND BATCHNO IN ( SELECT batchno FROM HCFA_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_HCFA.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' union SELECT batchno FROM UB_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_UB.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' union SELECT batchno FROM DEN_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_DENTAL.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' ) ORDER BY new_imagename ASC ";
string q2 = "SELECT OLD_IMAGENAME,NEW_IMAGENAME FROM CCM_IMAGE_RENAME WHERE PROCESS_ID IN ( 78 ) AND BATCHNO IN ( SELECT batchno FROM HCFA_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '''' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' union SELECT batchno FROM UB_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''78'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' union SELECT batchno FROM DEN_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '''' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' ) ORDER BY new_imagename ASC ";
DataTable dtb = new DataTable();
dtb = db.GetTable(q2);
if (dtb.Rows.Count > 0)
{
string DuplicateFolder = "";
DuplicateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images_Report");

if (!Directory.Exists(DuplicateFolder))
{
Directory.CreateDirectory(DuplicateFolder);
}
R_folder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);


if (File.Exists(DuplicateFolder + "\\" + PType + "_" +"120118" + "_DCN_Report.txt"))
{
File.Delete(DuplicateFolder + "\\"+PType+"_" +"120118" + "_DCN_Report.txt");
}
FileInfo t = new FileInfo(DuplicateFolder + "\\"+PType+"_" +"120118" + "_DCN_Report.txt");
StreamWriter Tex = t.AppendText();
Tex.WriteLine("TCN Original_Name");
foreach (DataRow drPrintRow in dtb.Rows)
{
String str = drPrintRow["NEW_IMAGENAME"].ToString().Replace(".TIF", "").Replace(".tif", "") + " " + drPrintRow["OLD_IMAGENAME"].ToString().Replace(".TIF", "").Replace(".tif", "");
Tex.WriteLine(str);
}

Tex.Close();
MessageBox.Show("Report is generated.\nFile name is - " + ""+PType+"_" +"120118" + "_DCN_Report.txt", "Image Renamer", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.DoEvents();

txt_FolderPath.Text = "";

Process.Start(DuplicateFolder);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;



}
其他
{
MessageBox.Show("There is no batches to generate report for today''s date. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

}
}

private void btn_Cancal_Click(object sender, EventArgs e)
{
this.Close();
}

private void btn_report_Click(object sender, EventArgs e)
{
if (comboBox2.Text != "---Select---" && comboBox1.SelectedItem != null)
{

if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "185";
string p_Type_UB = "";
string p_Type_DENTAL = "";
string ptype = "CCM_HCFA";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "";
string p_Type_UB = "78";
string p_Type_DENTAL = "";

string ptype = "CCM_UB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;
}
if (comboBox1.SelectedItem.ToString() == "---Select---" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "185";
string p_Type_UB = "78";
string p_Type_DENTAL = "";

string ptype = "CCM";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;
}
if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "191";
string p_Type_UB = "";
string p_Type_DENTAL = "";
string ptype = "SSB_HCFA";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "";
string p_Type_UB = "192";
string p_Type_DENTAL = "";
string ptype = "SSB_UB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;

}
if (comboBox1.SelectedItem.ToString() == "Dental" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "";
string p_Type_UB = "";
string p_Type_DENTAL = "193";
string ptype = "SSB_DENTAL";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;

}

if (comboBox1.SelectedItem.ToString() == "---Select---" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "191";
string p_Type_UB = "192";
string p_Type_DENTAL = "193";
string ptype = "SSB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);

返回;
}




}
其他
{
MessageBox.Show("Please Select Correct Process Type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
返回;

}
btn_submit.Enabled = false;
btn_Cancal.Enabled = false;
btn_report.Enabled = false;





}

私有void comboBox1_SelectedIndexChanged(对象发送者,EventArgs e)
{

}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedItem.ToString()=="CCM")
{
comboBox1.Items.Remove("HCFA Reprice");
comboBox1.Items.Remove("HCFA EOB");
comboBox1.Items.Remove("UB Reprice");
comboBox1.Items.Remove("UB EOB");
comboBox1.Items.Remove("Dental");
comboBox1.Refresh();


}
if (comboBox2.SelectedItem.ToString() == "SSB")
{
if (comboBox1.Items.Count == 3)
{
comboBox1.Items.Add("HCFA Reprice");
comboBox1.Items.Add("HCFA EOB");
comboBox1.Items.Add("UB Reprice");
comboBox1.Items.Add("UB EOB");
comboBox1.Items.Add("Dental");

}


}


}

private void button1_Click_1(object sender, EventArgs e)
{
FolderBrowserDialog f = new System.Windows.Forms.FolderBrowserDialog();
if (f.ShowDialog() == DialogResult.OK)
{
txt_FolderPath.Text = f.SelectedPath;
}
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Enabled = false;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Enabled = true;

}


}
}





-------------------------------------------------- ------------------------------

使用系统;
使用System.Collections.Generic;
using System.ComponentModel;
使用System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Numeric;
using System.Linq;
使用System.Web;
使用System.Web;
using System.IO;




using System.Windows.Forms;

namespace demofortiff
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}




private void button1_Click(object sender, EventArgs e)
{
//using (Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\FHM1201101250028.tif"))
//{
// using (Bitmap newBitmap = new Bitmap(bitmap))
//{
// newBitmap.SetResolution(300, 300);
// newBitmap.Save("C:\\images\\file300", System.Drawing.Imaging.ImageFormat.Tiff);
//}
//}

int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif"))
{
//obtain the XResolution and YResolution TIFFTAG values
System.Drawing.Imaging. PropertyItem piXRes = bmp.GetPropertyItem(400);
System.Drawing.Imaging.PropertyItem piYRes = bmp.GetPropertyItem(400);

//values are stored as a rational number - numerator/denominator pair
numerator = BitConverter.ToInt32(piXRes.Value, 0);
denominator = BitConverter.ToInt32(piXRes.Value, 4);
float xRes = numerator/denominator;

numerator = BitConverter.ToInt32(piYRes.Value, 0);
denominator = BitConverter.ToInt32(piYRes.Value, 4);
float yRes = numerator/denominator;

//now set the values
byte[] numeratorBytes = new byte[4];
byte[] denominatorBytes = new byte[4];

numeratorBytes = BitConverter.GetBytes(600);//specify resolution in numerator
denominatorBytes = BitConverter.GetBytes(1);

Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4);//set the XResolution value
Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4);//set the YResolution value
Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);

bmp.SetPropertyItem(piXRes);//finally set the image property resolution
bmp.SetPropertyItem(piYRes);

// double ratio = maxWidth/finalWidth;
// int maxHeight = (int)img1.Height * ratio;
bmp.GetThumbnailImage(7000, 7000, null, IntPtr.Zero);



FixedSize(bmp, 200, 200);

bmp.SetResolution(600, 600);//now set the bitmap resolution

bmp.Save("C:\\images\\output.tif");//save the image
}


}
public static Bitmap Resize(Bitmap b, int nWidth, int nHeight)
{
Bitmap bTemp = (Bitmap)b.Clone();
b = new Bitmap(nWidth, nHeight, bTemp.PixelFormat);

double nXFactor = (double)bTemp.Width/(double)nWidth;
double nYFactor = (double)bTemp.Height/(double)nHeight;

for (int x = 0; x < b.Width; ++x)
for (int y = 0; y < b.Height; ++y)
b.SetPixel(x, y, bTemp.GetPixel((int)(Math.Floor(x * nXFactor)),
(int)(Math.Floor(y * nYFactor))));

return b;
}

private void button2_Click(object sender, EventArgs e)
{
//using (Image img = Image.FromStream(memoryStream))
//{
// Guid id = img.FrameDimensionsList[0];
// System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(id);
// int totalFrame = img.GetFrameCount(dimension);
// for (int i = 0; i < totalFrame; i++)
//{
// img.SelectActiveFrame(dimension, i);

// Faxed documents will have an non-square pixel aspect ratio.
// If this is the case,adjust the height so that the
// resulting pixels are square.
// int width = img.Width;
// int height = img.Height;
// if (img.VerticalResolution < img.HorizontalResolution)
//{
// height = (int)(height * img.HorizontalResolution/img.VerticalResolution);
// }

// bitmaps.Add(new Bitmap(img, new Size(width, height)));
//}
//}

//ImageCodecInfo ici = null;
//ImageCodecInfo[] Encoders = ImageCodecInfo.GetImageEncoders();
//foreach (ImageCodecInfo ListICI in Encoders)
//{
// if (ListICI.MimeType == "image/tiff")
//{
// ici = ListICI;
//中断;
//}
//}

////Can''t find the TIFF encoder
//if (ici == null) return;

////Set encoder to use no compression
//EncoderParameters ep = new EncoderParameters();
//ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone);

////Load a new image
//Bitmap TempImg = new Bitmap("C:\\images\\CCM_HB_20111228_0031901.tif");

//尝试
//{//Attempt to save the image
// TempImg.Save("C:\\images\\CCM_HB_20111228_.tif", ici, ep);
//}
//catch(异常前)
//{
// MessageBox.Show("Error saving image: " + ex.Message);
//}

//TempImg.Dispose();//Clean up
//ep.Dispose();

//Image tif = Image.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif");
//float width = tif.PhysicalDimension.Width;
//float height = tif.PhysicalDimension.Height;


//float hresolution = tif.HorizontalResolution;
//float vresolution = tif.VerticalResolution;






//tif.Dispose();


//MessageBox.Show(width.ToString());



int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif"))
{
//obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);

//values are stored as a rational number - numerator/denominator pair
//numerator = BitConverter.ToInt32(piXRes.Value, 0);
//denominator = BitConverter.ToInt32(piXRes.Value, 4);
//float xRes = numerator/denominator;

//numerator = BitConverter.ToInt32(piYRes.Value, 0);
//denominator = BitConverter.ToInt32(piYRes.Value, 4);
//float yRes = numerator/denominator;

////now set the values
//byte[] numeratorBytes = new byte[4];
//byte[] denominatorBytes = new byte[4];

//numeratorBytes = BitConverter.GetBytes(600);//specify resolution in numerator
//denominatorBytes = BitConverter.GetBytes(1);

//Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4);//set the XResolution value
//Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

//Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4);//set the YResolution value
//Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);
// float height = bmp.PhysicalDimension.Height;

//bmp.SetPropertyItem(height);//finally set the image property resolution
//bmp.SetPropertyItem(piYRes);







FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300);//now set the bitmap resolution

bmp.Save("C:\\images\\boutput12222.tif");//save the image
}






}

static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width/(float)sourceWidth);
nPercentH = ((float)Height/(float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent))/2);
}
其他
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent))/2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300 ,300);
图形grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
//grPhoto.Dispose();
//return bmPhoto;




//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

// Graphics grPhoto = Graphics.FromImage(bmPhoto);
//grPhoto.Clear(Color.Black);
////grPhoto.InterpolationMode =System.Drawing.Image.InterpolationMode.HighQualityBicubic;

// grPhoto.DrawImage(imgPhoto, new Rectangle(sourceX, sourceY, sourceX, sourceY), new Rectangle(destX, destY, destWidth, destHeight), GraphicsUnit.Pixel);

//bmPhoto.SetResolution(300, 300);
//ImageFormat.Tiff
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

//Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);



//bmPhoto.Save("C:\\images\\output1211.tif", encoderInfo, encoderParams);
//grPhoto.Dispose();
return bmPhoto;
}

private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
返回null;
}


private void button3_Click(对象发送者,EventArgs e)
{

Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif");
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
string jay = "C:\\images\\boutput12350.tif";


Image tiff = Image.FromStream(byteStream);
ImageCodecInfo encoderInfo = GetEncoderInfo ("image/tiff");

EncoderParameters encoderParams = new EncoderParameters(2);
EncoderParameter parameter = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = parameter;
parameter = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
encoderParams.Param[1] = parameter;
tiff.Save(jay, encoderInfo, encoderParams);
EncoderParameters EncoderParams = new EncoderParameters(2);
EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
EncoderParameter CompressionEncodeParam = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
EncoderParams.Param[0] = CompressionEncodeParam;
EncoderParams.Param[1] = SaveEncodeParam;
tiff.SaveAdd(EncoderParams);
//EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush);
//EncoderParams = new EncoderParameters(1);
//EncoderParams.Param[0] = SaveEncodeParam;
//tiff.SaveAdd(EncoderParams);







}



}
}

using System;
using System.Configuration;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Windows.Forms;
using Tela.OCLEVER.Common;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data.Odbc;
using System.Collections;
using System.Drawing.Imaging;
using System.Drawing;


namespace Tela.OCLEVER.Prepping.MCI
{
public partial class CCMDCNRenamingForm : Form
{
Database db = new Database();
string batchNo_1 = "";
string batchNo_2 = "";
string batchNo_3 = "";
string batchNo_4 = "";
string batchNo_5 = "";
string batchNo_6 = "";
string batchNo_7 = "";
string batchNo_9 = "";
string batchNo_8 = "";
string batchNo_10 = "";
string batchNo_11= "";
string batchNo_12 = "";
string batchNo_13 = "";
string batchNo_14 = "";
string batchNo_15 = "";
string batchNo_16 = "";
string batchNo_17 = "";
string batchNo_18 = "";
string batchNo_19 = "";
string batchNo_20 = "";
int cnt1 = 0;
int cnt2 = 0;
int cnt3 = 0;
int cnt4 = 0;
int cnt5 = 0;
int cnt6 = 0;
int cnt7 = 0;
int cnt8 = 0; int cnt9 = 0; int cnt10 = 0; int cnt11 = 0; int cnt12 = 0; int cnt13 = 0; int cnt14 = 0; int cnt15 = 0; int cnt16 = 0; int cnt17 = 0; int cnt18 = 0; int cnt19 = 0; int cnt20 = 0;
string cnt1_ = "";
string cnt2_ = "";
string cnt3_ = "";
string cnt4_ = "";
string cnt5_ = "";
string cnt6_ = "";
string cnt7_ = "";
string cnt8_ = ""; string cnt9_ = ""; string cnt10_ = ""; string cnt11_ = ""; string cnt12_ = ""; string cnt13_ = ""; string cnt14_ = ""; string cnt15_ = ""; string cnt16_ = ""; string cnt17_ = ""; string cnt18_ = ""; string cnt19_ = ""; string cnt20_ = "";




DataTable dt = new DataTable();
string FilePath = "";
bool imagefound = false;
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"^(([1-9])|(0[1-9])|(1[0-2]))(([0-9])|([0-2][0-9])|(3[0-1]))(([0-9][0-9])|([1-2][0,9][0-9][0-9]))$");
public CCMDCNRenamingForm()
{
InitializeComponent();
}



private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog f = new System.Windows.Forms.FolderBrowserDialog();
if (f.ShowDialog() == DialogResult.OK)
{
txt_FolderPath.Text = f.SelectedPath;
}
}

string GETSR(int count)
{
string sr = "";



if (count <= 100)
{
sr = "1000" + count.ToString();
if (sr.Length==6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length==7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}

else if (count > 100 && count <= 200)
{
sr = "2000" + (count - 100).ToString();

if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 200 && count <= 300)
{
sr = "3000" + (count - 200).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 300 && count <= 400)
{
sr = "4000" + (count - 300).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 400 && count <= 500)
{
sr = "5000" + (count - 400).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 500 && count <= 600)
{
sr = "6000" + (count - 500).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}

else if (count > 600 && count <= 700)
{
sr = "7000" + (count - 600).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}


}

else if (count > 700 && count <= 800)
{
sr = "8000" + (count - 700).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 800 && count <= 900)
{
sr = "9000" + (count - 800).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 900 && count <= 1000)
{
sr = "10000" + (count - 900).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1000 && count <= 1100)
{
sr = "11000" + (count - 1000).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0,2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1100 && count <= 1200)
{
sr = "12000" + (count - 1100).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1200 && count <= 1300)
{
sr = "13000" + (count - 1200).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1300 && count <= 1400)
{
sr = "14000" + (count - 1300).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 1400 && count <= 1500)
{
sr = "15000" + (count - 1400).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}

return sr;
}

bool checkvaliddate(string date1)
{
string year = date1.Substring(0, 4);
string month = date1.Substring(4, 2);
string day = date1.Substring(6, 2);
date1 = month +day+ year;
bool flag = false;
if (regex.IsMatch(date1))
flag = true;
else
flag = false;

return flag;
}



void copyDirectory(string Src, string Dst)
{
string source = Src;
String[] Files;
if(Dst[Dst.Length-1]!=Path.DirectorySeparatorChar)
Dst+=Path.DirectorySeparatorChar;
if(!Directory.Exists(Dst))
Directory.CreateDirectory(Dst);
Files=Directory.GetFileSystemEntries(Src);
foreach(string Element in Files)
{
// Sub directories
if(Directory.Exists(Element))
copyDirectory(Element,Dst+Path.GetFileName(Element));
// Files in directory
else
File.Copy(Element, Path.Combine(Dst ,Path.GetFileName(Element)),true);
}

}

public void reset()
{
batchNo_1 = "";//,batchNo_1,batchNo_1,batchNo_1,batchNo_1 = "";
batchNo_2 = "";
batchNo_3 = "";
batchNo_4 = "";
batchNo_5 = "";
batchNo_6 = "";
batchNo_7 = "";
batchNo_8 = "";
batchNo_9 = "";
batchNo_10 = "";
batchNo_11 = "";
batchNo_12 = "";
batchNo_13 = "";
batchNo_14 = "";
batchNo_15 = "";
batchNo_16 = "";
batchNo_17 = "";
batchNo_18 = "";
batchNo_19 = "";
batchNo_20 = "";
cnt1 = 0;
cnt2 = 0;
cnt3 = 0;
cnt4 = 0;
cnt5 = 0;
cnt6 = 0;
cnt7 = 0;
cnt8 = 0;
cnt9 = 0;
cnt10 = 0;
cnt11 = 0;
cnt12 = 0;
cnt13 = 0;
cnt14 = 0;
cnt15 = 0;
cnt16 = 0;
cnt17 = 0;
cnt18 = 0;
cnt19 = 0;
cnt20 = 0;

cnt1_ = "";
cnt2_ = "";
cnt3_ = "";
cnt4_ = "";
cnt5_ = "";
cnt6_ = "";
cnt7_ = "";
cnt8_ = "";
cnt9_ = "";
cnt10_ = "";
cnt11_ = "";
cnt12_ = "";
cnt13_ = "";
cnt14_ = "";
cnt15_ = "";
cnt16_ = "";
cnt17_ = "";
cnt18_ = "";
cnt19_ = "";
cnt20_ = "";
}

private void btn_submit_Click(object sender, EventArgs e)
{


btn_submit.Enabled = false;
btn_Cancal.Enabled = false;
btn_report.Enabled = false;
reset();
try
{
if (rdbadvanced.Checked == true)
{
if (cmbdpi.SelectedItem.ToString() == "---Select---" || cmbheight.SelectedItem.ToString() == "---Select---" || cmbwidth.SelectedItem.ToString() == "---Select---")
{
MessageBox.Show("Please select the advanced features correctly.", "Error ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;

}

}


if (comboBox1.Text != "--Select Process--")
{
if (txt_FolderPath.Text == "")
{
MessageBox.Show("Please Select the Folder", "Error ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;
return;
}

if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type = "CCM1H";
string p_ID = "185";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type = "CCM1U";
string p_ID = "78";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBNH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "HCFA Reprice" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBRH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
return;

}
if (comboBox1.SelectedItem.ToString() == "HCFA EOB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBOH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
return;

}

if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBNU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB Reprice" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBRU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB EOB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBOU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
return;

}
if (comboBox1.SelectedItem.ToString() == "Dental" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBND";
string p_ID = "193";
RenameFunction(p_Type, p_ID);
return;
}


}
else
{
MessageBox.Show("Please Select Process", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_FolderPath.Text = "";
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;
progressBar1.Visible = false;

}



}

public void RenameFunction(string ptype, string p_ID)
{
Cursor.Current = Cursors.WaitCursor;
Application.DoEvents();
string[] GetBatchNames = Directory.GetDirectories(txt_FolderPath.Text);
string path = "";

if (Directory.Exists(txt_FolderPath.Text))
{
string Orignal = "";
Orignal = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Orignal_Images");

copyDirectory(txt_FolderPath.Text, Orignal);
DirectoryInfo BatchName = new DirectoryInfo(txt_FolderPath.Text);

FileInfo[] Imagenames = BatchName.GetFiles("*.tif", SearchOption.AllDirectories);
if (Imagenames.Length > 0)
{

string DuplicateFolder = "";
DuplicateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images");

if (!Directory.Exists(DuplicateFolder))
{
Directory.CreateDirectory(DuplicateFolder);
}



create_batch_HCFA(ptype,p_ID);

string source = txt_FolderPath.Text;
copyDirectory(Orignal, source);
Directory.Delete(Orignal, true);
MessageBox.Show("Operation is Completed.\nTotal - " + Imagenames.Length + " Image(s) Processed.\nCreated Batche(s) are - \n" + batchNo_1 + "" + cnt1_ + " \n" + batchNo_2 + "" + cnt2_ + " \n" + batchNo_3 + "" + cnt3_ + " \n" + batchNo_4 + "" + cnt4_ + " \n" + batchNo_5 + "" + cnt5_ + " \n" + batchNo_6 + "" + cnt6_ + " \n" + batchNo_7 + "" + cnt7_ + " \n" + batchNo_8 + "" + cnt8_ + " \n" + batchNo_9 + "" + cnt9_ + "\n" + batchNo_10 + "" + cnt10_ + "\n" + batchNo_11 + "" + cnt11_ + "\n" + batchNo_12 + "" + cnt12_ + "\n" + batchNo_13 + "" + cnt13_ + "\n" + batchNo_14 + "" + cnt14_ + "\n" + batchNo_15 + "" + cnt15_ + "", "Image Renamer", MessageBoxButtons.OK, MessageBoxIcon.Information);
//comboBox1.SelectedText = ("--Select Process--");
Application.DoEvents();

txt_FolderPath.Text = "";

Process.Start(DuplicateFolder);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

progressBar1.Visible = false;
return;
}
else
{
MessageBox.Show("There is no .tif Image in selected folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_FolderPath.Text = "";
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

progressBar1.Visible = false;
}
}

}

private void Form1_Load(object sender, EventArgs e)
{
groupBox1.Enabled = false;

comboBox1.SelectedText = ("---Select---");
comboBox2.SelectedText = ("---Select---");
cmbheight.SelectedText = ("---Select---");
cmbdpi.SelectedText = ("---Select---");
cmbwidth.SelectedText = ("---Select---");


progressBar1.Value = 0;
progressBar1.Visible = false;


}



static Image FixedSize(Image imgPhoto, int Width, int Height,string file_name,int dpi)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;

nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(dpi, dpi);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
// grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
bmPhoto.Save(file_name);
grPhoto.Dispose();
return bmPhoto;
}


public void create_batch_HCFA(string processType, string pId)
{
DirectoryInfo BatchName = new DirectoryInfo(txt_FolderPath.Text);



FileInfo[] Imagenames = BatchName.GetFiles("*.tif", SearchOption.AllDirectories);
StringBuilder osb = new StringBuilder();
osb.AppendLine("DECLARE");
osb.AppendLine("vIMGID NUMBER;");
osb.Append("Begin ");
if (Imagenames.Length < 1500)
{



progressBar1.Value = 10;
progressBar1.Minimum = 0;
progressBar1.Maximum = Imagenames.Length;
for (int i = 0; i < Imagenames.Length; i++)
{

progressBar1.Value = i;

if (i < 100)
{

string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "001");
batchNo_1 = processType +"120118" + "001";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked==true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString())+1);
}

}
else
{
File.Move(source, Batch_Folder);

}



progressBar1.Visible = true;
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME,SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_1+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt1++;
cnt1_ = " - " + cnt1.ToString() + " Images.";


}
if (i >= 100 && i < 200)
{
// progressBar1.Value = 60;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "002");
batchNo_2 = processType +"120118" + "002";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;
if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
//File.Move(source, Batch_Folder);
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_2+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt2++;
cnt2_ = " - " + cnt2.ToString() + " Images.";
}
if (i >= 200 && i < 300)
{
// progressBar1.Value = 90;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "003");
batchNo_3 = processType +"120118" + "003";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}

osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_3+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt3++;
cnt3_ = " - " + cnt3.ToString() + " Images.";
}
if (i >= 300 && i < 400)
{
// progressBar1.Value = 100;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_4 = processType +"120118" + "004";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "004");

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_4+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt4++;
cnt4_ = " - " + cnt4.ToString() + " Images.";
}
if (i >= 400 && i < 500)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "005");
batchNo_5 = processType +"120118" + "005";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_5+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt5++;
cnt5_ = " - " + cnt5.ToString() + " Images.";
}
if (i >= 500 && i < 600)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_6 = processType +"120118" + "006";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "006");

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_6+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");

cnt6++;
cnt6_ = " - " + cnt6.ToString() + " Images.";
}
if (i >= 600 && i < 700)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "007");
batchNo_7 = processType +"120118" + "007";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_7+"'' ,''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt7++;
cnt7_ = " - " + cnt7.ToString() + " Images.";
}
if (i >= 700 && i < 800)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_8 = processType +"120118" + "008";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_8);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_8 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt8++;
cnt8_ = " - " + cnt8.ToString() + " Images.";

}
if (i >= 800 && i < 900)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_9 = processType +"120118" + "009";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_9);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_9 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt9++;
cnt9_ = " - " + cnt9.ToString() + " Images.";

}
if (i >= 900 && i < 1000)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_10 = processType +"120118" + "010";
string OutPutfileName = batchNo_10 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_10);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_10 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt10++;
cnt10_ = " - " + cnt10.ToString() + " Images.";

}


if (i >= 1000 && i < 1100)
{
// progressBar1.Value = 60;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_11 = processType +"120118" + "011";
string OutPutfileName = batchNo_11 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_11);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_11 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt11++;
cnt11_ = " - " + cnt11.ToString() + " Images.";
}
if (i >= 1100 && i < 1200)
{
// progressBar1.Value = 90;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_12 = processType +"120118" + "012";
string OutPutfileName = batchNo_12 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_12);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}

osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_12 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt12++;
cnt12_ = " - " + cnt12.ToString() + " Images.";
}
if (i >= 1200 && i < 1300)
{
// progressBar1.Value = 100;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_13 = processType +"120118" + "013";
string OutPutfileName = batchNo_13 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_13);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_13 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt13++;
cnt13_ = " - " + cnt13.ToString() + " Images.";
}
if (i >= 1300 && i < 1400)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_14 = processType +"120118" + "014";
string OutPutfileName = batchNo_14 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_14);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_14 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt14++;
cnt14_ = " - " + cnt14.ToString() + " Images.";
}
if (i >= 1400 && i < 1500)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_15 = processType +"120118" + "015";
string OutPutfileName = batchNo_15 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_15);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_15 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");

cnt15++;
cnt15_ = " - " + cnt15.ToString() + " Images.";
}



}
osb.Append("End;");
db.InsertDeleteUpdate(osb.ToString());



}
else
{
MessageBox.Show("Image Should be less than 1500", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}

public void GenerateReport(string p_id_HCFA, string p_id_UB, string p_id_DENTAL, string PType)
{
string R_folder = "";

//if (p_id_HCFA != "" && p_id_UB == "" && p_id_DENTAL == "")
//{
// // p_id_UB = "," + p_id_UB + " ";

//}

//if (p_id_HCFA == "" && p_id_UB != "" && p_id_DENTAL == "")
//{
// // p_id_UB = "," + p_id_UB + " ";

//}
//if (p_id_HCFA == "" && p_id_UB == "" && p_id_DENTAL != "")
//{
// // p_id_DENTAL = "," + p_id_DENTAL + " ";

//}
if (p_id_HCFA != "" && p_id_UB != "" && p_id_DENTAL != "")
{
p_id_UB = "," + p_id_UB + " ";
p_id_DENTAL = "," + p_id_DENTAL + " ";
}
if (p_id_HCFA != "" && p_id_UB != "" && p_id_DENTAL == "")
{
p_id_UB = "," + p_id_UB + " ";

}







string query = "SELECT OLD_IMAGENAME,NEW_IMAGENAME FROM CCM_IMAGE_RENAME WHERE PROCESS_ID IN ( " + p_id_HCFA + " " + p_id_UB + " " + p_id_DENTAL + ") AND BATCHNO IN ( SELECT batchno FROM HCFA_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_HCFA.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' union SELECT batchno FROM UB_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_UB.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' union SELECT batchno FROM DEN_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_DENTAL.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' ) ORDER BY new_imagename ASC ";
string q2 = "SELECT OLD_IMAGENAME,NEW_IMAGENAME FROM CCM_IMAGE_RENAME WHERE PROCESS_ID IN ( 78 ) AND BATCHNO IN ( SELECT batchno FROM HCFA_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '''' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' union SELECT batchno FROM UB_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''78'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' union SELECT batchno FROM DEN_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '''' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' ) ORDER BY new_imagename ASC ";
DataTable dtb = new DataTable();
dtb = db.GetTable(q2);
if (dtb.Rows.Count > 0)
{
string DuplicateFolder = "";
DuplicateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images_Report");

if (!Directory.Exists(DuplicateFolder))
{
Directory.CreateDirectory(DuplicateFolder);
}
R_folder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);


if (File.Exists(DuplicateFolder + "\\" + PType + "_" +"120118" + "_DCN_Report.txt"))
{
File.Delete(DuplicateFolder + "\\"+PType+"_" +"120118" + "_DCN_Report.txt");
}
FileInfo t = new FileInfo(DuplicateFolder + "\\"+PType+"_" +"120118" + "_DCN_Report.txt");
StreamWriter Tex = t.AppendText();
Tex.WriteLine("TCN Original_Name");
foreach (DataRow drPrintRow in dtb.Rows)
{
String str = drPrintRow["NEW_IMAGENAME"].ToString().Replace(".TIF", "").Replace(".tif", "") + " " + drPrintRow["OLD_IMAGENAME"].ToString().Replace(".TIF", "").Replace(".tif", "");
Tex.WriteLine(str);
}

Tex.Close();
MessageBox.Show("Report is generated.\nFile name is - " + ""+PType+"_" +"120118" + "_DCN_Report.txt", "Image Renamer", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.DoEvents();

txt_FolderPath.Text = "";

Process.Start(DuplicateFolder);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;



}
else
{
MessageBox.Show("There is no batches to generate report for today''s date. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

}
}

private void btn_Cancal_Click(object sender, EventArgs e)
{
this.Close();
}

private void btn_report_Click(object sender, EventArgs e)
{
if (comboBox2.Text != "---Select---" && comboBox1.SelectedItem != null)
{

if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "185";
string p_Type_UB = "";
string p_Type_DENTAL = "";
string ptype = "CCM_HCFA";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "";
string p_Type_UB = "78";
string p_Type_DENTAL = "";

string ptype = "CCM_UB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "---Select---" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "185";
string p_Type_UB = "78";
string p_Type_DENTAL = "";

string ptype = "CCM";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "191";
string p_Type_UB = "";
string p_Type_DENTAL = "";
string ptype = "SSB_HCFA";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "";
string p_Type_UB = "192";
string p_Type_DENTAL = "";
string ptype = "SSB_UB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;

}
if (comboBox1.SelectedItem.ToString() == "Dental" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "";
string p_Type_UB = "";
string p_Type_DENTAL = "193";
string ptype = "SSB_DENTAL";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;

}

if (comboBox1.SelectedItem.ToString() == "---Select---" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "191";
string p_Type_UB = "192";
string p_Type_DENTAL = "193";
string ptype = "SSB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);

return;
}




}
else
{
MessageBox.Show("Please Select Correct Process Type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;

}
btn_submit.Enabled = false;
btn_Cancal.Enabled = false;
btn_report.Enabled = false;





}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedItem.ToString()=="CCM")
{
comboBox1.Items.Remove("HCFA Reprice");
comboBox1.Items.Remove("HCFA EOB");
comboBox1.Items.Remove("UB Reprice");
comboBox1.Items.Remove("UB EOB");
comboBox1.Items.Remove("Dental");
comboBox1.Refresh();


}
if (comboBox2.SelectedItem.ToString() == "SSB")
{
if (comboBox1.Items.Count == 3)
{
comboBox1.Items.Add("HCFA Reprice");
comboBox1.Items.Add("HCFA EOB");
comboBox1.Items.Add("UB Reprice");
comboBox1.Items.Add("UB EOB");
comboBox1.Items.Add("Dental");

}


}


}

private void button1_Click_1(object sender, EventArgs e)
{
FolderBrowserDialog f = new System.Windows.Forms.FolderBrowserDialog();
if (f.ShowDialog() == DialogResult.OK)
{
txt_FolderPath.Text = f.SelectedPath;
}
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Enabled = false;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Enabled = true;

}


}
}





--------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Numeric;
using System.Linq;
using System.Web;
using System.Web;
using System.IO;




using System.Windows.Forms;

namespace demofortiff
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}




private void button1_Click(object sender, EventArgs e)
{
//using (Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\FHM1201101250028.tif"))
//{
// using (Bitmap newBitmap = new Bitmap(bitmap))
// {
// newBitmap.SetResolution(300, 300);
// newBitmap.Save("C:\\images\\file300", System.Drawing.Imaging.ImageFormat.Tiff);
// }
//}

int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
System.Drawing.Imaging. PropertyItem piXRes = bmp.GetPropertyItem(400);
System.Drawing.Imaging.PropertyItem piYRes = bmp.GetPropertyItem(400);

// values are stored as a rational number - numerator/denominator pair
numerator = BitConverter.ToInt32(piXRes.Value, 0);
denominator = BitConverter.ToInt32(piXRes.Value, 4);
float xRes = numerator / denominator;

numerator = BitConverter.ToInt32(piYRes.Value, 0);
denominator = BitConverter.ToInt32(piYRes.Value, 4);
float yRes = numerator / denominator;

// now set the values
byte[] numeratorBytes = new byte[4];
byte[] denominatorBytes = new byte[4];

numeratorBytes = BitConverter.GetBytes(600); // specify resolution in numerator
denominatorBytes = BitConverter.GetBytes(1);

Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4); // set the XResolution value
Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);

bmp.SetPropertyItem(piXRes); // finally set the image property resolution
bmp.SetPropertyItem(piYRes);

// double ratio = maxWidth / finalWidth;
// int maxHeight = (int)img1.Height * ratio;
bmp.GetThumbnailImage(7000, 7000, null, IntPtr.Zero);



FixedSize(bmp, 200, 200);

bmp.SetResolution(600, 600); // now set the bitmap resolution

bmp.Save("C:\\images\\output.tif"); // save the image
}


}
public static Bitmap Resize(Bitmap b, int nWidth, int nHeight)
{
Bitmap bTemp = (Bitmap)b.Clone();
b = new Bitmap(nWidth, nHeight, bTemp.PixelFormat);

double nXFactor = (double)bTemp.Width / (double)nWidth;
double nYFactor = (double)bTemp.Height / (double)nHeight;

for (int x = 0; x < b.Width; ++x)
for (int y = 0; y < b.Height; ++y)
b.SetPixel(x, y, bTemp.GetPixel((int)(Math.Floor(x * nXFactor)),
(int)(Math.Floor(y * nYFactor))));

return b;
}

private void button2_Click(object sender, EventArgs e)
{
//using (Image img = Image.FromStream(memoryStream))
//{
// Guid id = img.FrameDimensionsList[0];
// System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(id);
// int totalFrame = img.GetFrameCount(dimension);
// for (int i = 0; i < totalFrame; i++)
// {
// img.SelectActiveFrame(dimension, i);

// Faxed documents will have an non-square pixel aspect ratio.
// If this is the case,adjust the height so that the
// resulting pixels are square.
// int width = img.Width;
// int height = img.Height;
// if (img.VerticalResolution < img.HorizontalResolution)
// {
// height = (int)(height * img.HorizontalResolution / img.VerticalResolution);
// }

// bitmaps.Add(new Bitmap(img, new Size(width, height)));
// }
//}

//ImageCodecInfo ici = null;
//ImageCodecInfo[] Encoders = ImageCodecInfo.GetImageEncoders();
//foreach (ImageCodecInfo ListICI in Encoders)
//{
// if (ListICI.MimeType == "image/tiff")
// {
// ici = ListICI;
// break;
// }
//}

//// Can''t find the TIFF encoder
//if (ici == null) return;

//// Set encoder to use no compression
//EncoderParameters ep = new EncoderParameters();
//ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone);

//// Load a new image
//Bitmap TempImg = new Bitmap("C:\\images\\CCM_HB_20111228_0031901.tif");

//try
//{ // Attempt to save the image
// TempImg.Save("C:\\images\\CCM_HB_20111228_.tif", ici, ep);
//}
//catch (Exception ex)
//{
// MessageBox.Show("Error saving image: " + ex.Message);
//}

//TempImg.Dispose(); // Clean up
//ep.Dispose();

//Image tif = Image.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif");
//float width = tif.PhysicalDimension.Width;
//float height = tif.PhysicalDimension.Height;


//float hresolution = tif.HorizontalResolution;
//float vresolution = tif.VerticalResolution;






//tif.Dispose();


//MessageBox.Show(width.ToString());



int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);

// values are stored as a rational number - numerator/denominator pair
//numerator = BitConverter.ToInt32(piXRes.Value, 0);
//denominator = BitConverter.ToInt32(piXRes.Value, 4);
//float xRes = numerator / denominator;

//numerator = BitConverter.ToInt32(piYRes.Value, 0);
//denominator = BitConverter.ToInt32(piYRes.Value, 4);
//float yRes = numerator / denominator;

//// now set the values
//byte[] numeratorBytes = new byte[4];
//byte[] denominatorBytes = new byte[4];

//numeratorBytes = BitConverter.GetBytes(600); // specify resolution in numerator
//denominatorBytes = BitConverter.GetBytes(1);

//Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4); // set the XResolution value
//Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

//Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
//Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);
// float height = bmp.PhysicalDimension.Height;

//bmp.SetPropertyItem(height); // finally set the image property resolution
// bmp.SetPropertyItem(piYRes);







FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300); // now set the bitmap resolution

bmp.Save("C:\\images\\boutput12222.tif"); // save the image
}






}

static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300 ,300);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
//grPhoto.Dispose();
// return bmPhoto;




// bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

// Graphics grPhoto = Graphics.FromImage(bmPhoto);
// grPhoto.Clear(Color.Black);
//// grPhoto.InterpolationMode =System.Drawing.Image.InterpolationMode.HighQualityBicubic;

// grPhoto.DrawImage(imgPhoto, new Rectangle(sourceX, sourceY, sourceX, sourceY), new Rectangle(destX, destY, destWidth, destHeight), GraphicsUnit.Pixel);

//bmPhoto.SetResolution(300, 300);
//ImageFormat.Tiff
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

// Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);



// bmPhoto.Save("C:\\images\\output1211.tif", encoderInfo, encoderParams);
//grPhoto.Dispose();
return bmPhoto;
}

private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}


private void button3_Click(object sender, EventArgs e)
{

Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif");
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
string jay = "C:\\images\\boutput12350.tif";


Image tiff = Image.FromStream(byteStream);
ImageCodecInfo encoderInfo = GetEncoderInfo ("image/tiff");

EncoderParameters encoderParams = new EncoderParameters(2);
EncoderParameter parameter = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = parameter;
parameter = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
encoderParams.Param[1] = parameter;
tiff.Save(jay, encoderInfo, encoderParams);
EncoderParameters EncoderParams = new EncoderParameters(2);
EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
EncoderParameter CompressionEncodeParam = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
EncoderParams.Param[0] = CompressionEncodeParam;
EncoderParams.Param[1] = SaveEncodeParam;
tiff.SaveAdd(EncoderParams);
// EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush);
//EncoderParams = new EncoderParameters(1);
//EncoderParams.Param[0] = SaveEncodeParam;
//tiff.SaveAdd(EncoderParams);







}



}
}

推荐答案

");
public CCMDCNRenamingForm()
{
InitializeComponent();
}



private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog f = new System.Windows.Forms.FolderBrowserDialog();
if (f.ShowDialog() == DialogResult.OK)
{
txt_FolderPath.Text = f.SelectedPath;
}
}

string GETSR(int count)
{
string sr = "";



if (count <= 100)
{
sr = "1000" + count.ToString();
if (sr.Length==6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length==7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}

else if (count > 100 && count <= 200)
{
sr = "2000" + (count - 100).ToString();

if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 200 && count <= 300)
{
sr = "3000" + (count - 200).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 300 && count <= 400)
{
sr = "4000" + (count - 300).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 400 && count <= 500)
{
sr = "5000" + (count - 400).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 500 && count <= 600)
{
sr = "6000" + (count - 500).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}

else if (count > 600 && count <= 700)
{
sr = "7000" + (count - 600).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}


}

else if (count > 700 && count <= 800)
{
sr = "8000" + (count - 700).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 800 && count <= 900)
{
sr = "9000" + (count - 800).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 900 && count <= 1000)
{
sr = "10000" + (count - 900).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1000 && count <= 1100)
{
sr = "11000" + (count - 1000).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0,2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1100 && count <= 1200)
{
sr = "12000" + (count - 1100).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1200 && count <= 1300)
{
sr = "13000" + (count - 1200).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1300 && count <= 1400)
{
sr = "14000" + (count - 1300).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 1400 && count <= 1500)
{
sr = "15000" + (count - 1400).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}

return sr;
}

bool checkvaliddate(string date1)
{
string year = date1.Substring(0, 4);
string month = date1.Substring(4, 2);
string day = date1.Substring(6, 2);
date1 = month +day+ year;
bool flag = false;
if (regex.IsMatch(date1))
标志= true;
其他
标志=假;

return flag;
}



void copyDirectory(string Src, string Dst)
{
string source = Src;
String[] Files;
if(Dst[Dst.Length-1]!=Path.DirectorySeparatorChar)
Dst+=Path.DirectorySeparatorChar;
if(!Directory.Exists(Dst))
Directory.CreateDirectory(Dst);
Files=Directory.GetFileSystemEntries(Src);
foreach(string Element in Files)
{
//Sub directories
if(Directory.Exists(Element))
copyDirectory(Element,Dst+Path.GetFileName(Element));
//Files in directory
else
File.Copy(Element, Path.Combine(Dst ,Path.GetFileName(Element)),true);
}

}

public void reset()
{
batchNo_1 = "";//,batchNo_1,batchNo_1,batchNo_1,batchNo_1 = "";
batchNo_2 = "";
batchNo_3 = "";
batchNo_4 = "";
batchNo_5 = "";
batchNo_6 = "";
batchNo_7 = "";
batchNo_8 = "";
batchNo_9 = "";
batchNo_10 = "";
batchNo_11 = "";
batchNo_12 = "";
batchNo_13 = "";
batchNo_14 = "";
batchNo_15 = "";
batchNo_16 = "";
batchNo_17 = "";
batchNo_18 = "";
batchNo_19 = "";
batchNo_20 = "";
cnt1 = 0;
cnt2 = 0;
cnt3 = 0;
cnt4 = 0;
cnt5 = 0;
cnt6 = 0;
cnt7 = 0;
cnt8 = 0;
cnt9 = 0;
cnt10 = 0;
cnt11 = 0;
cnt12 = 0;
cnt13 = 0;
cnt14 = 0;
cnt15 = 0;
cnt16 = 0;
cnt17 = 0;
cnt18 = 0;
cnt19 = 0;
cnt20 = 0;

cnt1_ = "";
cnt2_ = "";
cnt3_ = "";
cnt4_ = "";
cnt5_ = "";
cnt6_ = "";
cnt7_ = "";
cnt8_ = "";
cnt9_ = "";
cnt10_ = "";
cnt11_ = "";
cnt12_ = "";
cnt13_ = "";
cnt14_ = "";
cnt15_ = "";
cnt16_ = "";
cnt17_ = "";
cnt18_ = "";
cnt19_ = "";
cnt20_ = "";
}

private void btn_submit_Click(object sender, EventArgs e)
{


btn_submit.Enabled = false;
btn_Cancal.Enabled = false;
btn_report.Enabled = false;
reset();
试试
{
if (rdbadvanced.Checked == true)
{
if (cmbdpi.SelectedItem.ToString() == "---Select---" || cmbheight.SelectedItem.ToString() == "---Select---" || cmbwidth.SelectedItem.ToString() == "---Select---")
{
MessageBox.Show("Please select the advanced features correctly.", "Error ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
返回;

}

}


if (comboBox1.Text != "--Select Process--")
{
if (txt_FolderPath.Text == "")
{
MessageBox.Show("Please Select the Folder", "Error ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;
返回;
}

if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type = "CCM1H";
string p_ID = "185";
RenameFunction(p_Type, p_ID);
返回;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type = "CCM1U";
string p_ID = "78";
RenameFunction(p_Type, p_ID);
返回;
}
if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBNH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
返回;
}
if (comboBox1.SelectedItem.ToString() == "HCFA Reprice" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBRH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
返回;

}
if (comboBox1.SelectedItem.ToString() == "HCFA EOB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBOH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
返回;

}

if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBNU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
返回;
}
if (comboBox1.SelectedItem.ToString() == "UB Reprice" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBRU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
返回;
}
if (comboBox1.SelectedItem.ToString() == "UB EOB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBOU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
返回;

}
if (comboBox1.SelectedItem.ToString() == "Dental" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBND";
string p_ID = "193";
RenameFunction(p_Type, p_ID);
返回;
}


}
其他
{
MessageBox.Show("Please Select Process", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
返回;
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

}

}
catch(ex ex例外)
{
MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_FolderPath.Text = "";
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;
progressBar1.Visible = false;

}



}

public void RenameFunction(string ptype, string p_ID)
{
Cursor.Current = Cursors.WaitCursor;
Application.DoEvents();
string[] GetBatchNames = Directory.GetDirectories(txt_FolderPath.Text);
string path = "";

if (Directory.Exists(txt_FolderPath.Text))
{
string Orignal = "";
Orignal = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Orignal_Images");

copyDirectory(txt_FolderPath.Text, Orignal);
DirectoryInfo BatchName = new DirectoryInfo(txt_FolderPath.Text);

FileInfo[] Imagenames = BatchName.GetFiles("*.tif", SearchOption.AllDirectories);
if (Imagenames.Length > 0)
{

string DuplicateFolder = "";
DuplicateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images");

if (!Directory.Exists(DuplicateFolder))
{
Directory.CreateDirectory(DuplicateFolder);
}



create_batch_HCFA(ptype,p_ID);

string source = txt_FolderPath.Text;
copyDirectory(Orignal, source);
Directory.Delete(Orignal, true);
MessageBox.Show("Operation is Completed.\nTotal - " + Imagenames.Length + " Image(s) Processed.\nCreated Batche(s) are - \n" + batchNo_1 + "" + cnt1_ + " \n" + batchNo_2 + "" + cnt2_ + " \n" + batchNo_3 + "" + cnt3_ + " \n" + batchNo_4 + "" + cnt4_ + " \n" + batchNo_5 + "" + cnt5_ + " \n" + batchNo_6 + "" + cnt6_ + " \n" + batchNo_7 + "" + cnt7_ + " \n" + batchNo_8 + "" + cnt8_ + " \n" + batchNo_9 + "" + cnt9_ + "\n" + batchNo_10 + "" + cnt10_ + "\n" + batchNo_11 + "" + cnt11_ + "\n" + batchNo_12 + "" + cnt12_ + "\n" + batchNo_13 + "" + cnt13_ + "\n" + batchNo_14 + "" + cnt14_ + "\n" + batchNo_15 + "" + cnt15_ + "", "Image Renamer", MessageBoxButtons.OK, MessageBoxIcon.Information);
//comboBox1.SelectedText = ("--Select Process--");
Application.DoEvents();

txt_FolderPath.Text = "";

Process.Start(DuplicateFolder);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

progressBar1.Visible = false;
返回;
}
其他
{
MessageBox.Show("There is no .tif Image in selected folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_FolderPath.Text = "";
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

progressBar1.Visible = false;
}
}

}

private void Form1_Load(object sender, EventArgs e)
{
groupBox1.Enabled = false;

comboBox1.SelectedText = ("---Select---");
comboBox2.SelectedText = ("---Select---");
cmbheight.SelectedText = ("---Select---");
cmbdpi.SelectedText = ("---Select---");
cmbwidth.SelectedText = ("---Select---");


progressBar1.Value = 0;
progressBar1.Visible = false;


}



static Image FixedSize(Image imgPhoto, int Width, int Height,string file_name,int dpi)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;

nPercentW = ((float)Width/(float)sourceWidth);
nPercentH = ((float)Height/(float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent))/2);
}
其他
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent))/2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(dpi, dpi);
图形grPhoto = Graphics.FromImage(bmPhoto);
// grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
bmPhoto.Save(file_name);
grPhoto.Dispose();
return bmPhoto;
}


public void create_batch_HCFA(string processType, string pId)
{
DirectoryInfo BatchName = new DirectoryInfo(txt_FolderPath.Text);



FileInfo[] Imagenames = BatchName.GetFiles("*.tif", SearchOption.AllDirectories);
StringBuilder osb = new StringBuilder();
osb.AppendLine("DECLARE");
osb.AppendLine("vIMGID NUMBER;");
osb.Append("Begin ");
if (Imagenames.Length < 1500)
{



progressBar1.Value = 10;
progressBar1.Minimum = 0;
progressBar1.Maximum = Imagenames.Length;
for (int i = 0; i < Imagenames.Length; i++)
{

progressBar1.Value = i;

if (i < 100)
{

string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "001");
batchNo_1 = processType +"120118" + "001";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked==true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString())+1);
}

}
其他
{
File.Move(source, Batch_Folder);

}



progressBar1.Visible = true;
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME,SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_1+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt1++;
cnt1_ = " - " + cnt1.ToString() + " Images.";


}
if (i >= 100 && i < 200)
{
// progressBar1.Value = 60;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "002");
batchNo_2 = processType +"120118" + "002";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;
if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
//File.Move(source, Batch_Folder);
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_2+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt2++;
cnt2_ = " - " + cnt2.ToString() + " Images.";
}
if (i >= 200 && i < 300)
{
// progressBar1.Value = 90;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "003");
batchNo_3 = processType +"120118" + "003";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}

osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_3+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt3++;
cnt3_ = " - " + cnt3.ToString() + " Images.";
}
if (i >= 300 && i < 400)
{
//progressBar1.Value = 100;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; //+
batchNo_4 = processType +"120118" + "004";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "004");

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_4+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt4++;
cnt4_ = " - " + cnt4.ToString() + " Images.";
}
if (i >= 400 && i < 500)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "005");
batchNo_5 = processType +"120118" + "005";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_5+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt5++;
cnt5_ = " - " + cnt5.ToString() + " Images.";
}
if (i >= 500 && i < 600)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; //+
batchNo_6 = processType +"120118" + "006";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "006");

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_6+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");

cnt6++;
cnt6_ = " - " + cnt6.ToString() + " Images.";
}
if (i >= 600 && i < 700)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "007");
batchNo_7 = processType +"120118" + "007";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_7+"'' ,''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt7++;
cnt7_ = " - " + cnt7.ToString() + " Images.";
}
if (i >= 700 && i < 800)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; //+
batchNo_8 = processType +"120118" + "008";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_8);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_8 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt8++;
cnt8_ = " - " + cnt8.ToString() + " Images.";

}
if (i >= 800 && i < 900)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; //+
batchNo_9 = processType +"120118" + "009";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_9);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_9 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt9++;
cnt9_ = " - " + cnt9.ToString() + " Images.";

}
if (i >= 900 && i < 1000)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_10 = processType +"120118" + "010";
string OutPutfileName = batchNo_10 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_10);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_10 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt10++;
cnt10_ = " - " + cnt10.ToString() + " Images.";

}


if (i >= 1000 && i < 1100)
{
// progressBar1.Value = 60;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_11 = processType +"120118" + "011";
string OutPutfileName = batchNo_11 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_11);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_11 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt11++;
cnt11_ = " - " + cnt11.ToString() + " Images.";
}
if (i >= 1100 && i < 1200)
{
// progressBar1.Value = 90;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_12 = processType +"120118" + "012";
string OutPutfileName = batchNo_12 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_12);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}

osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_12 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt12++;
cnt12_ = " - " + cnt12.ToString() + " Images.";
}
if (i >= 1200 && i < 1300)
{
//progressBar1.Value = 100;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_13 = processType +"120118" + "013";
string OutPutfileName = batchNo_13 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_13);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_13 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt13++;
cnt13_ = " - " + cnt13.ToString() + " Images.";
}
if (i >= 1300 && i < 1400)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_14 = processType +"120118" + "014";
string OutPutfileName = batchNo_14 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_14);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_14 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt14++;
cnt14_ = " - " + cnt14.ToString() + " Images.";
}
if (i >= 1400 && i < 1500)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_15 = processType +"120118" + "015";
string OutPutfileName = batchNo_15 + sr + ".tif"; //+

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_15);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
其他
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_15 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");

cnt15++;
cnt15_ = " - " + cnt15.ToString() + " Images.";
}



}
osb.Append("End;");
db.InsertDeleteUpdate(osb.ToString());



}
其他
{
MessageBox.Show("Image Should be less than 1500", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}

public void GenerateReport(string p_id_HCFA, string p_id_UB, string p_id_DENTAL, string PType)
{
string R_folder = "";

//if (p_id_HCFA != "" && p_id_UB == "" && p_id_DENTAL == "")
//{
// //p_id_UB = "," + p_id_UB + " ";

//}

//if (p_id_HCFA == "" && p_id_UB != "" && p_id_DENTAL == "")
//{
// //p_id_UB = "," + p_id_UB + " ";

//}
//if (p_id_HCFA == "" && p_id_UB == "" && p_id_DENTAL != "")
//{
// //p_id_DENTAL = "," + p_id_DENTAL + " ";

//}
if (p_id_HCFA != "" && p_id_UB != "" && p_id_DENTAL != "")
{
p_id_UB = "," + p_id_UB + " ";
p_id_DENTAL = "," + p_id_DENTAL + " ";
}
if (p_id_HCFA != "" && p_id_UB != "" && p_id_DENTAL == "")
{
p_id_UB = "," + p_id_UB + " ";

}







string query = "SELECT OLD_IMAGENAME,NEW_IMAGENAME FROM CCM_IMAGE_RENAME WHERE PROCESS_ID IN ( " + p_id_HCFA + " " + p_id_UB + " " + p_id_DENTAL + ") AND BATCHNO IN ( SELECT batchno FROM HCFA_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_HCFA.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' union SELECT batchno FROM UB_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_UB.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' union SELECT batchno FROM DEN_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_DENTAL.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' ) ORDER BY new_imagename ASC ";
string q2 = "SELECT OLD_IMAGENAME,NEW_IMAGENAME FROM CCM_IMAGE_RENAME WHERE PROCESS_ID IN ( 78 ) AND BATCHNO IN ( SELECT batchno FROM HCFA_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '''' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' union SELECT batchno FROM UB_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''78'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' union SELECT batchno FROM DEN_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '''' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' ) ORDER BY new_imagename ASC ";
DataTable dtb = new DataTable();
dtb = db.GetTable(q2);
if (dtb.Rows.Count > 0)
{
string DuplicateFolder = "";
DuplicateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images_Report");

if (!Directory.Exists(DuplicateFolder))
{
Directory.CreateDirectory(DuplicateFolder);
}
R_folder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);


if (File.Exists(DuplicateFolder + "\\" + PType + "_" +"120118" + "_DCN_Report.txt"))
{
File.Delete(DuplicateFolder + "\\"+PType+"_" +"120118" + "_DCN_Report.txt");
}
FileInfo t = new FileInfo(DuplicateFolder + "\\"+PType+"_" +"120118" + "_DCN_Report.txt");
StreamWriter Tex = t.AppendText();
Tex.WriteLine("TCN Original_Name");
foreach (DataRow drPrintRow in dtb.Rows)
{
String str = drPrintRow["NEW_IMAGENAME"].ToString().Replace(".TIF", "").Replace(".tif", "") + " " + drPrintRow["OLD_IMAGENAME"].ToString().Replace(".TIF", "").Replace(".tif", "");
Tex.WriteLine(str);
}

Tex.Close();
MessageBox.Show("Report is generated.\nFile name is - " + ""+PType+"_" +"120118" + "_DCN_Report.txt", "Image Renamer", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.DoEvents();

txt_FolderPath.Text = "";

Process.Start(DuplicateFolder);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;



}
其他
{
MessageBox.Show("There is no batches to generate report for today''s date. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

}
}

private void btn_Cancal_Click(object sender, EventArgs e)
{
this.Close();
}

private void btn_report_Click(object sender, EventArgs e)
{
if (comboBox2.Text != "---Select---" && comboBox1.SelectedItem != null)
{

if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "185";
string p_Type_UB = "";
string p_Type_DENTAL = "";
string ptype = "CCM_HCFA";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "";
string p_Type_UB = "78";
string p_Type_DENTAL = "";

string ptype = "CCM_UB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;
}
if (comboBox1.SelectedItem.ToString() == "---Select---" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "185";
string p_Type_UB = "78";
string p_Type_DENTAL = "";

string ptype = "CCM";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;
}
if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "191";
string p_Type_UB = "";
string p_Type_DENTAL = "";
string ptype = "SSB_HCFA";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "";
string p_Type_UB = "192";
string p_Type_DENTAL = "";
string ptype = "SSB_UB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;

}
if (comboBox1.SelectedItem.ToString() == "Dental" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "";
string p_Type_UB = "";
string p_Type_DENTAL = "193";
string ptype = "SSB_DENTAL";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
返回;

}

if (comboBox1.SelectedItem.ToString() == "---Select---" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "191";
string p_Type_UB = "192";
string p_Type_DENTAL = "193";
string ptype = "SSB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);

返回;
}




}
其他
{
MessageBox.Show("Please Select Correct Process Type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
返回;

}
btn_submit.Enabled = false;
btn_Cancal.Enabled = false;
btn_report.Enabled = false;





}

私有void comboBox1_SelectedIndexChanged(对象发送者,EventArgs e)
{

}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedItem.ToString()=="CCM")
{
comboBox1.Items.Remove("HCFA Reprice");
comboBox1.Items.Remove("HCFA EOB");
comboBox1.Items.Remove("UB Reprice");
comboBox1.Items.Remove("UB EOB");
comboBox1.Items.Remove("Dental");
comboBox1.Refresh();


}
if (comboBox2.SelectedItem.ToString() == "SSB")
{
if (comboBox1.Items.Count == 3)
{
comboBox1.Items.Add("HCFA Reprice");
comboBox1.Items.Add("HCFA EOB");
comboBox1.Items.Add("UB Reprice");
comboBox1.Items.Add("UB EOB");
comboBox1.Items.Add("Dental");

}


}


}

private void button1_Click_1(object sender, EventArgs e)
{
FolderBrowserDialog f = new System.Windows.Forms.FolderBrowserDialog();
if (f.ShowDialog() == DialogResult.OK)
{
txt_FolderPath.Text = f.SelectedPath;
}
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Enabled = false;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Enabled = true;

}


}
}





-------------------------------------------------- ------------------------------

使用系统;
使用System.Collections.Generic;
using System.ComponentModel;
使用System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Numeric;
using System.Linq;
使用System.Web;
使用System.Web;
using System.IO;




using System.Windows.Forms;

namespace demofortiff
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}




private void button1_Click(object sender, EventArgs e)
{
//using (Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\FHM1201101250028.tif"))
//{
// using (Bitmap newBitmap = new Bitmap(bitmap))
//{
// newBitmap.SetResolution(300, 300);
// newBitmap.Save("C:\\images\\file300", System.Drawing.Imaging.ImageFormat.Tiff);
//}
//}

int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif"))
{
//obtain the XResolution and YResolution TIFFTAG values
System.Drawing.Imaging. PropertyItem piXRes = bmp.GetPropertyItem(400);
System.Drawing.Imaging.PropertyItem piYRes = bmp.GetPropertyItem(400);

//values are stored as a rational number - numerator/denominator pair
numerator = BitConverter.ToInt32(piXRes.Value, 0);
denominator = BitConverter.ToInt32(piXRes.Value, 4);
float xRes = numerator/denominator;

numerator = BitConverter.ToInt32(piYRes.Value, 0);
denominator = BitConverter.ToInt32(piYRes.Value, 4);
float yRes = numerator/denominator;

//now set the values
byte[] numeratorBytes = new byte[4];
byte[] denominatorBytes = new byte[4];

numeratorBytes = BitConverter.GetBytes(600);//specify resolution in numerator
denominatorBytes = BitConverter.GetBytes(1);

Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4);//set the XResolution value
Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4);//set the YResolution value
Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);

bmp.SetPropertyItem(piXRes);//finally set the image property resolution
bmp.SetPropertyItem(piYRes);

// double ratio = maxWidth/finalWidth;
// int maxHeight = (int)img1.Height * ratio;
bmp.GetThumbnailImage(7000, 7000, null, IntPtr.Zero);



FixedSize(bmp, 200, 200);

bmp.SetResolution(600, 600);//now set the bitmap resolution

bmp.Save("C:\\images\\output.tif");//save the image
}


}
public static Bitmap Resize(Bitmap b, int nWidth, int nHeight)
{
Bitmap bTemp = (Bitmap)b.Clone();
b = new Bitmap(nWidth, nHeight, bTemp.PixelFormat);

double nXFactor = (double)bTemp.Width/(double)nWidth;
double nYFactor = (double)bTemp.Height/(double)nHeight;

for (int x = 0; x < b.Width; ++x)
for (int y = 0; y < b.Height; ++y)
b.SetPixel(x, y, bTemp.GetPixel((int)(Math.Floor(x * nXFactor)),
(int)(Math.Floor(y * nYFactor))));

return b;
}

private void button2_Click(object sender, EventArgs e)
{
//using (Image img = Image.FromStream(memoryStream))
//{
// Guid id = img.FrameDimensionsList[0];
// System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(id);
// int totalFrame = img.GetFrameCount(dimension);
// for (int i = 0; i < totalFrame; i++)
//{
// img.SelectActiveFrame(dimension, i);

// Faxed documents will have an non-square pixel aspect ratio.
// If this is the case,adjust the height so that the
// resulting pixels are square.
// int width = img.Width;
// int height = img.Height;
// if (img.VerticalResolution < img.HorizontalResolution)
//{
// height = (int)(height * img.HorizontalResolution/img.VerticalResolution);
// }

// bitmaps.Add(new Bitmap(img, new Size(width, height)));
//}
//}

//ImageCodecInfo ici = null;
//ImageCodecInfo[] Encoders = ImageCodecInfo.GetImageEncoders();
//foreach (ImageCodecInfo ListICI in Encoders)
//{
// if (ListICI.MimeType == "image/tiff")
//{
// ici = ListICI;
//中断;
//}
//}

////Can''t find the TIFF encoder
//if (ici == null) return;

////Set encoder to use no compression
//EncoderParameters ep = new EncoderParameters();
//ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone);

////Load a new image
//Bitmap TempImg = new Bitmap("C:\\images\\CCM_HB_20111228_0031901.tif");

//尝试
//{//Attempt to save the image
// TempImg.Save("C:\\images\\CCM_HB_20111228_.tif", ici, ep);
//}
//catch(异常前)
//{
// MessageBox.Show("Error saving image: " + ex.Message);
//}

//TempImg.Dispose();//Clean up
//ep.Dispose();

//Image tif = Image.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif");
//float width = tif.PhysicalDimension.Width;
//float height = tif.PhysicalDimension.Height;


//float hresolution = tif.HorizontalResolution;
//float vresolution = tif.VerticalResolution;






//tif.Dispose();


//MessageBox.Show(width.ToString());



int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif"))
{
//obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);

//values are stored as a rational number - numerator/denominator pair
//numerator = BitConverter.ToInt32(piXRes.Value, 0);
//denominator = BitConverter.ToInt32(piXRes.Value, 4);
//float xRes = numerator/denominator;

//numerator = BitConverter.ToInt32(piYRes.Value, 0);
//denominator = BitConverter.ToInt32(piYRes.Value, 4);
//float yRes = numerator/denominator;

////now set the values
//byte[] numeratorBytes = new byte[4];
//byte[] denominatorBytes = new byte[4];

//numeratorBytes = BitConverter.GetBytes(600);//specify resolution in numerator
//denominatorBytes = BitConverter.GetBytes(1);

//Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4);//set the XResolution value
//Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

//Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4);//set the YResolution value
//Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);
// float height = bmp.PhysicalDimension.Height;

//bmp.SetPropertyItem(height);//finally set the image property resolution
//bmp.SetPropertyItem(piYRes);







FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300);//now set the bitmap resolution

bmp.Save("C:\\images\\boutput12222.tif");//save the image
}






}

static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width/(float)sourceWidth);
nPercentH = ((float)Height/(float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent))/2);
}
其他
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent))/2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300 ,300);
图形grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
//grPhoto.Dispose();
//return bmPhoto;




//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

// Graphics grPhoto = Graphics.FromImage(bmPhoto);
//grPhoto.Clear(Color.Black);
////grPhoto.InterpolationMode =System.Drawing.Image.InterpolationMode.HighQualityBicubic;

// grPhoto.DrawImage(imgPhoto, new Rectangle(sourceX, sourceY, sourceX, sourceY), new Rectangle(destX, destY, destWidth, destHeight), GraphicsUnit.Pixel);

//bmPhoto.SetResolution(300, 300);
//ImageFormat.Tiff
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

//Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);



//bmPhoto.Save("C:\\images\\output1211.tif", encoderInfo, encoderParams);
//grPhoto.Dispose();
return bmPhoto;
}

private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
返回null;
}


private void button3_Click(对象发送者,EventArgs e)
{

Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif");
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
string jay = "C:\\images\\boutput12350.tif";


Image tiff = Image.FromStream(byteStream);
ImageCodecInfo encoderInfo = GetEncoderInfo ("image/tiff");

EncoderParameters encoderParams = new EncoderParameters(2);
EncoderParameter parameter = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = parameter;
parameter = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
encoderParams.Param[1] = parameter;
tiff.Save(jay, encoderInfo, encoderParams);
EncoderParameters EncoderParams = new EncoderParameters(2);
EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
EncoderParameter CompressionEncodeParam = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
EncoderParams.Param[0] = CompressionEncodeParam;
EncoderParams.Param[1] = SaveEncodeParam;
tiff.SaveAdd(EncoderParams);
//EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush);
//EncoderParams = new EncoderParameters(1);
//EncoderParams.Param[0] = SaveEncodeParam;
//tiff.SaveAdd(EncoderParams);







}



}
}
");
public CCMDCNRenamingForm()
{
InitializeComponent();
}



private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog f = new System.Windows.Forms.FolderBrowserDialog();
if (f.ShowDialog() == DialogResult.OK)
{
txt_FolderPath.Text = f.SelectedPath;
}
}

string GETSR(int count)
{
string sr = "";



if (count <= 100)
{
sr = "1000" + count.ToString();
if (sr.Length==6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length==7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}

else if (count > 100 && count <= 200)
{
sr = "2000" + (count - 100).ToString();

if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 200 && count <= 300)
{
sr = "3000" + (count - 200).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 300 && count <= 400)
{
sr = "4000" + (count - 300).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 400 && count <= 500)
{
sr = "5000" + (count - 400).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 500 && count <= 600)
{
sr = "6000" + (count - 500).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}

else if (count > 600 && count <= 700)
{
sr = "7000" + (count - 600).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}


}

else if (count > 700 && count <= 800)
{
sr = "8000" + (count - 700).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 800 && count <= 900)
{
sr = "9000" + (count - 800).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 900 && count <= 1000)
{
sr = "10000" + (count - 900).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1000 && count <= 1100)
{
sr = "11000" + (count - 1000).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0,2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1100 && count <= 1200)
{
sr = "12000" + (count - 1100).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1200 && count <= 1300)
{
sr = "13000" + (count - 1200).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1300 && count <= 1400)
{
sr = "14000" + (count - 1300).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 1400 && count <= 1500)
{
sr = "15000" + (count - 1400).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}

return sr;
}

bool checkvaliddate(string date1)
{
string year = date1.Substring(0, 4);
string month = date1.Substring(4, 2);
string day = date1.Substring(6, 2);
date1 = month +day+ year;
bool flag = false;
if (regex.IsMatch(date1))
flag = true;
else
flag = false;

return flag;
}



void copyDirectory(string Src, string Dst)
{
string source = Src;
String[] Files;
if(Dst[Dst.Length-1]!=Path.DirectorySeparatorChar)
Dst+=Path.DirectorySeparatorChar;
if(!Directory.Exists(Dst))
Directory.CreateDirectory(Dst);
Files=Directory.GetFileSystemEntries(Src);
foreach(string Element in Files)
{
// Sub directories
if(Directory.Exists(Element))
copyDirectory(Element,Dst+Path.GetFileName(Element));
// Files in directory
else
File.Copy(Element, Path.Combine(Dst ,Path.GetFileName(Element)),true);
}

}

public void reset()
{
batchNo_1 = "";//,batchNo_1,batchNo_1,batchNo_1,batchNo_1 = "";
batchNo_2 = "";
batchNo_3 = "";
batchNo_4 = "";
batchNo_5 = "";
batchNo_6 = "";
batchNo_7 = "";
batchNo_8 = "";
batchNo_9 = "";
batchNo_10 = "";
batchNo_11 = "";
batchNo_12 = "";
batchNo_13 = "";
batchNo_14 = "";
batchNo_15 = "";
batchNo_16 = "";
batchNo_17 = "";
batchNo_18 = "";
batchNo_19 = "";
batchNo_20 = "";
cnt1 = 0;
cnt2 = 0;
cnt3 = 0;
cnt4 = 0;
cnt5 = 0;
cnt6 = 0;
cnt7 = 0;
cnt8 = 0;
cnt9 = 0;
cnt10 = 0;
cnt11 = 0;
cnt12 = 0;
cnt13 = 0;
cnt14 = 0;
cnt15 = 0;
cnt16 = 0;
cnt17 = 0;
cnt18 = 0;
cnt19 = 0;
cnt20 = 0;

cnt1_ = "";
cnt2_ = "";
cnt3_ = "";
cnt4_ = "";
cnt5_ = "";
cnt6_ = "";
cnt7_ = "";
cnt8_ = "";
cnt9_ = "";
cnt10_ = "";
cnt11_ = "";
cnt12_ = "";
cnt13_ = "";
cnt14_ = "";
cnt15_ = "";
cnt16_ = "";
cnt17_ = "";
cnt18_ = "";
cnt19_ = "";
cnt20_ = "";
}

private void btn_submit_Click(object sender, EventArgs e)
{


btn_submit.Enabled = false;
btn_Cancal.Enabled = false;
btn_report.Enabled = false;
reset();
try
{
if (rdbadvanced.Checked == true)
{
if (cmbdpi.SelectedItem.ToString() == "---Select---" || cmbheight.SelectedItem.ToString() == "---Select---" || cmbwidth.SelectedItem.ToString() == "---Select---")
{
MessageBox.Show("Please select the advanced features correctly.", "Error ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;

}

}


if (comboBox1.Text != "--Select Process--")
{
if (txt_FolderPath.Text == "")
{
MessageBox.Show("Please Select the Folder", "Error ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;
return;
}

if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type = "CCM1H";
string p_ID = "185";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type = "CCM1U";
string p_ID = "78";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBNH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "HCFA Reprice" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBRH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
return;

}
if (comboBox1.SelectedItem.ToString() == "HCFA EOB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBOH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
return;

}

if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBNU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB Reprice" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBRU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB EOB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBOU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
return;

}
if (comboBox1.SelectedItem.ToString() == "Dental" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBND";
string p_ID = "193";
RenameFunction(p_Type, p_ID);
return;
}


}
else
{
MessageBox.Show("Please Select Process", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_FolderPath.Text = "";
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;
progressBar1.Visible = false;

}



}

public void RenameFunction(string ptype, string p_ID)
{
Cursor.Current = Cursors.WaitCursor;
Application.DoEvents();
string[] GetBatchNames = Directory.GetDirectories(txt_FolderPath.Text);
string path = "";

if (Directory.Exists(txt_FolderPath.Text))
{
string Orignal = "";
Orignal = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Orignal_Images");

copyDirectory(txt_FolderPath.Text, Orignal);
DirectoryInfo BatchName = new DirectoryInfo(txt_FolderPath.Text);

FileInfo[] Imagenames = BatchName.GetFiles("*.tif", SearchOption.AllDirectories);
if (Imagenames.Length > 0)
{

string DuplicateFolder = "";
DuplicateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images");

if (!Directory.Exists(DuplicateFolder))
{
Directory.CreateDirectory(DuplicateFolder);
}



create_batch_HCFA(ptype,p_ID);

string source = txt_FolderPath.Text;
copyDirectory(Orignal, source);
Directory.Delete(Orignal, true);
MessageBox.Show("Operation is Completed.\nTotal - " + Imagenames.Length + " Image(s) Processed.\nCreated Batche(s) are - \n" + batchNo_1 + "" + cnt1_ + " \n" + batchNo_2 + "" + cnt2_ + " \n" + batchNo_3 + "" + cnt3_ + " \n" + batchNo_4 + "" + cnt4_ + " \n" + batchNo_5 + "" + cnt5_ + " \n" + batchNo_6 + "" + cnt6_ + " \n" + batchNo_7 + "" + cnt7_ + " \n" + batchNo_8 + "" + cnt8_ + " \n" + batchNo_9 + "" + cnt9_ + "\n" + batchNo_10 + "" + cnt10_ + "\n" + batchNo_11 + "" + cnt11_ + "\n" + batchNo_12 + "" + cnt12_ + "\n" + batchNo_13 + "" + cnt13_ + "\n" + batchNo_14 + "" + cnt14_ + "\n" + batchNo_15 + "" + cnt15_ + "", "Image Renamer", MessageBoxButtons.OK, MessageBoxIcon.Information);
//comboBox1.SelectedText = ("--Select Process--");
Application.DoEvents();

txt_FolderPath.Text = "";

Process.Start(DuplicateFolder);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

progressBar1.Visible = false;
return;
}
else
{
MessageBox.Show("There is no .tif Image in selected folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_FolderPath.Text = "";
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

progressBar1.Visible = false;
}
}

}

private void Form1_Load(object sender, EventArgs e)
{
groupBox1.Enabled = false;

comboBox1.SelectedText = ("---Select---");
comboBox2.SelectedText = ("---Select---");
cmbheight.SelectedText = ("---Select---");
cmbdpi.SelectedText = ("---Select---");
cmbwidth.SelectedText = ("---Select---");


progressBar1.Value = 0;
progressBar1.Visible = false;


}



static Image FixedSize(Image imgPhoto, int Width, int Height,string file_name,int dpi)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;

nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(dpi, dpi);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
// grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
bmPhoto.Save(file_name);
grPhoto.Dispose();
return bmPhoto;
}


public void create_batch_HCFA(string processType, string pId)
{
DirectoryInfo BatchName = new DirectoryInfo(txt_FolderPath.Text);



FileInfo[] Imagenames = BatchName.GetFiles("*.tif", SearchOption.AllDirectories);
StringBuilder osb = new StringBuilder();
osb.AppendLine("DECLARE");
osb.AppendLine("vIMGID NUMBER;");
osb.Append("Begin ");
if (Imagenames.Length < 1500)
{



progressBar1.Value = 10;
progressBar1.Minimum = 0;
progressBar1.Maximum = Imagenames.Length;
for (int i = 0; i < Imagenames.Length; i++)
{

progressBar1.Value = i;

if (i < 100)
{

string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "001");
batchNo_1 = processType +"120118" + "001";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked==true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString())+1);
}

}
else
{
File.Move(source, Batch_Folder);

}



progressBar1.Visible = true;
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME,SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_1+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt1++;
cnt1_ = " - " + cnt1.ToString() + " Images.";


}
if (i >= 100 && i < 200)
{
// progressBar1.Value = 60;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "002");
batchNo_2 = processType +"120118" + "002";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;
if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
//File.Move(source, Batch_Folder);
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_2+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt2++;
cnt2_ = " - " + cnt2.ToString() + " Images.";
}
if (i >= 200 && i < 300)
{
// progressBar1.Value = 90;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "003");
batchNo_3 = processType +"120118" + "003";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}

osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_3+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt3++;
cnt3_ = " - " + cnt3.ToString() + " Images.";
}
if (i >= 300 && i < 400)
{
// progressBar1.Value = 100;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_4 = processType +"120118" + "004";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "004");

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_4+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt4++;
cnt4_ = " - " + cnt4.ToString() + " Images.";
}
if (i >= 400 && i < 500)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "005");
batchNo_5 = processType +"120118" + "005";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_5+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt5++;
cnt5_ = " - " + cnt5.ToString() + " Images.";
}
if (i >= 500 && i < 600)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_6 = processType +"120118" + "006";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "006");

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_6+"'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");

cnt6++;
cnt6_ = " - " + cnt6.ToString() + " Images.";
}
if (i >= 600 && i < 700)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "007");
batchNo_7 = processType +"120118" + "007";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''"+batchNo_7+"'' ,''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt7++;
cnt7_ = " - " + cnt7.ToString() + " Images.";
}
if (i >= 700 && i < 800)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_8 = processType +"120118" + "008";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_8);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_8 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt8++;
cnt8_ = " - " + cnt8.ToString() + " Images.";

}
if (i >= 800 && i < 900)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_9 = processType +"120118" + "009";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_9);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_9 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt9++;
cnt9_ = " - " + cnt9.ToString() + " Images.";

}
if (i >= 900 && i < 1000)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_10 = processType +"120118" + "010";
string OutPutfileName = batchNo_10 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_10);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_10 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt10++;
cnt10_ = " - " + cnt10.ToString() + " Images.";

}


if (i >= 1000 && i < 1100)
{
// progressBar1.Value = 60;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_11 = processType +"120118" + "011";
string OutPutfileName = batchNo_11 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_11);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_11 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt11++;
cnt11_ = " - " + cnt11.ToString() + " Images.";
}
if (i >= 1100 && i < 1200)
{
// progressBar1.Value = 90;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_12 = processType +"120118" + "012";
string OutPutfileName = batchNo_12 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_12);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}

osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_12 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt12++;
cnt12_ = " - " + cnt12.ToString() + " Images.";
}
if (i >= 1200 && i < 1300)
{
// progressBar1.Value = 100;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_13 = processType +"120118" + "013";
string OutPutfileName = batchNo_13 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_13);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_13 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt13++;
cnt13_ = " - " + cnt13.ToString() + " Images.";
}
if (i >= 1300 && i < 1400)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_14 = processType +"120118" + "014";
string OutPutfileName = batchNo_14 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_14);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_14 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");
cnt14++;
cnt14_ = " - " + cnt14.ToString() + " Images.";
}
if (i >= 1400 && i < 1500)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_15 = processType +"120118" + "015";
string OutPutfileName = batchNo_15 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_15);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", ''" + batchNo_15 + "'',''" + Imagenames[i].ToString() + "'' , ''" + OutPutfileName + "'', ''" + DateTime.Now.ToString("dd-MMM-yy") + "'' );\n");

cnt15++;
cnt15_ = " - " + cnt15.ToString() + " Images.";
}



}
osb.Append("End;");
db.InsertDeleteUpdate(osb.ToString());



}
else
{
MessageBox.Show("Image Should be less than 1500", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}

public void GenerateReport(string p_id_HCFA, string p_id_UB, string p_id_DENTAL, string PType)
{
string R_folder = "";

//if (p_id_HCFA != "" && p_id_UB == "" && p_id_DENTAL == "")
//{
// // p_id_UB = "," + p_id_UB + " ";

//}

//if (p_id_HCFA == "" && p_id_UB != "" && p_id_DENTAL == "")
//{
// // p_id_UB = "," + p_id_UB + " ";

//}
//if (p_id_HCFA == "" && p_id_UB == "" && p_id_DENTAL != "")
//{
// // p_id_DENTAL = "," + p_id_DENTAL + " ";

//}
if (p_id_HCFA != "" && p_id_UB != "" && p_id_DENTAL != "")
{
p_id_UB = "," + p_id_UB + " ";
p_id_DENTAL = "," + p_id_DENTAL + " ";
}
if (p_id_HCFA != "" && p_id_UB != "" && p_id_DENTAL == "")
{
p_id_UB = "," + p_id_UB + " ";

}







string query = "SELECT OLD_IMAGENAME,NEW_IMAGENAME FROM CCM_IMAGE_RENAME WHERE PROCESS_ID IN ( " + p_id_HCFA + " " + p_id_UB + " " + p_id_DENTAL + ") AND BATCHNO IN ( SELECT batchno FROM HCFA_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_HCFA.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' union SELECT batchno FROM UB_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_UB.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' union SELECT batchno FROM DEN_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''" + p_id_DENTAL.Replace(",", "") + "'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''" + DateTime.Now.ToString("dd/MMM/yyyy") + "'' ) ORDER BY new_imagename ASC ";
string q2 = "SELECT OLD_IMAGENAME,NEW_IMAGENAME FROM CCM_IMAGE_RENAME WHERE PROCESS_ID IN ( 78 ) AND BATCHNO IN ( SELECT batchno FROM HCFA_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '''' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' union SELECT batchno FROM UB_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= ''78'' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' union SELECT batchno FROM DEN_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '''' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,''MM/DD/YYYY'')= ''05/Jan/2012'' ) ORDER BY new_imagename ASC ";
DataTable dtb = new DataTable();
dtb = db.GetTable(q2);
if (dtb.Rows.Count > 0)
{
string DuplicateFolder = "";
DuplicateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images_Report");

if (!Directory.Exists(DuplicateFolder))
{
Directory.CreateDirectory(DuplicateFolder);
}
R_folder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);


if (File.Exists(DuplicateFolder + "\\" + PType + "_" +"120118" + "_DCN_Report.txt"))
{
File.Delete(DuplicateFolder + "\\"+PType+"_" +"120118" + "_DCN_Report.txt");
}
FileInfo t = new FileInfo(DuplicateFolder + "\\"+PType+"_" +"120118" + "_DCN_Report.txt");
StreamWriter Tex = t.AppendText();
Tex.WriteLine("TCN Original_Name");
foreach (DataRow drPrintRow in dtb.Rows)
{
String str = drPrintRow["NEW_IMAGENAME"].ToString().Replace(".TIF", "").Replace(".tif", "") + " " + drPrintRow["OLD_IMAGENAME"].ToString().Replace(".TIF", "").Replace(".tif", "");
Tex.WriteLine(str);
}

Tex.Close();
MessageBox.Show("Report is generated.\nFile name is - " + ""+PType+"_" +"120118" + "_DCN_Report.txt", "Image Renamer", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.DoEvents();

txt_FolderPath.Text = "";

Process.Start(DuplicateFolder);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;



}
else
{
MessageBox.Show("There is no batches to generate report for today''s date. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

}
}

private void btn_Cancal_Click(object sender, EventArgs e)
{
this.Close();
}

private void btn_report_Click(object sender, EventArgs e)
{
if (comboBox2.Text != "---Select---" && comboBox1.SelectedItem != null)
{

if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "185";
string p_Type_UB = "";
string p_Type_DENTAL = "";
string ptype = "CCM_HCFA";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "";
string p_Type_UB = "78";
string p_Type_DENTAL = "";

string ptype = "CCM_UB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "---Select---" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "185";
string p_Type_UB = "78";
string p_Type_DENTAL = "";

string ptype = "CCM";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "191";
string p_Type_UB = "";
string p_Type_DENTAL = "";
string ptype = "SSB_HCFA";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "";
string p_Type_UB = "192";
string p_Type_DENTAL = "";
string ptype = "SSB_UB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;

}
if (comboBox1.SelectedItem.ToString() == "Dental" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "";
string p_Type_UB = "";
string p_Type_DENTAL = "193";
string ptype = "SSB_DENTAL";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;

}

if (comboBox1.SelectedItem.ToString() == "---Select---" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "191";
string p_Type_UB = "192";
string p_Type_DENTAL = "193";
string ptype = "SSB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);

return;
}




}
else
{
MessageBox.Show("Please Select Correct Process Type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;

}
btn_submit.Enabled = false;
btn_Cancal.Enabled = false;
btn_report.Enabled = false;





}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedItem.ToString()=="CCM")
{
comboBox1.Items.Remove("HCFA Reprice");
comboBox1.Items.Remove("HCFA EOB");
comboBox1.Items.Remove("UB Reprice");
comboBox1.Items.Remove("UB EOB");
comboBox1.Items.Remove("Dental");
comboBox1.Refresh();


}
if (comboBox2.SelectedItem.ToString() == "SSB")
{
if (comboBox1.Items.Count == 3)
{
comboBox1.Items.Add("HCFA Reprice");
comboBox1.Items.Add("HCFA EOB");
comboBox1.Items.Add("UB Reprice");
comboBox1.Items.Add("UB EOB");
comboBox1.Items.Add("Dental");

}


}


}

private void button1_Click_1(object sender, EventArgs e)
{
FolderBrowserDialog f = new System.Windows.Forms.FolderBrowserDialog();
if (f.ShowDialog() == DialogResult.OK)
{
txt_FolderPath.Text = f.SelectedPath;
}
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Enabled = false;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Enabled = true;

}


}
}





--------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Numeric;
using System.Linq;
using System.Web;
using System.Web;
using System.IO;




using System.Windows.Forms;

namespace demofortiff
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}




private void button1_Click(object sender, EventArgs e)
{
//using (Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\FHM1201101250028.tif"))
//{
// using (Bitmap newBitmap = new Bitmap(bitmap))
// {
// newBitmap.SetResolution(300, 300);
// newBitmap.Save("C:\\images\\file300", System.Drawing.Imaging.ImageFormat.Tiff);
// }
//}

int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
System.Drawing.Imaging. PropertyItem piXRes = bmp.GetPropertyItem(400);
System.Drawing.Imaging.PropertyItem piYRes = bmp.GetPropertyItem(400);

// values are stored as a rational number - numerator/denominator pair
numerator = BitConverter.ToInt32(piXRes.Value, 0);
denominator = BitConverter.ToInt32(piXRes.Value, 4);
float xRes = numerator / denominator;

numerator = BitConverter.ToInt32(piYRes.Value, 0);
denominator = BitConverter.ToInt32(piYRes.Value, 4);
float yRes = numerator / denominator;

// now set the values
byte[] numeratorBytes = new byte[4];
byte[] denominatorBytes = new byte[4];

numeratorBytes = BitConverter.GetBytes(600); // specify resolution in numerator
denominatorBytes = BitConverter.GetBytes(1);

Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4); // set the XResolution value
Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);

bmp.SetPropertyItem(piXRes); // finally set the image property resolution
bmp.SetPropertyItem(piYRes);

// double ratio = maxWidth / finalWidth;
// int maxHeight = (int)img1.Height * ratio;
bmp.GetThumbnailImage(7000, 7000, null, IntPtr.Zero);



FixedSize(bmp, 200, 200);

bmp.SetResolution(600, 600); // now set the bitmap resolution

bmp.Save("C:\\images\\output.tif"); // save the image
}


}
public static Bitmap Resize(Bitmap b, int nWidth, int nHeight)
{
Bitmap bTemp = (Bitmap)b.Clone();
b = new Bitmap(nWidth, nHeight, bTemp.PixelFormat);

double nXFactor = (double)bTemp.Width / (double)nWidth;
double nYFactor = (double)bTemp.Height / (double)nHeight;

for (int x = 0; x < b.Width; ++x)
for (int y = 0; y < b.Height; ++y)
b.SetPixel(x, y, bTemp.GetPixel((int)(Math.Floor(x * nXFactor)),
(int)(Math.Floor(y * nYFactor))));

return b;
}

private void button2_Click(object sender, EventArgs e)
{
//using (Image img = Image.FromStream(memoryStream))
//{
// Guid id = img.FrameDimensionsList[0];
// System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(id);
// int totalFrame = img.GetFrameCount(dimension);
// for (int i = 0; i < totalFrame; i++)
// {
// img.SelectActiveFrame(dimension, i);

// Faxed documents will have an non-square pixel aspect ratio.
// If this is the case,adjust the height so that the
// resulting pixels are square.
// int width = img.Width;
// int height = img.Height;
// if (img.VerticalResolution < img.HorizontalResolution)
// {
// height = (int)(height * img.HorizontalResolution / img.VerticalResolution);
// }

// bitmaps.Add(new Bitmap(img, new Size(width, height)));
// }
//}

//ImageCodecInfo ici = null;
//ImageCodecInfo[] Encoders = ImageCodecInfo.GetImageEncoders();
//foreach (ImageCodecInfo ListICI in Encoders)
//{
// if (ListICI.MimeType == "image/tiff")
// {
// ici = ListICI;
// break;
// }
//}

//// Can''t find the TIFF encoder
//if (ici == null) return;

//// Set encoder to use no compression
//EncoderParameters ep = new EncoderParameters();
//ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone);

//// Load a new image
//Bitmap TempImg = new Bitmap("C:\\images\\CCM_HB_20111228_0031901.tif");

//try
//{ // Attempt to save the image
// TempImg.Save("C:\\images\\CCM_HB_20111228_.tif", ici, ep);
//}
//catch (Exception ex)
//{
// MessageBox.Show("Error saving image: " + ex.Message);
//}

//TempImg.Dispose(); // Clean up
//ep.Dispose();

//Image tif = Image.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif");
//float width = tif.PhysicalDimension.Width;
//float height = tif.PhysicalDimension.Height;


//float hresolution = tif.HorizontalResolution;
//float vresolution = tif.VerticalResolution;






//tif.Dispose();


//MessageBox.Show(width.ToString());



int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);

// values are stored as a rational number - numerator/denominator pair
//numerator = BitConverter.ToInt32(piXRes.Value, 0);
//denominator = BitConverter.ToInt32(piXRes.Value, 4);
//float xRes = numerator / denominator;

//numerator = BitConverter.ToInt32(piYRes.Value, 0);
//denominator = BitConverter.ToInt32(piYRes.Value, 4);
//float yRes = numerator / denominator;

//// now set the values
//byte[] numeratorBytes = new byte[4];
//byte[] denominatorBytes = new byte[4];

//numeratorBytes = BitConverter.GetBytes(600); // specify resolution in numerator
//denominatorBytes = BitConverter.GetBytes(1);

//Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4); // set the XResolution value
//Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

//Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
//Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);
// float height = bmp.PhysicalDimension.Height;

//bmp.SetPropertyItem(height); // finally set the image property resolution
// bmp.SetPropertyItem(piYRes);







FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300); // now set the bitmap resolution

bmp.Save("C:\\images\\boutput12222.tif"); // save the image
}






}

static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300 ,300);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
//grPhoto.Dispose();
// return bmPhoto;




// bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

// Graphics grPhoto = Graphics.FromImage(bmPhoto);
// grPhoto.Clear(Color.Black);
//// grPhoto.InterpolationMode =System.Drawing.Image.InterpolationMode.HighQualityBicubic;

// grPhoto.DrawImage(imgPhoto, new Rectangle(sourceX, sourceY, sourceX, sourceY), new Rectangle(destX, destY, destWidth, destHeight), GraphicsUnit.Pixel);

//bmPhoto.SetResolution(300, 300);
//ImageFormat.Tiff
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

// Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);



// bmPhoto.Save("C:\\images\\output1211.tif", encoderInfo, encoderParams);
//grPhoto.Dispose();
return bmPhoto;
}

private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}


private void button3_Click(object sender, EventArgs e)
{

Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif");
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
string jay = "C:\\images\\boutput12350.tif";


Image tiff = Image.FromStream(byteStream);
ImageCodecInfo encoderInfo = GetEncoderInfo ("image/tiff");

EncoderParameters encoderParams = new EncoderParameters(2);
EncoderParameter parameter = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = parameter;
parameter = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
encoderParams.Param[1] = parameter;
tiff.Save(jay, encoderInfo, encoderParams);
EncoderParameters EncoderParams = new EncoderParameters(2);
EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
EncoderParameter CompressionEncodeParam = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
EncoderParams.Param[0] = CompressionEncodeParam;
EncoderParams.Param[1] = SaveEncodeParam;
tiff.SaveAdd(EncoderParams);
// EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush);
//EncoderParams = new EncoderParameters(1);
//EncoderParams.Param[0] = SaveEncodeParam;
//tiff.SaveAdd(EncoderParams);







}



}
}


using System;
使用System.Collections.Generic;
using System.ComponentModel;
使用System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Numeric;
using System.Linq;
使用System.Web;
使用System.Web;
using System.IO;




using System.Windows.Forms;

namespace demofortiff
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}




private void button1_Click(object sender, EventArgs e)
{
//using (Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\FHM1201101250028.tif"))
//{
// using (Bitmap newBitmap = new Bitmap(bitmap))
//{
// newBitmap.SetResolution(300, 300);
// newBitmap.Save("C:\\images\\file300", System.Drawing.Imaging.ImageFormat.Tiff);
//}
//}

int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif"))
{
//obtain the XResolution and YResolution TIFFTAG values
System.Drawing.Imaging. PropertyItem piXRes = bmp.GetPropertyItem(400);
System.Drawing.Imaging.PropertyItem piYRes = bmp.GetPropertyItem(400);

//values are stored as a rational number - numerator/denominator pair
numerator = BitConverter.ToInt32(piXRes.Value, 0);
denominator = BitConverter.ToInt32(piXRes.Value, 4);
float xRes = numerator/denominator;

numerator = BitConverter.ToInt32(piYRes.Value, 0);
denominator = BitConverter.ToInt32(piYRes.Value, 4);
float yRes = numerator/denominator;

//now set the values
byte[] numeratorBytes = new byte[4];
byte[] denominatorBytes = new byte[4];

numeratorBytes = BitConverter.GetBytes(600);//specify resolution in numerator
denominatorBytes = BitConverter.GetBytes(1);

Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4);//set the XResolution value
Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4);//set the YResolution value
Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);

bmp.SetPropertyItem(piXRes);//finally set the image property resolution
bmp.SetPropertyItem(piYRes);

// double ratio = maxWidth/finalWidth;
// int maxHeight = (int)img1.Height * ratio;
bmp.GetThumbnailImage(7000, 7000, null, IntPtr.Zero);



FixedSize(bmp, 200, 200);

bmp.SetResolution(600, 600);//now set the bitmap resolution

bmp.Save("C:\\images\\output.tif");//save the image
}


}
public static Bitmap Resize(Bitmap b, int nWidth, int nHeight)
{
Bitmap bTemp = (Bitmap)b.Clone();
b = new Bitmap(nWidth, nHeight, bTemp.PixelFormat);

double nXFactor = (double)bTemp.Width/(double)nWidth;
double nYFactor = (double)bTemp.Height/(double)nHeight;

for (int x = 0; x < b.Width; ++x)
for (int y = 0; y < b.Height; ++y)
b.SetPixel(x, y, bTemp.GetPixel((int)(Math.Floor(x * nXFactor)),
(int)(Math.Floor(y * nYFactor))));

return b;
}

private void button2_Click(object sender, EventArgs e)
{
//using (Image img = Image.FromStream(memoryStream))
//{
// Guid id = img.FrameDimensionsList[0];
// System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(id);
// int totalFrame = img.GetFrameCount(dimension);
// for (int i = 0; i < totalFrame; i++)
//{
// img.SelectActiveFrame(dimension, i);

// Faxed documents will have an non-square pixel aspect ratio.
// If this is the case,adjust the height so that the
// resulting pixels are square.
// int width = img.Width;
// int height = img.Height;
// if (img.VerticalResolution < img.HorizontalResolution)
//{
// height = (int)(height * img.HorizontalResolution/img.VerticalResolution);
// }

// bitmaps.Add(new Bitmap(img, new Size(width, height)));
//}
//}

//ImageCodecInfo ici = null;
//ImageCodecInfo[] Encoders = ImageCodecInfo.GetImageEncoders();
//foreach (ImageCodecInfo ListICI in Encoders)
//{
// if (ListICI.MimeType == "image/tiff")
//{
// ici = ListICI;
//中断;
//}
//}

////Can''t find the TIFF encoder
//if (ici == null) return;

////Set encoder to use no compression
//EncoderParameters ep = new EncoderParameters();
//ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone);

////Load a new image
//Bitmap TempImg = new Bitmap("C:\\images\\CCM_HB_20111228_0031901.tif");

//尝试
//{//Attempt to save the image
// TempImg.Save("C:\\images\\CCM_HB_20111228_.tif", ici, ep);
//}
//catch(异常前)
//{
// MessageBox.Show("Error saving image: " + ex.Message);
//}

//TempImg.Dispose();//Clean up
//ep.Dispose();

//Image tif = Image.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif");
//float width = tif.PhysicalDimension.Width;
//float height = tif.PhysicalDimension.Height;


//float hresolution = tif.HorizontalResolution;
//float vresolution = tif.VerticalResolution;






//tif.Dispose();


//MessageBox.Show(width.ToString());



int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif"))
{
//obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);

//values are stored as a rational number - numerator/denominator pair
//numerator = BitConverter.ToInt32(piXRes.Value, 0);
//denominator = BitConverter.ToInt32(piXRes.Value, 4);
//float xRes = numerator/denominator;

//numerator = BitConverter.ToInt32(piYRes.Value, 0);
//denominator = BitConverter.ToInt32(piYRes.Value, 4);
//float yRes = numerator/denominator;

////now set the values
//byte[] numeratorBytes = new byte[4];
//byte[] denominatorBytes = new byte[4];

//numeratorBytes = BitConverter.GetBytes(600);//specify resolution in numerator
//denominatorBytes = BitConverter.GetBytes(1);

//Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4);//set the XResolution value
//Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

//Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4);//set the YResolution value
//Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);
// float height = bmp.PhysicalDimension.Height;

//bmp.SetPropertyItem(height);//finally set the image property resolution
//bmp.SetPropertyItem(piYRes);







FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300);//now set the bitmap resolution

bmp.Save("C:\\images\\boutput12222.tif");//save the image
}






}

static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width/(float)sourceWidth);
nPercentH = ((float)Height/(float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent))/2);
}
其他
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent))/2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300 ,300);
图形grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
//grPhoto.Dispose();
//return bmPhoto;




//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

// Graphics grPhoto = Graphics.FromImage(bmPhoto);
//grPhoto.Clear(Color.Black);
////grPhoto.InterpolationMode =System.Drawing.Image.InterpolationMode.HighQualityBicubic;

// grPhoto.DrawImage(imgPhoto, new Rectangle(sourceX, sourceY, sourceX, sourceY), new Rectangle(destX, destY, destWidth, destHeight), GraphicsUnit.Pixel);

//bmPhoto.SetResolution(300, 300);
//ImageFormat.Tiff
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

//Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);



//bmPhoto.Save("C:\\images\\output1211.tif", encoderInfo, encoderParams);
//grPhoto.Dispose();
return bmPhoto;
}

private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
返回null;
}


private void button3_Click(对象发送者,EventArgs e)
{

Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif");
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
string jay = "C:\\images\\boutput12350.tif";


Image tiff = Image.FromStream(byteStream);
ImageCodecInfo encoderInfo = GetEncoderInfo ("image/tiff");

EncoderParameters encoderParams = new EncoderParameters(2);
EncoderParameter parameter = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = parameter;
parameter = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
encoderParams.Param[1] = parameter;
tiff.Save(jay, encoderInfo, encoderParams);
EncoderParameters EncoderParams = new EncoderParameters(2);
EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
EncoderParameter CompressionEncodeParam = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
EncoderParams.Param[0] = CompressionEncodeParam;
EncoderParams.Param[1] = SaveEncodeParam;
tiff.SaveAdd(EncoderParams);
//EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush);
//EncoderParams = new EncoderParameters(1);
//EncoderParams.Param[0] = SaveEncodeParam;
//tiff.SaveAdd(EncoderParams);







}



}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Numeric;
using System.Linq;
using System.Web;
using System.Web;
using System.IO;




using System.Windows.Forms;

namespace demofortiff
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}




private void button1_Click(object sender, EventArgs e)
{
//using (Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\FHM1201101250028.tif"))
//{
// using (Bitmap newBitmap = new Bitmap(bitmap))
// {
// newBitmap.SetResolution(300, 300);
// newBitmap.Save("C:\\images\\file300", System.Drawing.Imaging.ImageFormat.Tiff);
// }
//}

int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
System.Drawing.Imaging. PropertyItem piXRes = bmp.GetPropertyItem(400);
System.Drawing.Imaging.PropertyItem piYRes = bmp.GetPropertyItem(400);

// values are stored as a rational number - numerator/denominator pair
numerator = BitConverter.ToInt32(piXRes.Value, 0);
denominator = BitConverter.ToInt32(piXRes.Value, 4);
float xRes = numerator / denominator;

numerator = BitConverter.ToInt32(piYRes.Value, 0);
denominator = BitConverter.ToInt32(piYRes.Value, 4);
float yRes = numerator / denominator;

// now set the values
byte[] numeratorBytes = new byte[4];
byte[] denominatorBytes = new byte[4];

numeratorBytes = BitConverter.GetBytes(600); // specify resolution in numerator
denominatorBytes = BitConverter.GetBytes(1);

Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4); // set the XResolution value
Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);

bmp.SetPropertyItem(piXRes); // finally set the image property resolution
bmp.SetPropertyItem(piYRes);

// double ratio = maxWidth / finalWidth;
// int maxHeight = (int)img1.Height * ratio;
bmp.GetThumbnailImage(7000, 7000, null, IntPtr.Zero);



FixedSize(bmp, 200, 200);

bmp.SetResolution(600, 600); // now set the bitmap resolution

bmp.Save("C:\\images\\output.tif"); // save the image
}


}
public static Bitmap Resize(Bitmap b, int nWidth, int nHeight)
{
Bitmap bTemp = (Bitmap)b.Clone();
b = new Bitmap(nWidth, nHeight, bTemp.PixelFormat);

double nXFactor = (double)bTemp.Width / (double)nWidth;
double nYFactor = (double)bTemp.Height / (double)nHeight;

for (int x = 0; x < b.Width; ++x)
for (int y = 0; y < b.Height; ++y)
b.SetPixel(x, y, bTemp.GetPixel((int)(Math.Floor(x * nXFactor)),
(int)(Math.Floor(y * nYFactor))));

return b;
}

private void button2_Click(object sender, EventArgs e)
{
//using (Image img = Image.FromStream(memoryStream))
//{
// Guid id = img.FrameDimensionsList[0];
// System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(id);
// int totalFrame = img.GetFrameCount(dimension);
// for (int i = 0; i < totalFrame; i++)
// {
// img.SelectActiveFrame(dimension, i);

// Faxed documents will have an non-square pixel aspect ratio.
// If this is the case,adjust the height so that the
// resulting pixels are square.
// int width = img.Width;
// int height = img.Height;
// if (img.VerticalResolution < img.HorizontalResolution)
// {
// height = (int)(height * img.HorizontalResolution / img.VerticalResolution);
// }

// bitmaps.Add(new Bitmap(img, new Size(width, height)));
// }
//}

//ImageCodecInfo ici = null;
//ImageCodecInfo[] Encoders = ImageCodecInfo.GetImageEncoders();
//foreach (ImageCodecInfo ListICI in Encoders)
//{
// if (ListICI.MimeType == "image/tiff")
// {
// ici = ListICI;
// break;
// }
//}

//// Can''t find the TIFF encoder
//if (ici == null) return;

//// Set encoder to use no compression
//EncoderParameters ep = new EncoderParameters();
//ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone);

//// Load a new image
//Bitmap TempImg = new Bitmap("C:\\images\\CCM_HB_20111228_0031901.tif");

//try
//{ // Attempt to save the image
// TempImg.Save("C:\\images\\CCM_HB_20111228_.tif", ici, ep);
//}
//catch (Exception ex)
//{
// MessageBox.Show("Error saving image: " + ex.Message);
//}

//TempImg.Dispose(); // Clean up
//ep.Dispose();

//Image tif = Image.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif");
//float width = tif.PhysicalDimension.Width;
//float height = tif.PhysicalDimension.Height;


//float hresolution = tif.HorizontalResolution;
//float vresolution = tif.VerticalResolution;






//tif.Dispose();


//MessageBox.Show(width.ToString());



int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);

// values are stored as a rational number - numerator/denominator pair
//numerator = BitConverter.ToInt32(piXRes.Value, 0);
//denominator = BitConverter.ToInt32(piXRes.Value, 4);
//float xRes = numerator / denominator;

//numerator = BitConverter.ToInt32(piYRes.Value, 0);
//denominator = BitConverter.ToInt32(piYRes.Value, 4);
//float yRes = numerator / denominator;

//// now set the values
//byte[] numeratorBytes = new byte[4];
//byte[] denominatorBytes = new byte[4];

//numeratorBytes = BitConverter.GetBytes(600); // specify resolution in numerator
//denominatorBytes = BitConverter.GetBytes(1);

//Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4); // set the XResolution value
//Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

//Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
//Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);
// float height = bmp.PhysicalDimension.Height;

//bmp.SetPropertyItem(height); // finally set the image property resolution
// bmp.SetPropertyItem(piYRes);







FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300); // now set the bitmap resolution

bmp.Save("C:\\images\\boutput12222.tif"); // save the image
}






}

static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300 ,300);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
//grPhoto.Dispose();
// return bmPhoto;




// bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

// Graphics grPhoto = Graphics.FromImage(bmPhoto);
// grPhoto.Clear(Color.Black);
//// grPhoto.InterpolationMode =System.Drawing.Image.InterpolationMode.HighQualityBicubic;

// grPhoto.DrawImage(imgPhoto, new Rectangle(sourceX, sourceY, sourceX, sourceY), new Rectangle(destX, destY, destWidth, destHeight), GraphicsUnit.Pixel);

//bmPhoto.SetResolution(300, 300);
//ImageFormat.Tiff
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

// Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);



// bmPhoto.Save("C:\\images\\output1211.tif", encoderInfo, encoderParams);
//grPhoto.Dispose();
return bmPhoto;
}

private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}


private void button3_Click(object sender, EventArgs e)
{

Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif");
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
string jay = "C:\\images\\boutput12350.tif";


Image tiff = Image.FromStream(byteStream);
ImageCodecInfo encoderInfo = GetEncoderInfo ("image/tiff");

EncoderParameters encoderParams = new EncoderParameters(2);
EncoderParameter parameter = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = parameter;
parameter = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
encoderParams.Param[1] = parameter;
tiff.Save(jay, encoderInfo, encoderParams);
EncoderParameters EncoderParams = new EncoderParameters(2);
EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
EncoderParameter CompressionEncodeParam = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
EncoderParams.Param[0] = CompressionEncodeParam;
EncoderParams.Param[1] = SaveEncodeParam;
tiff.SaveAdd(EncoderParams);
// EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush);
//EncoderParams = new EncoderParameters(1);
//EncoderParams.Param[0] = SaveEncodeParam;
//tiff.SaveAdd(EncoderParams);







}



}
}


static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width/(float)sourceWidth);
nPercentH = ((float)Height/(float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent))/2);
}
其他
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent))/2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300, 300);
图形grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

//Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);

return bmPhoto;
}











private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
返回null;
}










using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\QUOTE014.tif"))
{
//obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);


FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300);//now set the bitmap resolution


}
static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300, 300);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

// Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);

return bmPhoto;
}











private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}










using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\QUOTE014.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);


FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300); // now set the bitmap resolution


}


这篇关于TIFF图像重命名与重新设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆