Example #1
0
 public void ResetTextChange(Control ctr)
 {
     if (ctr.GetType() == typeof(txtTextBox))
     {
         txtTextBox t = (txtTextBox)ctr;
         t.bTextChange = false;
     }
     if (ctr.GetType() == typeof(txtTextLookup))
     {
         txtTextLookup t = (txtTextLookup)ctr;
         t.bTextChange = false;
     }
     foreach (Control ctrl in ctr.Controls)
     {
         ResetTextChange(ctrl);
     }
 }
Example #2
0
        private void SetBorderTextBox(Control ctr, PaintEventArgs e)
        {
            Color cl = Commons.Common.GetColorBoder();

            foreach (Control ctrl in ctr.Controls)
            {
                if (ctrl.HasChildren)
                {
                    foreach (Control ctrChild in ctrl.Controls)
                    {
                        SetBorderTextBox(ctrChild, e);
                    }
                }
                if (ctrl.GetType() == typeof(txtTextBox))
                {
                    //ctrl.Location.
                    txtTextBox t = (txtTextBox)ctrl;
                    if (t.bRequire)
                    {
                        Graphics  g       = e.Graphics;
                        Rectangle newRect = new Rectangle(ctrl.Location.X - 1, ctrl.Location.Y - 1,
                                                          ctrl.Width + 1, ctrl.Height + 1);
                        g.DrawRectangle(new Pen(cl, 1), newRect);
                    }
                }
                else if (ctrl.GetType() == typeof(txtDateTime))
                {
                    //ctrl.Location.
                    txtDateTime t = (txtDateTime)ctrl;
                    if (t.bRequire)
                    {
                        Graphics  g       = e.Graphics;
                        Rectangle newRect = new Rectangle(ctrl.Location.X - 1, ctrl.Location.Y - 1,
                                                          ctrl.Width + 1, ctrl.Height + 1);
                        g.DrawRectangle(new Pen(cl, 1), newRect);
                    }
                }
            }
        }
Example #3
0
        public virtual void Import_Excel_ODBC()
        {
            txtTextBox     txttemp = new txtTextBox();
            OpenFileDialog ofdlg   = new OpenFileDialog();

            ofdlg.Filter           = "xls files (*.xls)|*.xls";
            ofdlg.RestoreDirectory = true;
            //ofdlg.DefaultExt = "xls";
            //ofdlg.Filter = "*.xls|*.xls|*.xlsx|*.xlsx";

            if (ofdlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            else
            {
                txttemp.Text = ofdlg.FileName;
            }

            //Get Enviroment OS
            //string strPath_OS = @"C:\Windows\SysWow64";
            //string probeConnStr = string.Empty;

//            if (Directory.Exists(strPath_OS)) //Window 64 bit
//            {
//                probeConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;
//						Data Source= " + ofdlg.FileName + ";" +
//                            "Extended Properties=\"Excel 8.0;HDR=YES\"";
//            }
//            else
//            {
//                probeConnStr = @"Provider=Microsoft.Jet.OLEDB.4.0;
//						Data Source= " + ofdlg.FileName + ";" +
//                            "Extended Properties=\"Excel 8.0;HDR=YES\"";
//            }

            string strConnectString =
                "Driver={Microsoft Excel Driver (*.xls)};DBQ=" + txttemp.Text;


            OdbcConnection odbcConn = new OdbcConnection(strConnectString);

            odbcConn.Open();


            OdbcCommand odbcComm = new OdbcCommand();

            odbcComm.Connection = odbcConn;

            try
            {
                OdbcDataAdapter odbcDA;
                DataTable       tbExcel = new DataTable();
                odbcComm.CommandText = "SELECT * FROM [Sheet1$] WHERE 0 = 1" + "Where " + strCode + " IS NOT NULL AND " + strName + " IS NOT NULL";
                odbcDA = new OdbcDataAdapter(odbcComm);

                odbcDA = new OdbcDataAdapter(odbcComm);
                odbcDA.Fill(tbExcel);

                DataTable dtStruct  = DataTool.SQLGetDataTable(strTableName, "TOP 0 * ", " 0 = 1", null);
                DataTable dtStruct2 = dtStruct.Clone();
                DataRow   drNewRow  = dtStruct.NewRow();
                dtStruct.Rows.Add(drNewRow);

                foreach (DataColumn dc in dtStruct2.Columns)
                {
                    if (dc.DataType.ToString() == "System.Byte[]")
                    {
                        dtStruct.Columns.Remove(dc.ColumnName);
                        dtStruct.AcceptChanges();
                    }
                }


                //if (drNewRow.Table.Columns.Contains("Hinh"))
                //{
                //    drNewRow.Table.Columns.Remove("Hinh");
                //    drNewRow.Table.AcceptChanges();
                //}

                Common.SetDefaultDataRow(ref drNewRow);

                string strMsg        = (Element.sysLanguage == enuLanguageType.Vietnamese ? "Bạn có muốn ghi đè lên mẫu tin đã tồn tại không ?" : "Do you want to override exists data ?");
                bool   bIs_Overwrite = Common.MsgYes_No(strMsg);

                foreach (DataRow drExcel in tbExcel.Rows)
                {
                    Common.CopyDataRow(drExcel, drNewRow);
                    drNewRow.AcceptChanges();

                    if (bIs_Overwrite)
                    {
                        DataTool.SQLDelete(strTableName, drNewRow);
                        DataTool.SQLUpdate(enuEdit.New, strTableName, ref drNewRow);
                    }
                    else
                    {
                        if (DataTool.SQLCheckExist(strTableName, strCode, (string)drExcel[strCode]))
                        {
                            continue;
                        }
                        else
                        {
                            DataTool.SQLUpdate(enuEdit.New, strTableName, ref drNewRow);
                        }
                    }

                    //if (bIs_Overwrite && DataTool.SQLCheckExist(strTableName, strCode, (string)drExcel[strCode]))
                    //    DataTool.SQLUpdate(enuEdit.Edit, strTableName, ref drNewRow);
                    //else
                    //    DataTool.SQLUpdate(enuEdit.New, strTableName, ref drNewRow);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Có lỗi khi import file " + ofdlg.FileName + ex.Message);
            }

            Type type = this.GetType();

            type.InvokeMember("FillData", BindingFlags.InvokeMethod, null, this, null);
            Common.MsgOk(Languages.GetLanguage("End_Process"));
        }