| using System; | 
| using System.Collections.Generic; | 
| using System.ComponentModel; | 
| using System.Data; | 
| using System.Drawing; | 
| using System.Text; | 
| using System.Windows.Forms; | 
|   | 
| namespace BLL | 
| { | 
|     public partial class KB_KanbanPlaySet : Form | 
|     { | 
|         public KB_KanbanPlaySet() | 
|         { | 
|             InitializeComponent(); | 
|         } | 
|   | 
|         public const Int16 HItemIDCol = 0; | 
|         public const Int16 HSnoCol = 1; | 
|         public const Int16 HKanBanNameCol = 2; | 
|         public const Int16 HDisplayTimesCol = 3; | 
|         // | 
|         public Int64 HCurNo = 1;  //µ±Ç°¿´°å | 
|         public Int64 HCurSumTimes = 0; //µ±Ç°¿´°å×Üʱ¼ä | 
|         public Int64 HCurTimes = 0; //µ±Ç°¿´°åÒѺÄÓÃʱ¼ä | 
|         public Int64 HSumNo = 0;   //×Ü¿´°åÊýÁ¿ | 
|         public string HCurKanbanName = ""; | 
|         Form frm; | 
|   | 
|         private void KB_KanbanPlaySet_Load(object sender, EventArgs e) | 
|         { | 
|             initGrid(); | 
|             ShowBill(); | 
|   | 
|         } | 
|   | 
|         private void ShowBill() | 
|         { | 
|             try | 
|             { | 
|                 SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); | 
|                 //   | 
|                 //»ñÈ¡IP | 
|                 string sIP = DBUtility.ClsPub.IPAddress; | 
|                 DataSet ds; | 
|                 ds = oCn.RunProcReturn("select * from KB_KanbanPlaySet Where HIPAddr='" + sIP + "'", "KB_KanbanPlaySet"); | 
|                 if (ds == null || ds.Tables[0].Rows.Count == 0) | 
|                 {  | 
|                     return; | 
|                 } | 
|                 else | 
|                 { | 
|                     for (int i = 0; i < ds.Tables[0].Rows.Count; i++) | 
|                     { | 
|                         grdMain.Rows[i].Cells[HSnoCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HSNO"]); | 
|                         grdMain.Rows[i].Cells[HKanBanNameCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HKanBanName"]); | 
|                         grdMain.Rows[i].Cells[HDisplayTimesCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HDisplayTimes"]);  | 
|                     } | 
|                 }   | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 MessageBox.Show("ÏÔʾʧ°Ü!" + e.Message); | 
|                  | 
|             } | 
|         } | 
|   | 
|         //³õʼ»¯Íø¸ñ | 
|         private void initGrid() | 
|         { | 
|             grdMain.ColumnCount = 4;                       //×ÜÁÐÊý | 
|             DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name); | 
|             //= | 
|             grdMain.Columns[HSnoCol].HeaderText = "ÐòºÅ"; | 
|             grdMain.Columns[HKanBanNameCol].HeaderText = "¿´°åÃû³Æ"; | 
|             grdMain.Columns[HDisplayTimesCol].HeaderText = "²¥·Åʱ¼ä";  | 
|             //== | 
|             grdMain.Columns[HItemIDCol].Visible = false; | 
|             // | 
|             DBUtility.ClsPub.GetGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath); | 
|         } | 
|   | 
|         private void cmdCancel_Click(object sender, EventArgs e) | 
|         { | 
|             DBUtility.ClsPub.SaveGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath); | 
|             this.Close(); | 
|         } | 
|   | 
|         private void cmdSave_Click(object sender, EventArgs e) | 
|         { | 
|             SaveBill(); | 
|         } | 
|   | 
|         private void SaveBill() | 
|         { | 
|             SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); | 
|             // | 
|             DisNo(); | 
|             //»ñÈ¡IP | 
|             string sIP = DBUtility.ClsPub.IPAddress; | 
|             oCn.RunProc("delete from KB_KanbanPlaySet Where HIPAddr='" + sIP  + "'"); | 
|             for (int i = 0; i < grdMain.Rows.Count; i++) | 
|             { | 
|                 if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HKanBanNameCol].Value) != "") | 
|                 { | 
|                     oCn.RunProc("insert into KB_KanbanPlaySet(HSNO,HIPAddr,HMaker,HMakeDate,HKanBanName " +  | 
|                         ",HMouldName,HDisplayTimes,HRelTimes) " +  | 
|                         " values( " + | 
|                         "'" + DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HSnoCol].Value) + "'" + | 
|                         ",'" + DBUtility.ClsPub.isStrNull(sIP) + "'" + | 
|                         ",'" + DBUtility.ClsPub.CurUserName + "'" + | 
|                         ",getdate()" + | 
|                         ",'" + DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HKanBanNameCol].Value) + "'" + | 
|                         ",''" + | 
|                         "," + DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HDisplayTimesCol].Value) + "" + | 
|                         "," + DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HDisplayTimesCol].Value)/30 + "" +  | 
|                         ")"); | 
|                 } | 
|                 else | 
|                 {  | 
|                     // | 
|                 } | 
|             } | 
|   | 
|         } | 
|   | 
|         private void timer1_Tick(object sender, EventArgs e) | 
|         { | 
|             if (HCurSumTimes <= HCurTimes) | 
|             { | 
|                 Display(); | 
|             } | 
|             else | 
|             { | 
|                 HCurTimes = HCurTimes + 1; | 
|             } | 
|         } | 
|   | 
|         private void Display() | 
|         { | 
|             try | 
|             { | 
|                 // | 
|                 SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); | 
|                 //   | 
|                 if (HSumNo <= HCurNo) | 
|                 { | 
|                     HCurNo = 0; | 
|                 } | 
|                 //»ñÈ¡IP | 
|                 string sIP = DBUtility.ClsPub.IPAddress; | 
|                 DataSet ds; | 
|                 ds = oCn.RunProcReturn("select top 1 HSNO,HKanBanName,HDisplayTimes,HRelTimes from KB_KanbanPlaySet Where HIPAddr='" + sIP + "' and HSNO>" + HCurNo + " order by hsno ", "KB_KanbanPlaySet"); | 
|                 if (ds == null) | 
|                 { | 
|                     MessageBox.Show("¶ÁÈ¡Òì³£!"); | 
|                     return; | 
|                 } | 
|                 else | 
|                 { | 
|                     if (ds.Tables[0].Rows.Count == 0) | 
|                     { | 
|                         MessageBox.Show("¶ÁÈ¡Òì³£2!"); | 
|                         HCurNo = 0; | 
|                         return; | 
|                     } | 
|                     else | 
|                     { | 
|                         HCurSumTimes = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HRelTimes"]); ; //µ±Ç°¿´°å×Üʱ¼ä | 
|                         HCurTimes = 0; //µ±Ç°¿´°åÒѺÄÓÃʱ¼ä | 
|                         HCurNo = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HSNO"]);//µ±Ç°¿´°åÐòºÅ | 
|                         HCurKanbanName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HKanBanName"]);//µ±Ç°¿´°å  | 
|                         //¸ù¾Ý¿´°åÃûÏÔʾ¶ÔÓ¦¿´°å | 
|                         CloseAllKanban(); | 
|                         ShowKanbanByName(HCurKanbanName); | 
|   | 
|                     } | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 MessageBox.Show("È¡Êýʧ°Ü!" + e.Message); | 
|             } | 
|         } | 
|          | 
|         //¹Ø±ÕÈ«²¿¿´°å | 
|         private void CloseAllKanban() | 
|         { | 
|             try | 
|             { | 
|                 if (frm == null) | 
|                 { | 
|                 } | 
|                 else | 
|                 { | 
|                     frm.Close(); | 
|                     frm = null; | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 MessageBox.Show("¹Ø±Õʧ°Ü!" + e.Message); | 
|             } | 
|         } | 
|   | 
|         //¸ù¾ÝÃû×ÖÏÔʾ¶ÔÓ¦¿´°å | 
|         private void ShowKanbanByName(string sCurKanbanName) | 
|         { | 
|             try | 
|             { | 
|                 switch (sCurKanbanName) | 
|                 { | 
|                     case "1": | 
|                         frm = new Xt_AccountPeriod(); | 
|                         frm.Show(); | 
|                         break; | 
|                     case "2": | 
|                         frm = new Frm_SQLInfo(); | 
|                         frm.Show(); | 
|                         break; | 
|                     case "3": | 
|                         frm = new Frm_SQLInfo(); | 
|                         frm.Show(); | 
|                         break; | 
|                     default: | 
|   | 
|                         break; | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 MessageBox.Show("È¡Êýʧ°Ü!" + e.Message); | 
|             } | 
|         } | 
|   | 
|         private bool GetKanbanSet() | 
|         { | 
|             try | 
|             { | 
|                 SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); | 
|                 //  | 
|                 //´ÓÊý¾Ý¿â»ñÈ¡Êý¾Ý²¢Ð´Èë±äÁ¿ | 
|                 HCurNo = 1;  //µ±Ç°¿´°å | 
|                 HSumNo = 0;   //×Ü¿´°åÊýÁ¿ | 
|                 //»ñÈ¡IP | 
|                 string sIP = DBUtility.ClsPub.IPAddress; | 
|                 DataSet ds; | 
|                 ds = oCn.RunProcReturn("select count(1) HCount from KB_KanbanPlaySet Where HIPAddr='" + sIP + "'", "KB_KanbanPlaySet"); | 
|                 if (ds == null || ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     MessageBox.Show("ûÓÐÕÒµ½¸ÃIPÉèÖõĿ´°åÐÅÏ¢!"); | 
|                     return false; | 
|                 } | 
|                 else | 
|                 { | 
|                     HSumNo = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0][0]); | 
|                 } | 
|                 if (HSumNo < HCurNo) | 
|                 { | 
|                     MessageBox.Show("×Ü¿´°åÊýÁ¿Ð¡ÓÚµ±Ç°¿´°å±àºÅ!"); | 
|                     return false; | 
|                 } | 
|                 return true; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 MessageBox.Show("ÉèÖÃʧ°Ü!" + e.Message); | 
|                 return false; | 
|             } | 
|         } | 
|   | 
|         private void cmdPlay_Click(object sender, EventArgs e) | 
|         { | 
|             //»ñÈ¡Êý¾Ý¿âÊý¾Ý | 
|             if (GetKanbanSet()==false) | 
|             { | 
|                 timer1.Enabled = false; | 
|                 return; | 
|             } | 
|             // | 
|             timer1.Enabled = true; | 
|             cmdPlay.Enabled = false; | 
|             cmdPause.Enabled = true; | 
|             tabControl1.Visible = false; | 
|             groupBox2.Visible = false; | 
|             HCurNo = 0; | 
|             Display(); | 
|   | 
|         } | 
|   | 
|         private void cmdPause_Click(object sender, EventArgs e) | 
|         {  | 
|             timer1.Enabled = false; | 
|             cmdPlay.Enabled = true; | 
|             cmdPause.Enabled = false; | 
|             tabControl1.Visible = true; | 
|             groupBox2.Visible = true; | 
|         } | 
|   | 
|         private void DisNo() | 
|         { | 
|             for (int i = 0; i < grdMain.Rows.Count; i++) | 
|             { | 
|                 if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HKanBanNameCol].Value) != "") | 
|                 { | 
|                     grdMain.Rows[i].Cells[HSnoCol].Value = i + 1; | 
|                 } | 
|                 else | 
|                 { | 
|                     grdMain.Rows[i].Cells[HSnoCol].Value = ""; | 
|                 } | 
|             } | 
|         } | 
|   | 
|         private void cmdDisNo_Click(object sender, EventArgs e) | 
|         { | 
|             DisNo(); | 
|         } | 
|   | 
|   | 
|   | 
|   | 
|     } | 
| } |