public void RefreshSelect()
 {
     try
     {
         string    ID   = DBase.StringReturn(dgv.SelectedRows[0].Cells[colKEYCOL].Value);
         DataTable temp = DHuy.SELECT(TableName, KEYCOL, ID.ToString());
         if (dt != null)
         {
             try
             {
                 DBase.TablePropertyRemove(dt);
                 for (int d = 0; d < dt.Rows.Count; d++)
                 {
                     if (dt.Rows[d][KEYCOL].ToString() == ID.ToString())
                     {
                         dt.Rows[d].ItemArray = temp.Rows[0].ItemArray;
                         break;
                     }
                 }
             }
             catch (Exception ex) { }
         }
     }
     catch (Exception ex) { }
 }
 public void RefreshInsert(string ID)
 {
     try
     {
         DataTable temp = DHuy.SELECT(TableName, KEYCOL, ID.ToString());
         if (dt != null)
         {
             try
             {
                 DBase.TablePropertyRemove(dt);
                 DataRow dr = dt.NewRow();
                 dr.ItemArray = temp.Rows[0].ItemArray;
                 dt.Rows.Add(dr);
             }
             catch (Exception ex) { }
         }
     }
     catch (Exception ex) { }
 }
Beispiel #3
0
        private void CODER_DETAIL_Load(object sender, EventArgs e)
        {
            if (ID != "") // Update
            {
                type = 1; // 0 - insert ; 1 - update
                dt   = DHuy.SELECT(TableName, KEYCOL, ID);
            }
            else
            {
                dt = DHuy.SELECT_NEWROW(TableName);
                foreach (DataColumn dc in dt.Columns)
                {
                    if (dc.ColumnName == "CUSERCODE" || dc.ColumnName == "UUSERCODE")
                    {
                        dt.Rows[0][dc.ColumnName] = DBase.UserCodeLogin;
                    }

                    if (dc.ColumnName == "CREATEDBYAGY" || dc.ColumnName == "UPDATEDBYAGY")
                    {
                        // dt.Rows[0][dc.ColumnName] = DBase.AgencyCodeLogin;
                    }


                    string sqlType = dc.DataType.ToString();
                    if (sqlType == "System.DateTime")
                    {
                        dt.Rows[0][dc.ColumnName] = DBase.DatetimeReturn_NowIfNull(dt.Columns[dc.ColumnName]);
                    }
                }
            }

            foreach (Control C in this.Controls)
            {
                if (!C.Name.Contains("edt"))
                {
                    continue;
                }
                String ColName = C.Name.Replace("edt", "");
                string sqlType = dt.Rows[0][ColName].GetType().ToString();

                if (sqlType == "System.DateTime")
                {
                    DateTimePicker D = (DateTimePicker)C;
                    D.Value = DBase.DatetimeReturn(dt.Rows[0][C.Name.Replace("edt", "")]);
                }
                else
                {
//                        if (C.GetType() == typeof(TextPopup))
//                        {
//                            TextPopup T = (TextPopup)C;
//                            T.StopEvent();
//                            T.Text = DBase.StringReturn(dt.Rows[0][C.Name.Replace("edt", "")]);
//                            T.StartEvent();
//                        }
                    if (C.GetType() == typeof(ComboBox))
                    {
                        ComboBox T = (ComboBox)C;
                        T.Text = DBase.StringReturn(dt.Rows[0][C.Name.Replace("edt", "")]);
                    }

                    else if (C.GetType() == typeof(CheckBox))
                    {
                        CheckBox T = (CheckBox)C;
                        T.Checked = DBase.BoolReturn(dt.Rows[0][C.Name.Replace("edt", "")]);
                    }


                    else if (C.GetType() == typeof(PictureBox))
                    {
                        PictureBox T = (PictureBox)C;
                        T.Click += new System.EventHandler(this.edtIMAGE_Click);
                        try
                        {
                            System.IO.MemoryStream ms = new System.IO.MemoryStream((Byte[])(dt.Rows[0][C.Name.Replace("edt", "")]));
                            T.Image = Image.FromStream(ms);
                            //  ms.Dispose();
                        }
                        catch (Exception ex) { }
                    }

                    else
                    {
                        C.Text = DBase.StringReturn(dt.Rows[0][C.Name.Replace("edt", "")]);
                    }
                }
            }
            //Asign Value Change Event
            foreach (Control C in this.Controls)
            {
                C.TextChanged += new System.EventHandler(this.TextChange);
            }

            //Asign Checkchange Event
            foreach (Control C in this.Controls)
            {
                if (C.GetType() == typeof(CheckBox))
                {
                    ((CheckBox)C).CheckedChanged += new System.EventHandler(this.CheckedChanged);
                }
            }

            //Remove Readonly
            foreach (DataColumn col in dt.Columns)
            {
                col.ReadOnly = false;
            }
        }