//************************************** **************************************** **
// Name: sysresearcha_z
// Function: publish the questionnaire
// Author: zql
// Create time: 2004/09/02
// Version 1.0
// Related table: infresearch, infresproject, infresoption
// Related class:
//************************************** **************************************** **
Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. text;
Using aaaaaa. com;
Namespace AAAAA. infocenter. sys
{
/// <Summary>
/// Abstract description of sysresearcha_z.
/// </Summary>
Public class sysresearcha_z: system. Web. UI. Page
{
Protected system. Web. UI. webcontrols. textbox txtsubject;
Protected system. Web. UI. webcontrols. DataGrid datagrid1;
Protected system. Web. UI. htmlcontrols. htmlform form1;
Protected system. Web. UI. webcontrols. Label label1;
Protected system. Web. UI. webcontrols. Label label2;
Protected system. Web. UI. webcontrols. Label label3;
Protected system. Web. UI. webcontrols. Button btnprjadd;
Protected system. Web. UI. webcontrols. textbox txtshow1;
Protected system. Web. UI. webcontrols. dropdownlist drptype;
Protected system. Web. UI. webcontrols. textbox txtproject;
Protected system. Web. UI. webcontrols. Label label4;
Protected system. Web. UI. webcontrols. Label label6;
Protected system. Web. UI. webcontrols. dropdownlist drpshow;
Protected system. Web. UI. webcontrols. Button btncontent;
Protected system. Web. UI. webcontrols. DataGrid datagrid2;
Protected system. Web. UI. webcontrols. textbox txtcontent;
Datatable research1;
Dataview researchview1;
Datatable content;
Protected system. Web. UI. webcontrols. Button btsend;
Protected system. Web. UI. webcontrols. Button btcancel;
Dataview contentview;
Datetime dtime;
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
// *************** Temp code fro test ******************
Session ["userid"] = "61844785-b2d1-4b2a-9d01-e671a56c6386 ";
Session ["usertype"] = "S ";
Session ["userright"] = "M, 012 ";
Application ["elibid"] = "027b9961-f00a-4594-8775-775d9e5f8e4e ";
// *************** Temp code fro test ******************
// For (I = 0; I <10; I ++)
//{
// ROW = Tb. newrow ();
// TB. Rows. Add (ROW );
//}
If (session ["research1"] = NULL)
{
Research1 = new datatable ();
Research1.columns. Add (New datacolumn ("showno", typeof (string )));
Research1.columns. Add (New datacolumn ("type", typeof (string )));
Research1.columns. Add (New datacolumn ("project", typeof (string )));
// Datarow row;
// For (INT I = 0; I <10; I ++)
//{
// ROW = research1.newrow ();
// Research1.rows. Add (ROW );
//}
Session ["research1"] = research1;
}
Else
{
Research1 = (datatable) session ["research1"];
}
Researchview1 = new dataview (research1 );
Datagrid1.datasource = researchview1;
Researchview1.sort = "showno ";
Datagrid1.databind ();
If (session ["content"] = NULL)
{
Content = new datatable ();
Content. Columns. Add (New datacolumn ("showno", typeof (string )));
Content. Columns. Add (New datacolumn ("content", typeof (string )));
Session ["content"] = content;
}
Else
{
Content = (datatable) session ["content"];
}
Contentview = new dataview (content );
Datagrid2.datasource = contentview;
Contentview. Sort = "showno ";
Datagrid2.databind ();
}
# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. btnprjadd. Click + = new system. eventhandler (this. btnprjadd_click );
This. Maid + = new system. Web. UI. webcontrols. Maid (this. Maid editcommand );
This. Maid + = new system. Web. UI. webcontrols. Maid (this. Maid deletecommand );
This. btncontent. Click + = new system. eventhandler (this. btncontent_click );
This. Maid + = new system. Web. UI. webcontrols. Maid (this. Maid );
This. Maid + = new system. Web. UI. webcontrols. Maid (this. Maid );
This. btsend. Click + = new system. eventhandler (this. btsend_click );
This. btcancel. Click + = new system. eventhandler (this. btcancel_click );
This. Load + = new system. eventhandler (this. page_load );
}
# Endregion
Private void btnprjadd_click (Object sender, system. eventargs E)
{
// Add new data to the grid
If (txtshow1.text = "")
{
Response. Write ("<SCRIPT> alert ('display sequence cannot be empty. '); </SCRIPT> ");
Return;
}
If (txtproject. Text = "")
{
Response. Write ("<SCRIPT> alert ('Project cannot be blank. '); </SCRIPT> ");
Return;
}
If (btnprjadd. Text = "save ")
{
Btnprjadd. Text = "add"; // rename the button
// Researchview1.delete (delflg); // Delete the record first
Researchview1.delete (INT) session ["delflg"]); // Delete the record first
// Delflg =-1; // set the flag to-1.
}
Datarow DR = research1.newrow ();
Dr [0] = txtshow1.text. tostring ();
Dr [1] = drptype. selecteditem. value. tostring ();
Dr [2] = txtproject. Text. tostring ();
Research1.rows. Add (DR); // Add a new row of data.
Datagrid1.databind ();
Drpshow. datasource = researchview1;
Drpshow. datavaluefield = "showno ";
Drpshow. databind ();
// For (INT I = 0; I <(10-convert.toint32 (research1.rows. Count. tostring ()/10); I ++)
//{
// DR = research1.newrow ();
// Research1.rows. Add (DR );
//}
// Clear input
Txtshow1.text = "";
Txtproject. Text = "";
}
Private void datagrid1_deletecommand (Object source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
// Delete a row
Researchview1.delete (E. Item. itemindex); // This row deletes the currently selected row
Datagrid1.databind ();
Drpshow. databind ();
// If you press modify and then click Delete, You need to rename the Add button.
Btnprjadd. Text = "add ";
}
Private void datagrid1_editcommand (Object source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
// Delflg = maid; // obtain the currently selected row number
Session ["delflg"] = E. Item. itemindex;
Txtshow1.text = E. Item. cells [0]. Text. tostring (); // get the row Value
Drptype. selectedvalue = E. Item. cells [1]. Text. tostring ();
Txtproject. Text = E. Item. cells [2]. Text. tostring ();
Btnprjadd. Text = "save"; // change the name of the Add button.
}
Private void datagrid2_deletecommand (Object source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
// Delete a row
Contentview. Delete (E. Item. itemindex); // Delete the row selected currently.
Datagrid2.databind ();
// If you press modify and then click Delete, You need to rename the Add button.
Btncontent. Text = "add ";
}
Private void datagrid2_editcommand (Object source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
Session ["cdelflg"] = E. Item. itemindex; // obtain the currently selected row number.
Drpshow. selectedvalue = E. Item. cells [0]. Text. tostring ();
Txtcontent. Text = E. Item. cells [1]. Text. tostring ();
Btncontent. Text = "save"; // change the name of the Add button
}
Private void btncontent_click (Object sender, system. eventargs E)
{
// Add new data to the grid
If (txtcontent. Text = "")
{
Response. Write ("<SCRIPT> alert ('content cannot be blank. '); </SCRIPT> ");
Return;
}
If (btncontent. Text = "save ")
{
Btncontent. Text = "add"; // rename the button
Contentview. Delete (INT) session ["cdelflg"]); // Delete the record first
}
Datarow DR = content. newrow ();
Dr [0] = drpshow. selecteditem. value. tostring ();
Dr [1] = txtcontent. Text. tostring ();
Content. Rows. Add (DR); // Add a new row of data.
Datagrid2.databind ();
// Clear input
Txtcontent. Text = "";
}
Private void delresearch (datetime dtime)
{
// Delete all data
String strsql;
Strsql = "delete from infresearch where issuancetime = '" + dtime + "'";
Localdbdealer IV = new localdbdealer ();
Bool success = IV. execommandbool (strsql );
If (! Success)
{
Response. Write ("<SCRIPT> alert ('failed to delete database table infresearch '); </SCRIPT> ");
// Return;
}
Strsql = "delete from infresproject where createtime = '" + dtime + "'";
Success = IV. execommandbool (strsql );
If (! Success)
{
Response. Write ("<SCRIPT> alert ('failed to delete database table infresproject '); </SCRIPT> ");
// Return;
}
Strsql = "delete from infresoption where createtime = '" + dtime + "'";
Success = IV. execommandbool (strsql );
If (! Success)
{
Response. Write ("<SCRIPT> alert ('failed to delete database table infresoption '); </SCRIPT> ");
// Return;
}
}
Private void btsend_click (Object sender, system. eventargs E)
{
// Check before submission
String rtnstr;
If (rtnstr = verify. checkinput ("topic", this.txt subject. Text, 100, false ))! = "")
{
Response. Write ("<SCRIPT> alert ('" + rtnstr + "'); </SCRIPT> ");
Return;
}
If (maid. Count. tostring () = "0 ")
{
Response. Write ("<SCRIPT> alert ('no project data, cannot submit. '); </SCRIPT> ");
Return;
}
If (maid. Count. tostring () = "0 ")
{
Response. Write ("<SCRIPT> alert ('no content data, cannot submit. '); </SCRIPT> ");
Return;
}
// First save the data to the infresearch table (research1)
String strsql;
Dtime = datetime. now;
Strsql = "insert into infresearch (subject, state, issuancetime, ballot, creater, createtime) values ('";
Strsql = strsql + txtsubject. Text. Trim () + "', '1','"; // 1 indicates the editing status.
Strsql = strsql + dtime + "', 0 ,'";
Strsql = strsql + session ["userid"]. tostring () + "','";
Strsql = strsql + dtime + "')";
Localdbdealer IV = new localdbdealer ();
Bool success = IV. execommandbool (strsql );
If (! Success)
{
Response. Write ("<SCRIPT> alert ('database writing failed'); </SCRIPT> ");
Delresearch (dtime );
}
// Obtain the guid
Strsql = "select researchid from infresearch where subject = '" + txtsubject. Text. Trim () + "' and issuancetime = '" + dtime + "'";
Dataset DS = IV. exeselectds (strsql );
String getguid = "0 ";
Foreach (datarow myrow in DS. Tables [0]. Rows)
{
Getguid = myrow ["researchid"]. tostring ();
}
// Check the number of rows of data in research1 and determine the cycle
// Int Ss = convert. toint32 (research1.rows. Count. tostring ());
// Read data
// String AA = research1.rows [0] [0]. tostring ();
// Write to database infresproject
For (INT I = 0; I <convert. toint32 (research1.rows. Count. tostring (); I ++)
{
// AA = research1.rows [I] [0]. tostring ();
Strsql = "insert into infresproject (researchid, showorder, butttype, project, creater, createtime) values ('";
Strsql = strsql + getguid + "','" + research1.rows [I] [0]. tostring () + "','";
Strsql = strsql + research1.rows [I] [1]. tostring () + "','";
Strsql = strsql + research1.rows [I] [2]. tostring () + "','";
Strsql = strsql + session ["userid"]. tostring () + "','";
Strsql = strsql + dtime + "')";
Success = IV. execommandbool (strsql );
If (! Success)
{
Response. Write ("<SCRIPT> alert ('database writing failed'); </SCRIPT> ");
Delresearch (dtime );
}
}
// Write to the database table infresoption
For (INT I = 0; I <convert. toint32 (content. Rows. Count. tostring (); I ++)
{
// Obtain the guid first
Strsql = "select resprojectid from infresproject where showorder = '" + content. rows [I] [0]. tostring () + "'and createtime ='" + dtime + "'";
DS = IV. exeselectds (strsql );
Foreach (datarow myrow in DS. Tables [0]. Rows)
{
Getguid = myrow ["resprojectid"]. tostring ();
}
Strsql = "insert into infresoption (resprojectid, content, creater, createtime) values ('";
Strsql = strsql + getguid + "','" + content. Rows [I] [1]. tostring () + "','";
Strsql = strsql + session ["userid"]. tostring () + "','";
Strsql = strsql + dtime + "')";
Success = IV. execommandbool (strsql );
If (! Success)
{
Response. Write ("<SCRIPT> alert ('database writing failed'); </SCRIPT> ");
Delresearch (dtime );
}
}
Response. Write ("<SCRIPT> alert ('Survey table submitted successfully. '); </SCRIPT> ");
Btsend. Enabled = false;
}
Private void btcancel_click (Object sender, system. eventargs E)
{
// Clear all data
Session ["research1"] = NULL;
Session ["content"] = NULL;
Datagrid1.datasource = NULL;
Datagrid2.datasource = NULL;
Datagrid1.databind ();
Datagrid2.databind ();
This. drpshow. datasource = NULL;
// Drpshow. datavaluefield = "";
// Drpshow. databind ();
Drpshow. Items. Clear ();
Page_load (sender, e );
Btsend. Enabled = true;
}
}
}