Esempio n. 1
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;
            }
        }