Пример #1
0
        private void CheckHD(dgvControl dgvPermission, string strColumnName, int beg, int end)
        {
            if (beg > end)
            {
                int temp = beg;
                beg = end;
                end = temp;
            }
            else
            {
                beg = beg + 1;
            }

            //DataTable dt = dgvPermission.DataSource as DataTable;
            for (int i = beg; i <= end; i++)
            {
                dgvPermission.Rows[i].Cells[strColumnName].Value = !(bool)dgvPermission.Rows[i].Cells[strColumnName].Value;

                if (Common.CheckPermission("PERMISSION", enuPermission_Type.Allow_Access) || Epoint.Systems.Elements.Element.sysIs_Admin)
                {
                    //drCurrent = dtPermission.Rows[i];
                    drCurrent = ((DataRowView)bdsPermission.Current).Row;
                    drCurrent.AcceptChanges();

                    bool bAllow_View   = (bool)drCurrent["ALLOW_VIEW"],
                         bAllow_Access = (bool)drCurrent["ALLOW_ACCESS"],
                         bAllow_New    = (bool)drCurrent["ALLOW_NEW"],
                         bAllow_Edit   = (bool)drCurrent["ALLOW_EDIT"],
                         bAllow_Delete = (bool)drCurrent["ALLOW_DELETE"],
                         bAllow_Duyet  = (bool)drCurrent["ALLOW_DUYET"];

                    bool bDeny_View   = (bool)drCurrent["DENY_VIEW"],
                         bDeny_Access = (bool)drCurrent["DENY_ACCESS"],
                         bDeny_New    = (bool)drCurrent["DENY_NEW"],
                         bDeny_Edit   = (bool)drCurrent["DENY_EDIT"],
                         bDeny_Delete = (bool)drCurrent["DENY_DELETE"];

                    string strSQLExec;
                    int    iIdent00;

                    Hashtable htPara = new Hashtable();
                    htPara.Add("MEMBER_ID", strMember_ID);
                    htPara.Add("OBJECT_ID", (string)drCurrent["Object_ID"]);
                    htPara.Add("ALLOW_VIEW", bAllow_View);
                    htPara.Add("ALLOW_ACCESS", bAllow_Access);
                    htPara.Add("ALLOW_NEW", bAllow_New);
                    htPara.Add("ALLOW_EDIT", bAllow_Edit);
                    htPara.Add("ALLOW_DELETE", bAllow_Delete);
                    htPara.Add("ALLOW_DUYET", bAllow_Delete);

                    if (drCurrent["Ident00"] == DBNull.Value || Convert.ToInt32(drCurrent["Ident00"]) == 0) //Chưa tồn tại
                    {
                        strSQLExec = @"INSERT INTO SYSPERMISSION (Member_ID, Object_ID, Allow_View, Allow_Access, Allow_New, Allow_Edit, Allow_Delete, Allow_Duyet) 
										VALUES (@Member_ID, @Object_ID, @Allow_View, @Allow_Access, @Allow_New, @Allow_Edit, @Allow_Delete, @Allow_Duyet) 
									SELECT @@IDENTITY"                                    ;

                        iIdent00 = Convert.ToInt32(SQLExec.ExecuteReturnValue(strSQLExec, htPara, CommandType.Text));

                        if (iIdent00 != 0)
                        {
                            drCurrent["Allow_View"]   = bAllow_View; //Allow
                            drCurrent["Allow_Access"] = bAllow_Access;
                            drCurrent["Allow_New"]    = bAllow_New;
                            drCurrent["Allow_Edit"]   = bAllow_Edit;
                            drCurrent["Allow_Delete"] = bAllow_Delete;
                            drCurrent["Allow_Duyet"]  = bAllow_Duyet;
                            drCurrent["Deny_View"]    = bDeny_View; //Deny
                            drCurrent["Deny_Access"]  = bDeny_Access;
                            drCurrent["Deny_New"]     = bDeny_New;
                            drCurrent["Deny_Edit"]    = bDeny_Edit;
                            drCurrent["Deny_Delete"]  = bDeny_Delete;
                            drCurrent["Ident00"]      = iIdent00;
                        }
                    }
                    else //Đã tồn tại
                    {
                        htPara.Add("IDENT00", Convert.ToInt32(drCurrent["Ident00"]));
                        strSQLExec = @"UPDATE SYSPERMISSION SET Allow_View = @Allow_View, Allow_Access = @Allow_Access, Allow_New = @Allow_New, Allow_Edit = @Allow_Edit, Allow_Delete = @Allow, Allow_Duyet = @Allow_Duyet WHERE Ident00 = @Ident00";

                        if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                        {
                            drCurrent["Allow_View"]   = bAllow_View; //Allow
                            drCurrent["Allow_Access"] = bAllow_Access;
                            drCurrent["Allow_New"]    = bAllow_New;
                            drCurrent["Allow_Edit"]   = bAllow_Edit;
                            drCurrent["Allow_Delete"] = bAllow_Delete;
                            drCurrent["Allow_Duyet"]  = bAllow_Duyet;
                            drCurrent["Deny_View"]    = bDeny_View; //Deny
                            drCurrent["Deny_Access"]  = bDeny_Access;
                            drCurrent["Deny_New"]     = bDeny_New;
                            drCurrent["Deny_Edit"]    = bDeny_Edit;
                            drCurrent["Deny_Delete"]  = bDeny_Delete;
                        }
                    }

                    //Nếu check [Allow] và [Deny] bị gỡ ra toàn bộ -> Thì xóa hẳn khỏi SYSPERMISSION
                    if (drCurrent["Ident00"] != DBNull.Value && Convert.ToInt32(drCurrent["Ident00"]) != 0)
                    {
                        bool bUncheckAll = true;

                        if (dgvPermission.Columns.Contains("Allow_View") && dgvPermission.Columns["Allow_View"].Visible && ((bool)drCurrent["Allow_View"] || (bool)drCurrent["Deny_View"]))
                        {
                            bUncheckAll = false;
                        }
                        if (dgvPermission.Columns.Contains("Allow_Access") && dgvPermission.Columns["Allow_Access"].Visible && ((bool)drCurrent["Allow_Access"] || (bool)drCurrent["Deny_Access"]))
                        {
                            bUncheckAll = false;
                        }
                        if (dgvPermission.Columns.Contains("Allow_New") && dgvPermission.Columns["Allow_New"].Visible && ((bool)drCurrent["Allow_New"] || (bool)drCurrent["Deny_New"]))
                        {
                            bUncheckAll = false;
                        }
                        if (dgvPermission.Columns.Contains("Allow_Edit") && dgvPermission.Columns["Allow_Edit"].Visible && ((bool)drCurrent["Allow_Edit"] || (bool)drCurrent["Deny_Edit"]))
                        {
                            bUncheckAll = false;
                        }
                        if (dgvPermission.Columns.Contains("Allow_Delete") && dgvPermission.Columns["Allow_Delete"].Visible && ((bool)drCurrent["Allow_Delete"] || (bool)drCurrent["Deny_Delete"]))
                        {
                            bUncheckAll = false;
                        }

                        if (bUncheckAll)
                        {
                            if (SQLExec.Execute("DELETE FROM SYSPERMISSION WHERE Ident00 = " + drCurrent["Ident00"].ToString().Trim()))
                            {
                                drCurrent["Ident00"] = 0;
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        void dgvPermission_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return;
            }

            //string strColumnName = dgvPermission.Columns[e.ColumnIndex].Name;
            ///////////////////////////////
            DataGridViewCell dgvCell       = ((dgvControl)sender).CurrentCell;
            string           strColumnName = dgvCell.OwningColumn.Name.ToUpper();

            if (strColumnName == "ALLOW_ALL")
            {
                if (Common.CheckPermission("PERMISSION", enuPermission_Type.Allow_Access) || Epoint.Systems.Elements.Element.sysIs_Admin)
                {
                    drCurrent = ((DataRowView)bdsPermission.Current).Row;
                    drCurrent[strColumnName] = !(bool)drCurrent[strColumnName];
                    drCurrent.AcceptChanges();

                    drCurrent["ALLOW_VIEW"]   = drCurrent["ALLOW_ALL"];
                    drCurrent["ALLOW_ACCESS"] = drCurrent["ALLOW_ALL"];
                    drCurrent["ALLOW_NEW"]    = drCurrent["ALLOW_ALL"];
                    drCurrent["ALLOW_EDIT"]   = drCurrent["ALLOW_ALL"];
                    drCurrent["ALLOW_DELETE"] = drCurrent["ALLOW_ALL"];
                    drCurrent["ALLOW_DUYET"]  = drCurrent["ALLOW_ALL"];
                    drCurrent.AcceptChanges();

                    bool bAllow_View   = (bool)drCurrent["ALLOW_VIEW"],
                         bAllow_Access = (bool)drCurrent["ALLOW_ACCESS"],
                         bAllow_New    = (bool)drCurrent["ALLOW_NEW"],
                         bAllow_Edit   = (bool)drCurrent["ALLOW_EDIT"],
                         bAllow_Delete = (bool)drCurrent["ALLOW_DELETE"],
                         bAllow_Duyet  = (bool)drCurrent["ALLOW_DUYET"];

                    bool bDeny_View   = (bool)drCurrent["DENY_VIEW"],
                         bDeny_Access = (bool)drCurrent["DENY_ACCESS"],
                         bDeny_New    = (bool)drCurrent["DENY_NEW"],
                         bDeny_Edit   = (bool)drCurrent["DENY_EDIT"],
                         bDeny_Delete = (bool)drCurrent["DENY_DELETE"];

                    string strSQLExec;
                    int    iIdent00;

                    Hashtable htPara = new Hashtable();
                    htPara.Add("MEMBER_ID", strMember_ID);
                    htPara.Add("OBJECT_ID", (string)drCurrent["Object_ID"]);
                    htPara.Add("ALLOW_VIEW", bAllow_View);
                    htPara.Add("ALLOW_ACCESS", bAllow_Access);
                    htPara.Add("ALLOW_NEW", bAllow_New);
                    htPara.Add("ALLOW_EDIT", bAllow_Edit);
                    htPara.Add("ALLOW_DELETE", bAllow_Delete);
                    htPara.Add("ALLOW_DUYET", bAllow_Duyet);

                    if (drCurrent["Ident00"] == DBNull.Value || Convert.ToInt32(drCurrent["Ident00"]) == 0) //Chưa tồn tại
                    {
                        strSQLExec = @"INSERT INTO SYSPERMISSION (Member_ID, Object_ID, Allow_View, Allow_Access, Allow_New, Allow_Edit, Allow_Delete, Allow_Duyet) 
										VALUES (@Member_ID, @Object_ID, @Allow_View, @Allow_Access, @Allow_New, @Allow_Edit, @Allow_Delete, @Allow_Duyet) 
									SELECT @@IDENTITY"                                    ;

                        iIdent00 = Convert.ToInt32(SQLExec.ExecuteReturnValue(strSQLExec, htPara, CommandType.Text));

                        if (iIdent00 != 0)
                        {
                            drCurrent["Allow_View"]   = bAllow_View; //Allow
                            drCurrent["Allow_Access"] = bAllow_Access;
                            drCurrent["Allow_New"]    = bAllow_New;
                            drCurrent["Allow_Edit"]   = bAllow_Edit;
                            drCurrent["Allow_Delete"] = bAllow_Delete;
                            drCurrent["Allow_Duyet"]  = bAllow_Duyet;
                            drCurrent["Deny_View"]    = bDeny_View; //Deny
                            drCurrent["Deny_Access"]  = bDeny_Access;
                            drCurrent["Deny_New"]     = bDeny_New;
                            drCurrent["Deny_Edit"]    = bDeny_Edit;
                            drCurrent["Deny_Delete"]  = bDeny_Delete;
                            drCurrent["Ident00"]      = iIdent00;
                        }
                    }
                    else //Đã tồn tại
                    {
                        htPara.Add("IDENT00", Convert.ToInt32(drCurrent["Ident00"]));
                        strSQLExec = @"UPDATE SYSPERMISSION SET Allow_View = @Allow_View, Allow_Access = @Allow_Access, Allow_New = @Allow_New, Allow_Edit = @Allow_Edit, Allow_Delete = @Allow_Delete, Allow_Duyet = @Allow_Duyet WHERE Ident00 = @Ident00";

                        if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                        {
                            drCurrent["Allow_View"]   = bAllow_View; //Allow
                            drCurrent["Allow_Access"] = bAllow_Access;
                            drCurrent["Allow_New"]    = bAllow_New;
                            drCurrent["Allow_Edit"]   = bAllow_Edit;
                            drCurrent["Allow_Delete"] = bAllow_Delete;
                            drCurrent["Allow_Duyet"]  = bAllow_Duyet;
                            drCurrent["Deny_View"]    = bDeny_View; //Deny
                            drCurrent["Deny_Access"]  = bDeny_Access;
                            drCurrent["Deny_New"]     = bDeny_New;
                            drCurrent["Deny_Edit"]    = bDeny_Edit;
                            drCurrent["Deny_Delete"]  = bDeny_Delete;
                        }
                    }

                    //Nếu check [Allow] và [Deny] bị gỡ ra toàn bộ -> Thì xóa hẳn khỏi SYSPERMISSION
                    if (drCurrent["Ident00"] != DBNull.Value && Convert.ToInt32(drCurrent["Ident00"]) != 0)
                    {
                        bool bUncheckAll = true;

                        if (dgvPermission.Columns.Contains("Allow_View") && dgvPermission.Columns["Allow_View"].Visible && ((bool)drCurrent["Allow_View"] || (bool)drCurrent["Deny_View"]))
                        {
                            bUncheckAll = false;
                        }
                        if (dgvPermission.Columns.Contains("Allow_Access") && dgvPermission.Columns["Allow_Access"].Visible && ((bool)drCurrent["Allow_Access"] || (bool)drCurrent["Deny_Access"]))
                        {
                            bUncheckAll = false;
                        }
                        if (dgvPermission.Columns.Contains("Allow_New") && dgvPermission.Columns["Allow_New"].Visible && ((bool)drCurrent["Allow_New"] || (bool)drCurrent["Deny_New"]))
                        {
                            bUncheckAll = false;
                        }
                        if (dgvPermission.Columns.Contains("Allow_Edit") && dgvPermission.Columns["Allow_Edit"].Visible && ((bool)drCurrent["Allow_Edit"] || (bool)drCurrent["Deny_Edit"]))
                        {
                            bUncheckAll = false;
                        }
                        if (dgvPermission.Columns.Contains("Allow_Delete") && dgvPermission.Columns["Allow_Delete"].Visible && ((bool)drCurrent["Allow_Delete"] || (bool)drCurrent["Deny_Delete"]))
                        {
                            bUncheckAll = false;
                        }

                        if (bUncheckAll)
                        {
                            if (SQLExec.Execute("DELETE FROM SYSPERMISSION WHERE Ident00 = " + drCurrent["Ident00"].ToString().Trim()))
                            {
                                drCurrent["Ident00"] = 0;
                            }
                        }
                    }
                }
            }


            if (!Common.Inlist(strColumnName, "ALLOW_VIEW,ALLOW_ACCESS,ALLOW_NEW,ALLOW_EDIT,ALLOW_DELETE,ALLOW_DUYET,DENY_VIEW,DENY_ACCESS,DENY_NEW,DENY_EDIT,DENY_DELETE"))
            {
                return;
            }


            if (!bCheckKey)
            {
                iBeginRow = dgvPermission.CurrentRow.Index;
            }
            else
            {
                if (iBeginRow == -1)
                {
                    iBeginRow = dgvPermission.CurrentRow.Index;
                }
                else
                {
                    iEndRow = dgvPermission.CurrentRow.Index;
                }
                CheckHD(dgvPermission, strColumnName, iBeginRow, iEndRow);
                iBeginRow = iEndRow;
            }

            //////////////////////////////////
            if (bCheckKey)
            {
                return;
            }

            if (Common.CheckPermission("PERMISSION", enuPermission_Type.Allow_Access) || Epoint.Systems.Elements.Element.sysIs_Admin)
            {
                drCurrent = ((DataRowView)bdsPermission.Current).Row;
                drCurrent.AcceptChanges();

                bool bAllow_View   = (bool)drCurrent["ALLOW_VIEW"],
                     bAllow_Access = (bool)drCurrent["ALLOW_ACCESS"],
                     bAllow_New    = (bool)drCurrent["ALLOW_NEW"],
                     bAllow_Edit   = (bool)drCurrent["ALLOW_EDIT"],
                     bAllow_Delete = (bool)drCurrent["ALLOW_DELETE"],
                     bAllow_Duyet  = (bool)drCurrent["ALLOW_DUYET"];

                bool bDeny_View   = (bool)drCurrent["DENY_VIEW"],
                     bDeny_Access = (bool)drCurrent["DENY_ACCESS"],
                     bDeny_New    = (bool)drCurrent["DENY_NEW"],
                     bDeny_Edit   = (bool)drCurrent["DENY_EDIT"],
                     bDeny_Delete = (bool)drCurrent["DENY_DELETE"];

                if (strColumnName == "ALLOW_VIEW") //Allow
                {
                    bAllow_View = !(bool)drCurrent[strColumnName];
                }
                else if (strColumnName == "ALLOW_ACCESS")
                {
                    bAllow_Access = !(bool)drCurrent[strColumnName];
                }
                else if (strColumnName == "ALLOW_NEW")
                {
                    bAllow_New = !(bool)drCurrent[strColumnName];
                }
                else if (strColumnName == "ALLOW_EDIT")
                {
                    bAllow_Edit = !(bool)drCurrent[strColumnName];
                }
                else if (strColumnName == "ALLOW_DELETE")
                {
                    bAllow_Delete = !(bool)drCurrent[strColumnName];
                }
                else if (strColumnName == "ALLOW_DUYET")
                {
                    bAllow_Duyet = !(bool)drCurrent[strColumnName];
                }
                else if (strColumnName == "DENY_VIEW") //Deny: Allow luôn ngược với Deny
                {
                    bDeny_View = !(bool)drCurrent[strColumnName];
                }
                else if (strColumnName == "DENY_ACCESS")
                {
                    bDeny_Access = !(bool)drCurrent[strColumnName];
                }
                else if (strColumnName == "DENY_NEW")
                {
                    bDeny_New = !(bool)drCurrent[strColumnName];
                }
                else if (strColumnName == "DENY_EDIT")
                {
                    bDeny_Edit = !(bool)drCurrent[strColumnName];
                }
                else if (strColumnName == "DENY_DELETE")
                {
                    bDeny_Delete = !(bool)drCurrent[strColumnName];
                }

                string strSQLExec;
                int    iIdent00;

                Hashtable htPara = new Hashtable();
                htPara.Add("MEMBER_ID", strMember_ID);
                htPara.Add("OBJECT_ID", (string)drCurrent["Object_ID"]);
                htPara.Add("ALLOW_VIEW", bAllow_View);
                htPara.Add("ALLOW_ACCESS", bAllow_Access);
                htPara.Add("ALLOW_NEW", bAllow_New);
                htPara.Add("ALLOW_EDIT", bAllow_Edit);
                htPara.Add("ALLOW_DELETE", bAllow_Delete);
                htPara.Add("ALLOW_DUYET", bAllow_Duyet);

                if (drCurrent["Ident00"] == DBNull.Value || Convert.ToInt32(drCurrent["Ident00"]) == 0) //Chưa tồn tại
                {
                    strSQLExec = @"INSERT INTO SYSPERMISSION (Member_ID, Object_ID, Allow_View, Allow_Access, Allow_New, Allow_Edit, Allow_Delete, Allow_Duyet) 
										VALUES (@Member_ID, @Object_ID, @Allow_View, @Allow_Access, @Allow_New, @Allow_Edit, @Allow_Delete, @Allow_Duyet) 
									SELECT @@IDENTITY"                                    ;

                    iIdent00 = Convert.ToInt32(SQLExec.ExecuteReturnValue(strSQLExec, htPara, CommandType.Text));

                    if (iIdent00 != 0)
                    {
                        drCurrent["Allow_View"]   = bAllow_View; //Allow
                        drCurrent["Allow_Access"] = bAllow_Access;
                        drCurrent["Allow_New"]    = bAllow_New;
                        drCurrent["Allow_Edit"]   = bAllow_Edit;
                        drCurrent["Allow_Delete"] = bAllow_Delete;
                        drCurrent["Allow_Duyet"]  = bAllow_Duyet;
                        drCurrent["Deny_View"]    = bDeny_View; //Deny
                        drCurrent["Deny_Access"]  = bDeny_Access;
                        drCurrent["Deny_New"]     = bDeny_New;
                        drCurrent["Deny_Edit"]    = bDeny_Edit;
                        drCurrent["Deny_Delete"]  = bDeny_Delete;
                        drCurrent["Ident00"]      = iIdent00;
                    }
                }
                else //Đã tồn tại
                {
                    htPara.Add("IDENT00", Convert.ToInt32(drCurrent["Ident00"]));
                    strSQLExec = @"UPDATE SYSPERMISSION SET Allow_View = @Allow_View, Allow_Access = @Allow_Access, Allow_New = @Allow_New, Allow_Edit = @Allow_Edit, Allow_Delete = @Allow_Delete, Allow_Duyet = @Allow_Duyet WHERE Ident00 = @Ident00";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drCurrent["Allow_View"]   = bAllow_View; //Allow
                        drCurrent["Allow_Access"] = bAllow_Access;
                        drCurrent["Allow_New"]    = bAllow_New;
                        drCurrent["Allow_Edit"]   = bAllow_Edit;
                        drCurrent["Allow_Delete"] = bAllow_Delete;
                        drCurrent["Allow_Duyet"]  = bAllow_Duyet;
                        drCurrent["Deny_View"]    = bDeny_View; //Deny
                        drCurrent["Deny_Access"]  = bDeny_Access;
                        drCurrent["Deny_New"]     = bDeny_New;
                        drCurrent["Deny_Edit"]    = bDeny_Edit;
                        drCurrent["Deny_Delete"]  = bDeny_Delete;
                    }
                }

                //Nếu check [Allow] và [Deny] bị gỡ ra toàn bộ -> Thì xóa hẳn khỏi SYSPERMISSION
                if (drCurrent["Ident00"] != DBNull.Value && Convert.ToInt32(drCurrent["Ident00"]) != 0)
                {
                    bool bUncheckAll = true;

                    if (dgvPermission.Columns.Contains("Allow_View") && dgvPermission.Columns["Allow_View"].Visible && ((bool)drCurrent["Allow_View"] || (bool)drCurrent["Deny_View"]))
                    {
                        bUncheckAll = false;
                    }
                    if (dgvPermission.Columns.Contains("Allow_Access") && dgvPermission.Columns["Allow_Access"].Visible && ((bool)drCurrent["Allow_Access"] || (bool)drCurrent["Deny_Access"]))
                    {
                        bUncheckAll = false;
                    }
                    if (dgvPermission.Columns.Contains("Allow_New") && dgvPermission.Columns["Allow_New"].Visible && ((bool)drCurrent["Allow_New"] || (bool)drCurrent["Deny_New"]))
                    {
                        bUncheckAll = false;
                    }
                    if (dgvPermission.Columns.Contains("Allow_Edit") && dgvPermission.Columns["Allow_Edit"].Visible && ((bool)drCurrent["Allow_Edit"] || (bool)drCurrent["Deny_Edit"]))
                    {
                        bUncheckAll = false;
                    }
                    if (dgvPermission.Columns.Contains("Allow_Delete") && dgvPermission.Columns["Allow_Delete"].Visible && ((bool)drCurrent["Allow_Delete"] || (bool)drCurrent["Deny_Delete"]))
                    {
                        bUncheckAll = false;
                    }

                    if (bUncheckAll)
                    {
                        if (SQLExec.Execute("DELETE FROM SYSPERMISSION WHERE Ident00 = " + drCurrent["Ident00"].ToString().Trim()))
                        {
                            drCurrent["Ident00"] = 0;
                        }
                    }
                }
            }
        }
Пример #3
0
        public static void Import_Excel(string strTableName)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter           = "xls files (*.xls;*.xlsx)|*.xls;*.xlsx";
            dialog.RestoreDirectory = true;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                String strConnectString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                                          "Data Source=" + dialog.FileName + ";Extended Properties=Excel 8.0;";

                int num = 0;
                using (OleDbConnection connection = new OleDbConnection(strConnectString))
                {
                    connection.Open();

                    string selectCommandText = "SELECT * FROM [Sheet1$] Where Ma_Vt IS NOT NULL ";

                    using (OleDbDataAdapter oleDbDapter = new OleDbDataAdapter(selectCommandText, connection))
                    {
                        DataTable dataTable = new DataTable();
                        oleDbDapter.Fill(dataTable);
                        DataTable table2 = DataTool.SQLGetDataTable(strTableName, "TOP 0 * ", " 0 = 1", null);
                        DataTable table3 = table2.Clone();
                        DataRow   row    = table2.NewRow();
                        table2.Rows.Add(row);
                        Common.SetDefaultDataRow(ref row);
                        bool flag  = false;
                        bool flag2 = false;
                        foreach (DataRow row2 in dataTable.Rows)
                        {
                            Common.CopyDataRow(row2, row);
                            row.AcceptChanges();
                            row["Stt"] = Common.GetNewStt("08", true);
                            if (DataTool.SQLCheckExist(strTableName, new string[] { "Ma_DvCs", "Ma_Kho", "Ma_Vt" }, new object[] { Element.sysMa_DvCs, row["Ma_Kho"], row["Ma_Vt"] }))
                            {
                                if (!flag)
                                {
                                    string strMsg = (Element.sysLanguage == enuLanguageType.Vietnamese) ? "Bạn có ghi đè dữ liệu đã tồn tại ?" : "Do you want to override exists data ?";
                                    flag2 = Common.MsgYes_No(strMsg);
                                    flag  = true;
                                }
                                if (flag2)
                                {
                                    if (row.Table.Columns.Contains("Ident00"))
                                    {
                                        DataRow row3 = SQLExec.ExecuteReturnDt("SELECT * FROM " + strTableName + " WHERE Ma_DvCs = '" + Element.sysMa_DvCs + "' AND Ma_Kho = '" + row["Ma_Kho"].ToString() + "' AND Ma_Vt = '" + row["Ma_Vt"].ToString() + "'").Rows[0];
                                        if (row != null)
                                        {
                                            row["Ident00"] = row3["Ident00"];
                                        }
                                    }
                                    DataTool.SQLUpdate(enuEdit.Edit, strTableName, ref row);
                                    num++;
                                }
                            }
                            else
                            {
                                DataTool.SQLUpdate(enuEdit.New, strTableName, ref row);
                                num++;
                            }
                        }
                    }
                }

                SQLExec.Execute("update " + strTableName + " set Ma_Kho = RTRIM(LTRIM(Ma_Kho)) , Ma_Vt = RTRIM(LTRIM(Ma_Vt))");


                Common.MsgOk(Languages.GetLanguage("End_Process") + " " + num.ToString() + " dòng được cập nhật");
            }
        }
Пример #4
0
        public static bool Print(DataRow drPhView, bool bPreview, bool bShowDialog, ref bool bInVisibleNextPrint, ref string strReport_File_First)
        {
            string strStt               = (string)drPhView["Stt"];
            string strMa_Ct             = (string)drPhView["Ma_Ct"];
            string strMa_Tte            = "VND";// (string)drPhView["Ma_Tte"];
            string strReportTag         = string.Empty;
            string strTable_Ph          = string.Empty;
            string strTable_Ct          = string.Empty;
            bool   bIs_Vnd              = true;
            string strReport_File       = string.Empty;
            bool   bInVisibleNextPrint0 = false;
            bool   bIs_Doc_Tien1        = false;
            int    iSo_Lien             = 1;

            DataRow   drDmCt = DataTool.SQLGetDataRowByID("SYSDMCT", "Ma_Ct", strMa_Ct);
            DataTable dtHeader;
            DataTable dtDetail;

            strTable_Ph    = (string)drDmCt["Table_Ph"];
            strTable_Ct    = (string)drDmCt["Table_Ct"];
            strReport_File = (string)drDmCt["Report_File"];

            if (strMa_Ct == "BN" && !bInVisibleNextPrint)
            {
                DataRow drCtTien = DataTool.SQLGetDataRowByID(strTable_Ct, "Stt", strStt);

                if (!drPhView.Table.Columns.Contains("TK_NH"))
                {
                    drPhView.Table.Columns.Add("TK_NH", typeof(string));
                }

                drPhView["Tk_Nh"] = (string)drCtTien["Tk_Co"];

                frmIn_CT_UNC frm = new frmIn_CT_UNC();

                if (strMa_Tte != Element.sysMa_Tte)
                {
                    frm.rdbTien_Nt.Checked = true;
                }

                frm.Load(drPhView);

                if (!frm.isAccept)
                {
                    return(false);
                }

                bInVisibleNextPrint0 = frm.chkInVisibleNextPrint.Checked;
                bIs_Vnd = frm.rdbTien_VND.Checked;

                strReport_File = frm.cboMau_In.SelectedValue.ToString();
                iSo_Lien       = frm.iSo_Lien;
            }
            else
            {
                //In thông tin chữ ký
                string strName1 = string.Empty;
                string strName2 = string.Empty;
                string strName3 = string.Empty;
                string strName4 = string.Empty;
                string strName5 = string.Empty;

                string    strKey = "Ma_Dvcs = '" + Element.sysMa_DvCs + "'" + " AND Ma_Ct = '" + strMa_Ct + "'";
                DataTable dtDmCk = DataTool.SQLGetDataTable("SYSDMCK", "*", strKey, "Ma_Ct");
                if (dtDmCk != null)
                {
                    foreach (DataRow drDmCk in dtDmCk.Rows)
                    {
                        strName1 = drDmCk["Name1"].ToString();
                        strName2 = drDmCk["Name2"].ToString();
                        strName3 = drDmCk["Name3"].ToString();
                        strName4 = drDmCk["Name4"].ToString();
                        strName5 = drDmCk["Name5"].ToString();
                    }
                }

                //Cập nhật thông tin chữ ký xuống GLVOUCHER

                string strSQLUpdate = "UPDATE " + strTable_Ph + " SET " +
                                      @"Chu_Ky_1 = @Chu_Ky_1, Chu_Ky_2 = @Chu_Ky_2, Chu_Ky_3 = @Chu_Ky_3, Chu_Ky_4 = @Chu_Ky_4, Chu_Ky_5 = @Chu_Ky_5" +
                                      " WHERE Stt = @Stt";

                Hashtable htChuKy = new Hashtable();
                htChuKy["CHU_KY_1"] = strName1;
                htChuKy["CHU_KY_2"] = strName2;
                htChuKy["CHU_KY_3"] = strName3;
                htChuKy["CHU_KY_4"] = strName4;
                htChuKy["CHU_KY_5"] = strName5;
                htChuKy["STT"]      = strStt;

                SQLExec.Execute(strSQLUpdate, htChuKy, CommandType.Text);

                //In Tien_Nt
                if (strMa_Tte != Element.sysMa_Tte)
                {
                    frmIn_CT_Tien_NT frm = new frmIn_CT_Tien_NT();
                    frm.Load(drPhView);

                    if (!frm.isAccept)
                    {
                        return(false);
                    }

                    bIs_Vnd = frm.rdbTien_VND.Checked;
                }
            }

            //Chon nhieu mau report khi in
            DataTable dtDmMauIn = DataTool.SQLGetDataTable("SYSDMMAUCT", "Ma_Mau, Ten_Mau", "Ma_Ct = '" + strMa_Ct + "'", "Ma_Mau");

            if (dtDmMauIn.Rows.Count == 1)
            {
                strReport_File = (string)dtDmMauIn.Rows[0]["Ma_Mau"];
            }
            else if (strMa_Ct != "BN" && dtDmMauIn.Rows.Count > 1 && !bInVisibleNextPrint)
            {
                if (strMa_Ct == "PC" || strMa_Ct == "PT")
                {
                    frmIn_Ct_Khac frmInHD = new frmIn_Ct_Khac();
                    frmInHD.strMa_Ct  = strMa_Ct;
                    frmInHD.Is_Design = false;
                    frmInHD.Load(drPhView);

                    strReport_File       = frmInHD.cboMau_In.SelectedValue.ToString();
                    iSo_Lien             = frmInHD.iSo_Lien;
                    bInVisibleNextPrint0 = frmInHD.chkInVisibleNextPrint.Checked;
                    bIs_Doc_Tien1        = frmInHD.chkIs_Doc_Tien1.Checked;
                    if (!frmInHD.Is_Design)
                    {
                        return(false);
                    }
                }
                else
                {
                    frmIn_Ct_HD frmInHD = new frmIn_Ct_HD();
                    frmInHD.strMa_Ct  = strMa_Ct;
                    frmInHD.Is_Design = false;
                    frmInHD.Load(drPhView);

                    strReport_File       = frmInHD.cboMau_In.SelectedValue.ToString();
                    iSo_Lien             = frmInHD.iSo_Lien;
                    bInVisibleNextPrint0 = frmInHD.chkInVisibleNextPrint.Checked;

                    if (!frmInHD.Is_Design)
                    {
                        return(false);
                    }
                }
            }
            string strMau_So = string.Empty;

            if (drPhView.Table.Columns.Contains("Mau_So"))
            {
                strMau_So = (string)drPhView["Mau_So"];
            }

            Hashtable ht = new Hashtable();

            ht.Add("STT", strStt);
            ht.Add("MA_CT", strMa_Ct);
            ht.Add("IS_VND", bIs_Vnd ? 1 : 0);
            ht.Add("LANGUAGE_TYPE", (char)Element.sysLanguage);

            DataSet dsPrintVoucher = SQLExec.ExecuteReturnDs("sp_PrintVoucher", ht, CommandType.StoredProcedure);

            //Upadte Gia = 0, Tien = 0, TTien = 0 khi in chung tu doi voi User cam ACCESS_PRICE
            DataTable dtPrinVoucherHeader = new DataTable();
            DataTable dtPrinVoucherDetail = new DataTable();

            dtPrinVoucherHeader = dsPrintVoucher.Tables[0];
            dtPrinVoucherDetail = dsPrintVoucher.Tables[1];
            if (DataTool.SQLCheckExist("SYSOBJECT", "Object_ID", "ACCESS_PRICE") && !Common.CheckPermission("ACCESS_PRICE", enuPermission_Type.Allow_Access))
            {
                foreach (DataColumn dc in dtPrinVoucherHeader.Columns)
                {
                    if (dc.ColumnName.StartsWith("GIA") || dc.ColumnName.StartsWith("TIEN") || dc.ColumnName.StartsWith("TTIEN") || dc.ColumnName.StartsWith("PS_NO") || dc.ColumnName.StartsWith("PS_CO") || dc.ColumnName.StartsWith("PS_TANG") || dc.ColumnName.StartsWith("PS_GIAM") || dc.ColumnName.StartsWith("DU_DAU") || dc.ColumnName.StartsWith("DU_CUOI") || dc.ColumnName.StartsWith("DU_NO") || dc.ColumnName.StartsWith("DU_CO"))
                    {
                        if (dc.DataType == typeof(double) || dc.DataType == typeof(decimal))
                        {
                            //Gán cột dữ liệu về 0
                            foreach (DataRow dr in dtPrinVoucherHeader.Rows)
                            {
                                dr[dc] = 0;
                            }
                        }
                        if (dc.DataType == typeof(string))
                        {
                            //Gán cột dữ liệu về rổng
                            foreach (DataRow dr in dtPrinVoucherHeader.Rows)
                            {
                                dr[dc] = "";
                            }
                        }
                    }
                }
                foreach (DataColumn dc in dtPrinVoucherDetail.Columns)
                {
                    if (dc.ColumnName.StartsWith("GIA") || dc.ColumnName.StartsWith("TIEN") || dc.ColumnName.StartsWith("PS_NO") || dc.ColumnName.StartsWith("PS_CO") || dc.ColumnName.StartsWith("PS_TANG") || dc.ColumnName.StartsWith("PS_GIAM") || dc.ColumnName.StartsWith("DU_DAU") || dc.ColumnName.StartsWith("DU_CUOI") || dc.ColumnName.StartsWith("DU_NO") || dc.ColumnName.StartsWith("DU_CO"))
                    {
                        if (dc.DataType == typeof(double) || dc.DataType == typeof(decimal))
                        {
                            //Gán cột dữ liệu về 0
                            foreach (DataRow dr in dtPrinVoucherDetail.Rows)
                            {
                                dr[dc] = 0;
                            }
                        }
                    }
                }
            }

            dtHeader = dtPrinVoucherHeader;
            dtDetail = dtPrinVoucherDetail;

            dtHeader.Columns.Add("REPORT_FILE", typeof(string));
            dtHeader.Columns.Add("TITLE", typeof(string));
            dtHeader.Columns.Add("IS_VND", typeof(bool));
            dtHeader.Columns.Add("DOC_TIEN", typeof(string));
            dtHeader.Columns.Add("DOC_TIEN1", typeof(string));
            dtHeader.Columns.Add("DOC_TIEN_TC", typeof(string));

            DataRow drHeader = dtHeader.Rows[0];

            drHeader["Is_Vnd"] = bIs_Vnd;
            drHeader["Title"]  = ((string)drDmCt["Title"]).ToUpper();
            if (bInVisibleNextPrint)
            {
                drHeader["Report_File"] = strReport_File_First;
            }
            else
            {
                drHeader["Report_File"] = strReport_File;
                strReport_File_First    = strReport_File;
                bInVisibleNextPrint     = bInVisibleNextPrint0;
            }

            if (Element.sysLanguage == enuLanguageType.Vietnamese)
            {
                dtHeader.Rows[0]["Doc_Tien"] = !bIs_Vnd?Common.ReadMoney(Convert.ToDouble(drHeader["TTien_Nt"]), strMa_Tte) : Common.ReadMoney(Convert.ToDouble(drHeader["TTien"]), Element.sysMa_Tte.ToString());

                if (drHeader.Table.Columns.Contains("TTien_Nt00"))
                {
                    dtHeader.Rows[0]["Doc_Tien_Tc"] = !bIs_Vnd?Common.ReadMoney(Convert.ToDouble(drHeader["TTien_Nt00"]), strMa_Tte) : Common.ReadMoney(Convert.ToDouble(drHeader["TTien_Nt00"]), Element.sysMa_Tte.ToString());

                    dtHeader.Rows[0]["Doc_Tien_Tc"] = "(" + dtHeader.Rows[0]["Doc_Tien_Tc"].ToString() + ")";
                }
                if (bIs_Doc_Tien1)
                {
                    dtHeader.Rows[0]["Doc_Tien1"] = "";
                }
                else
                {
                    dtHeader.Rows[0]["Doc_Tien1"] = !bIs_Vnd?Common.ReadMoney(Convert.ToDouble(drHeader["TTien_Nt"]), strMa_Tte) : Common.ReadMoney(Convert.ToDouble(drHeader["TTien"]), Element.sysMa_Tte.ToString());
                }
            }
            else
            {
                dtHeader.Rows[0]["Doc_Tien"] = !bIs_Vnd?Common.ReadMoneyE(Convert.ToDouble(drHeader["TTien_Nt"]), strMa_Tte) : Common.ReadMoneyE(Convert.ToDouble(drHeader["TTien"]), Element.sysMa_Tte.ToString());

                if (bIs_Doc_Tien1)
                {
                    dtHeader.Rows[0]["Doc_Tien1"] = "";
                }
                else
                {
                    dtHeader.Rows[0]["Doc_Tien1"] = !bIs_Vnd?Common.ReadMoneyE(Convert.ToDouble(drHeader["TTien_Nt"]), strMa_Tte) : Common.ReadMoneyE(Convert.ToDouble(drHeader["TTien"]), Element.sysMa_Tte.ToString());
                }
            }

            Epoint.Reports.frmReportPrint frmPrint = new Epoint.Reports.frmReportPrint();
            //frmPrint.MdiParent = Element.frmActiveMain;
            return(frmPrint.Load(dtHeader.Rows[0], dtDetail, bPreview, bShowDialog));
        }
Пример #5
0
        public virtual void Import_Excel()
        {
            //OpenFileDialog dialog = new OpenFileDialog
            //{
            //    DefaultExt = "xls",
            //    Filter = "*.xls|*.xls"
            //};
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter           = "xls files (*.xls;*.xlsx)|*.xls;*.xlsx";
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string strConnectString =
                    "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + dialog.FileName;



                OdbcCommand odbcComm = new OdbcCommand();

                using (OdbcConnection connection = new OdbcConnection(strConnectString))
                {
                    connection.Open();
                    string selectCommandText = "SELECT * FROM [Sheet1$] Where Ma_Ts IS NOT NULL AND Ten_Ts IS NOT NULL";
                    string strMsg            = (Element.sysLanguage == enuLanguageType.Vietnamese) ? "Bạn có muốn ghi đè dữ liệu đã tồn tại không ? " : "Do you want to override exists data?";
                    bool   flag = Common.MsgYes_No(strMsg);
                    using (OdbcDataAdapter adapter = new OdbcDataAdapter(selectCommandText, connection))
                    {
                        DataTable dataTable = new DataTable();
                        adapter.Fill(dataTable);
                        DataTable tableASTS = DataTool.SQLGetDataTable("ASTS", "TOP 0 * ", " 0 = 1", null);
                        DataRow   row       = tableASTS.NewRow();
                        tableASTS.Rows.Add(row);
                        DataTable tableTSNGIA = DataTool.SQLGetDataTable("ASTSNG", "TOP 0 * ", " 0 = 1", null);
                        DataRow   row2        = tableTSNGIA.NewRow();
                        tableTSNGIA.Rows.Add(row2);
                        Common.SetDefaultDataRow(ref row);
                        Common.SetDefaultDataRow(ref row2);
                        foreach (DataRow row3 in dataTable.Rows)
                        {
                            Common.CopyDataRow(row3, row);
                            row.AcceptChanges();
                            Common.CopyDataRow(row3, row2);
                            row2.AcceptChanges();
                            if (flag && DataTool.SQLCheckExist("ASTS", "Ma_Ts", (string)row3["Ma_Ts"]))
                            {
                                DataTool.SQLUpdate(enuEdit.Edit, "ASTS", ref row);
                                SQLExec.Execute("DELETE FROM ASTSNG WHERE Ma_Ts = '" + ((string)row3["Ma_Ts"]) + "'");
                                row2["Stt"] = Common.GetNewStt("06", true);
                                DataTool.SQLUpdate(enuEdit.New, "ASTSNG", ref row2);
                            }
                            else if (!DataTool.SQLCheckExist("ASTS", "Ma_Ts", (string)row3["Ma_Ts"]))
                            {
                                DataTool.SQLUpdate(enuEdit.New, "ASTS", ref row);
                                row2["Stt"] = Common.GetNewStt("06", true);
                                DataTool.SQLUpdate(enuEdit.New, "ASTSNG", ref row2);
                            }
                        }
                    }
                    base.GetType().InvokeMember("FillData", BindingFlags.InvokeMethod, null, this, null);
                }

                /*
                 * using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;\r\n\t\t\t\t\t\tData Source= " + dialog.FileName + ";Extended Properties=\"Excel 8.0;HDR=YES\""))
                 * {
                 *  connection.Open();
                 *  string selectCommandText = "SELECT * FROM [Sheet1$] Where Ma_Ts IS NOT NULL AND Ten_Ts IS NOT NULL";
                 *  string strMsg = (Element.sysLanguage == enuLanguageType.Vietnamese) ? "Bạn có muốn ghi đè dữ liệu đã tồn tại không ? " : "Do you want to override exists data?";
                 *  bool flag = Common.MsgYes_No(strMsg);
                 *  using (OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommandText, connection))
                 *  {
                 *      DataTable dataTable = new DataTable();
                 *      adapter.Fill(dataTable);
                 *      DataTable tableASTS = DataTool.SQLGetDataTable("ASTS", "TOP 0 * ", " 0 = 1", null);
                 *      DataRow row = tableASTS.NewRow();
                 *      tableASTS.Rows.Add(row);
                 *      DataTable tableTSNGIA = DataTool.SQLGetDataTable("ASTSNG", "TOP 0 * ", " 0 = 1", null);
                 *      DataRow row2 = tableTSNGIA.NewRow();
                 *      tableTSNGIA.Rows.Add(row2);
                 *      Common.SetDefaultDataRow(ref row);
                 *      Common.SetDefaultDataRow(ref row2);
                 *      foreach (DataRow row3 in dataTable.Rows)
                 *      {
                 *          Common.CopyDataRow(row3, row);
                 *          row.AcceptChanges();
                 *          Common.CopyDataRow(row3, row2);
                 *          row2.AcceptChanges();
                 *          if (flag && DataTool.SQLCheckExist("ASTS", "Ma_Ts", (string)row3["Ma_Ts"]))
                 *          {
                 *              DataTool.SQLUpdate(enuEdit.Edit, "ASTS", ref row);
                 *              SQLExec.Execute("DELETE FROM ASTSNG WHERE Ma_Ts = '" + ((string)row3["Ma_Ts"]) + "'");
                 *              row2["Stt"] = Common.GetNewStt("06", true);
                 *              DataTool.SQLUpdate(enuEdit.New, "ASTSNG", ref row2);
                 *          }
                 *          else if (!DataTool.SQLCheckExist("ASTS", "Ma_Ts", (string)row3["Ma_Ts"]))
                 *          {
                 *              DataTool.SQLUpdate(enuEdit.New, "ASTS", ref row);
                 *              row2["Stt"] = Common.GetNewStt("06", true);
                 *              DataTool.SQLUpdate(enuEdit.New, "ASTSNG", ref row2);
                 *          }
                 *      }
                 *  }
                 *  base.GetType().InvokeMember("FillData", BindingFlags.InvokeMethod, null, this, null);
                 * }
                 */

                Common.MsgOk(Languages.GetLanguage("End_Process"));
            }
        }
Пример #6
0
        public override void EpointRelease()
        {
            string strDBSource = Element.sysDatabaseName.ToString();
            string strDBDest   = Parameters.GetParaValue("DATABASE_DEST").ToString();

            DateTime dteNgay_Ct1   = Library.StrToDate(this.txtNgay_Ct1.Text);
            DateTime dteNgay_Ct2   = Library.StrToDate(this.txtNgay_Ct2.Text);
            string   strMa_Ct_List = txtMa_Ct.Text;

            if (!Common.CheckDataLocked(dteNgay_Ct1) || !Common.CheckDataLocked(dteNgay_Ct2))
            {
                EpointProcessBox.AddMessage("Dữ liệu đã khóa, liên hệ với nhà quản trị !");
                return;
            }

            try
            {
                //Common.ShowStatus(Languages.GetLanguage("In_Process"));

                Hashtable ht = new Hashtable();
                ht["DBSOURCE"] = strDBSource;
                ht["DBDEST"]   = strDBDest;
                ht["MA_DVCS"]  = Element.sysMa_DvCs.ToString();
                if (tabControl1.SelectedTab == tabPageTranVoucher)
                {
                    EpointProcessBox.AddMessage("Đang chuyển số liệu chứng từ ");
                    if (dtTranVoucher == null)
                    {
                        return;
                    }

                    foreach (DataRow dr in dtTranVoucher.Rows)
                    {
                        if ((bool)dr["CHON"])
                        {
                            ht["STT"]   = dr["Stt"].ToString();
                            ht["MA_CT"] = dr["Ma_Ct"].ToString();

                            SQLExec.Execute("sp_Tranfer_Voucher", ht, CommandType.StoredProcedure);
                        }
                    }
                }
                else if (tabControl1.SelectedTab == tabPageTranList)
                {
                    EpointProcessBox.AddMessage("Đang chuyển danh mục ");
                    foreach (DataRow dr in dtTranList.Rows)
                    {
                        if ((bool)dr["IS_SEND"])
                        {
                            EpointProcessBox.AddMessage("Đang chuyển dữ liệu " + dr["Description"].ToString());
                            ht["TABLE_NAME"] = dr["Table_Name"].ToString();
                            SQLExec.Execute("sp_Tranfer_DanhMuc", ht, CommandType.StoredProcedure);
                        }
                    }
                }
                else if (tabControl1.SelectedTab == tabPageKhac)
                {
                    DateTime dteNgay_Ct01 = Library.StrToDate(this.txtNgay_Ct01.Text);
                    DateTime dteNgay_Ct02 = Library.StrToDate(this.txtNgay_Ct02.Text);

                    ht["NGAY_CT1"] = dteNgay_Ct01;
                    ht["NGAY_CT2"] = dteNgay_Ct02;
                    //ht["NAM"] = Element.sysWorkingYear;

                    if (chkDuDau_KeToan.Checked)
                    {
                        EpointProcessBox.AddMessage("Đang chuyển số dư đầu tài khoản ");
                        SQLExec.Execute("sp_Tranfer_DuDau_KeToan", ht, CommandType.StoredProcedure);
                    }
                    if (chkDuDau_TonKho.Checked)
                    {
                        EpointProcessBox.AddMessage("Đang chuyển số dư đầu tồn kho ");
                        SQLExec.Execute("sp_Tranfer_DuDau_TonKho", ht, CommandType.StoredProcedure);
                    }
                    if (chkTaiSan.Checked)
                    {
                        EpointProcessBox.AddMessage("Đang chuyển chứng từ tài sản ");
                        SQLExec.Execute("sp_Tranfer_TaiSan", ht, CommandType.StoredProcedure);
                    }
                }

                Element.sysNgay_Ct1 = Library.StrToDate(this.txtNgay_Ct1.Text);
                Element.sysNgay_Ct2 = Library.StrToDate(this.txtNgay_Ct2.Text);
                EpointProcessBox.AddMessage(Languages.GetLanguage("End_Process"));
            }
            catch (Exception)
            {
                EpointProcessBox.AddMessage("Không tìm thấy Database cần chuyển đến !");
            }
        }
Пример #7
0
        public virtual void Import_Excel(bool CheckAPI)
        {
            //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 Is_Avail = true;

            if (true)
            {
                SqlCommand command = SQLExec.GetNewSQLConnection().CreateCommand();
                command.CommandText = "OM_Import_DiscountProg";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Ma_DvCs", Element.sysMa_DvCs);
                //command.Parameters.AddWithValue("@IsImport", false);
                SqlParameter parameter = new SqlParameter
                {
                    SqlDbType     = SqlDbType.Structured,
                    ParameterName = "@EditDisc",
                    TypeName      = "TVP_DiscoutList",
                    Value         = dtImport
                };
                command.Parameters.Add(parameter);
                try
                {
                    command.ExecuteNonQuery();
                }
                catch (Exception exception)
                {
                    Is_Avail            = false;
                    command.CommandText = "WHILE @@TRANCOUNT > 0 ROLLBACK TRANSACTION";
                    command.CommandType = CommandType.Text;
                    command.Parameters.Clear();
                    command.ExecuteNonQuery();
                    EpointProcessBox.AddMessage("Có lỗi xảy ra :" + exception.Message);
                }
            }
            //return;
            if (!Is_Avail)
            {
                return;
            }


            Hashtable htParaBreaby = new Hashtable();

            htParaBreaby["MA_DVCS"]      = Element.sysMa_DvCs;
            htParaBreaby["LOCALMACHINE"] = System.Environment.MachineName;
            htParaBreaby["ISOVERWRITE"]  = chkIsOverride.Checked;
            DataSet ds = SQLExec.ExecuteReturnDs("OM_Import_DiscountProg_CheckValid", htParaBreaby, CommandType.StoredProcedure);

            DataTable dtCtkm     = ds.Tables[0];
            DataTable dtMa_vt    = ds.Tables[1];
            DataTable dtMa_Vt_Km = ds.Tables[2];


            if (dtCtkm.Rows.Count > 0)
            {
                strError += "\n" + "Chương trình KM/CK đã tồn tại trong hệ thống : ";
                foreach (DataRow dr in dtCtkm.Rows)
                {
                    strError += dr["Ma_CTKM"].ToString() + ",";
                }
            }
            if (dtMa_vt.Rows.Count > 0)
            {
                strError += "\n" + "Mã hàng bán không tồn tại : ";
                foreach (DataRow dr in dtMa_vt.Rows)
                {
                    strError += dr["Ma_Vt"].ToString() + ",";
                }
            }
            if (dtMa_Vt_Km.Rows.Count > 0)
            {
                strError += "\n" + "Mã hàng khuyến mãi không tồn tại : ";
                foreach (DataRow dr in dtMa_Vt_Km.Rows)
                {
                    strError += dr["Ma_Vt"].ToString() + ",";
                }
            }

            if (strError != string.Empty)
            {
                EpointProcessBox.AddMessage(strError);
            }
            else
            {
                Hashtable htPara = new Hashtable();
                htPara["MA_DVCS"]      = Element.sysMa_DvCs;
                htPara["LOCALMACHINE"] = System.Environment.MachineName;
                htPara["ISOVERWRITE"]  = chkIsOverride.Checked;
                if (SQLExec.Execute("OM_Import_DiscountProg_Valid", htPara, CommandType.StoredProcedure))
                {
                    EpointProcessBox.AddMessage("Import thành công!");
                }
                else
                {
                    EpointProcessBox.AddMessage("Import thất bại!");
                }
            }

            EpointProcessBox.AddMessage("Kết thúc");
        }
Пример #8
0
        protected override void OnClosed(EventArgs e)
        {
            //if (MessageBox.Show(Element.sysLanguage == enuLanguageType.Vietnamese ? "Bạn có muốn backup dữ liệu không?" : "Would you like to backup database?", "Message",
            //            MessageBoxButtons.YesNoCancel,
            //            MessageBoxIcon.Question,
            //            MessageBoxDefaultButton.Button2) == DialogResult.Cancel)


            //Backup dữ liệu
            string strSQLExec;

            if (!Collection.Parameters.ContainsKey("LASTBACKUP_DATE"))
            {
                strSQLExec = "INSERT INTO SYSPARAMETER (Parameter_ID, Parameter_Value, Parameter_Type, Visible, Parameter_Desc, Module_ID) " +
                             " VALUES (@Parameter_ID, @Parameter_Value, @Parameter_Type, @Visible, @Parameter_Desc, @Module_ID)";

                Hashtable htPara = new Hashtable();
                htPara.Add("PARAMETER_ID", "LASTBACKUP_DATE");
                htPara.Add("PARAMETER_VALUE", "1/1/1900");
                htPara.Add("PARAMETER_TYPE", "D");
                htPara.Add("VISIBLE", "0");
                htPara.Add("PARAMETER_DESC", "Ngày backup cuối cùng");
                htPara.Add("MODULE_ID", 7001);

                if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                {
                    Collection.Parameters.Add("LASTBACKUP_DATE", "1/1/1900");
                }
            }

            if (!Collection.Parameters.ContainsKey("BACKUP_PERIOD"))
            {
                strSQLExec = "INSERT INTO SYSPARAMETER (Parameter_ID, Parameter_Value, Parameter_Type, Visible, Parameter_Desc, Module_ID) " +
                             " VALUES (@Parameter_ID, @Parameter_Value, @Parameter_Type, @Visible, @Parameter_Desc, @Module_ID)";

                Hashtable htPara = new Hashtable();
                htPara.Add("PARAMETER_ID", "BACKUP_PERIOD");
                htPara.Add("PARAMETER_VALUE", 7);
                htPara.Add("PARAMETER_TYPE", "N");
                htPara.Add("VISIBLE", "1");
                htPara.Add("PARAMETER_DESC", "Kỳ hạn backup");
                htPara.Add("MODULE_ID", 7001);

                if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                {
                    Collection.Parameters.Add("BACKUP_PERIOD", "7");
                }
            }

            if (Collection.Parameters.ContainsKey("LASTBACKUP_DATE") && Collection.Parameters.ContainsKey("BACKUP_PERIOD"))
            {
                object objLastBackupDate = DataTool.SQLGetNameByCode("SYSPARAMETER", "Parameter_ID", "Parameter_Value", "LASTBACKUP_DATE");
                object objBackupPeriod   = DataTool.SQLGetNameByCode("SYSPARAMETER", "Parameter_ID", "Parameter_Value", "BACKUP_PERIOD");

                DateTime dLastBackupDate;
                if (!DateTime.TryParse((string)objLastBackupDate, out dLastBackupDate))
                {
                    dLastBackupDate = Convert.ToDateTime("1/1/1900");
                }

                int iBackupPeriod;
                if (!int.TryParse((string)objBackupPeriod, out iBackupPeriod))
                {
                    iBackupPeriod = 7;
                }

                if (iBackupPeriod > 0 && DateTime.Now.Subtract(dLastBackupDate).TotalDays >= iBackupPeriod)
                {
                    if (EpointMethod.BackupDatabase())
                    {
                        EpointMethod.DeleteBackup();
                        SQLExec.Execute("UPDATE SYSPARAMETER SET Parameter_Value = '" + Library.DateToStr(DateTime.Now) + "' WHERE Parameter_ID = 'LASTBACKUP_DATE'");
                    }
                }
            }



            base.OnClosed(e);
        }
Пример #9
0
        private bool Save()
        {
            Common.GatherMemvar(this, ref this.drEdit);

            if (!this.FormCheckValid())
            {
                return(false);
            }

            if (enuNew_Edit == enuEdit.New)
            {
                drEdit["Locked"] = false;
            }

            System.Collections.Hashtable ht = new System.Collections.Hashtable();
            ht.Add("MEMBER_ID", drEdit["Member_ID"]);
            ht.Add("MEMBER_NAME", drEdit["Member_Name"]);
            ht.Add("MEMBER_TYPE", drEdit["Member_Type"]);
            ht.Add("IS_ADMIN", drEdit["Is_Admin"]);
            ht.Add("LOCKED", drEdit["Locked"]);
            ht.Add("MEMBER_ID_ALLOW", drEdit["Member_ID_Allow"]);
            ht.Add("MEMBER_ACCESS", drEdit["Member_Access"]);
            ht.Add("PASSWORD", ((string)drEdit["Password"]).Trim());

            string strSQLExec = string.Empty;

            if (enuNew_Edit == enuEdit.New)
            {
                strSQLExec =
                    "INSERT INTO SYSMEMBER (Member_ID, Member_Name, Member_Type, Is_Admin, Locked, Member_ID_Allow, Member_Access, CheckPass) " +
                    "	VALUES (@Member_ID, @Member_Name, @Member_Type, @Is_Admin, @Locked, @Member_ID_Allow, @Member_Access, dbo.fn_Encrypt(@Password))";
            }
            else
            {
                strSQLExec =
                    "UPDATE SYSMEMBER SET " +
                    "		Member_ID = @Member_ID, Member_Name = @Member_Name, Member_Type = @Member_Type, Is_Admin = @Is_Admin, "+
                    "		Locked = @Locked, Member_ID_Allow = @Member_ID_Allow, Member_Access = @Member_Access "+
                    "	WHERE Member_ID = '"+ (string)drEdit["Member_ID", DataRowVersion.Original] + "'";
            }

            if (!SQLExec.Execute(strSQLExec, ht, CommandType.Text))
            {
                return(false);
            }

            //Thêm cột Ma_CbNv phục vụ cho CRM
            if (drEdit.Table.Columns.Contains("Ma_CbNv"))
            {
                strSQLExec = "UPDATE SYSMEMBER SET Ma_CbNv = '" + (string)drEdit["Ma_CbNv"] + "' WHERE Member_ID = '" + (string)drEdit["Member_ID"] + "'";

                SQLExec.Execute(strSQLExec);
            }

            //Thêm cột Ma_Bp
            if (drEdit.Table.Columns.Contains("Ma_Bp"))
            {
                strSQLExec = "UPDATE SYSMEMBER SET Ma_Bp = '" + (string)drEdit["Ma_Bp"] + "' WHERE Member_ID = '" + (string)drEdit["Member_ID"] + "'";

                SQLExec.Execute(strSQLExec);
            }

            //Thêm cột Ma_DvCs_Default phục vụ cho nhiều XN trực thuộc
            if (drEdit.Table.Columns.Contains("Ma_DvCs_Default"))
            {
                strSQLExec = "UPDATE SYSMEMBER SET Ma_DvCs_Default = '" + (string)drEdit["Ma_DvCs_Default"] + "' WHERE Member_ID = '" + (string)drEdit["Member_ID"] + "'";

                SQLExec.Execute(strSQLExec);
            }
            //Thêm cột Language_Default
            if (drEdit.Table.Columns.Contains("Language_Default"))
            {
                strSQLExec = "UPDATE SYSMEMBER SET Language_Default = '" + (string)drEdit["Language_Default"] + "' WHERE Member_ID = '" + (string)drEdit["Member_ID"] + "'";

                SQLExec.Execute(strSQLExec);
            }
            //Doi ma
            if (this.enuNew_Edit == enuEdit.Edit)
            {
                DataTool.SQLChangeID("MEMBER_ID", drEdit);
            }

            return(true);
        }
Пример #10
0
        private void KetChuyenPb()
        {
            dgvKetChuyenPb.EndEdit();
            bdsKetChuyenPb.EndEdit();

            if (Common.GetPartitionCurrent() != 0 && Common.GetPartitionCurrent() != Element.sysWorkingYear)
            {
                Common.MsgCancel("Phải chuyển về phân vùng dữ liệu " + Element.sysWorkingYear.ToString() + "!");
                return;
            }

            frmKetChuyen_Run frm = new frmKetChuyen_Run();

            frm.Tag = "Ket_Chuyen";

            frm.numThang1.Value = this.numThang1.Value;
            frm.numThang2.Value = this.numThang2.Value;

            frm.Load();

            if (!frm.isAccept)
            {
                return;
            }

            DateTime dteNgay_Ct1 = Library.StrToDate("01/" + frm.numThang1.Value + "/" + Element.sysWorkingYear);
            DateTime dteNgay_Ct2 = Library.StrToDate("01/" + frm.numThang2.Value + "/" + Element.sysWorkingYear);

            dteNgay_Ct2 = dteNgay_Ct2.AddMonths(1).AddDays(-1);

            if (!Common.CheckDataLocked(dteNgay_Ct1))
            {
                Common.MsgCancel("Dữ liệu đã khóa, liên hệ với nhà quản trị!");
                return;
            }

            foreach (DataRow dr in dtKetChuyenPb.Rows)
            {
                if ((bool)dr["SELECT"] == false)
                {
                    continue;
                }

                Hashtable ht = new Hashtable();
                ht["NGAY_CT1"]   = dteNgay_Ct1;
                ht["NGAY_CT2"]   = dteNgay_Ct2;
                ht["STT"]        = dr["Stt"];
                ht["TK"]         = dr["Tk"];
                ht["TK_DU_DEN"]  = dr["Tk_Du_Den"];
                ht["DIEN_GIAI"]  = dr["Dien_Giai"];
                ht["NO_CO_AUTO"] = dr["No_Co_Auto"];
                ht["PS_DU"]      = dr["Ps_Du"];
                ht["LOAI_KC"]    = dr["Loai_Kc"];
                ht["MA_CT"]      = "TD";
                ht["MA_DVCS"]    = Element.sysMa_DvCs;

                Common.ShowStatus(Languages.GetLanguage("In_Process") + (string)dr["Dien_Giai"]);

                //SQLExec.Execute("Sp_KetChuyen_Delete", ht, CommandType.StoredProcedure);

                if ((string)dr["Loai_Kc"] == "1")
                {
                    SQLExec.Execute("Sp_KetChuyenPb1", ht, CommandType.StoredProcedure);
                }
                else if ((string)dr["Loai_Kc"] == "2")
                {
                    SQLExec.Execute("Sp_KetChuyenPb2", ht, CommandType.StoredProcedure);
                }

                dr["Select"] = false;
            }

            Common.EndShowStatus();
            Common.MsgOk(Languages.GetLanguage("End_Process"));
        }
Пример #11
0
        public override void EpointRelease()
        {
            if (ReleaseType == "S")
            {
                string strMsgLog = string.Empty;
                try
                {
                    if (!Directory.Exists(FilePathZalo))
                    {
                        Directory.CreateDirectory(FilePathZalo);
                    }
                    object objImage;
                    string strMsg = string.Empty;
                    string AttachmentId = string.Empty;
                    string ZaloLink, File_Name, Description;
                    string FileImg;
                    //string FilePathZalo
                    //string strMa_Cbnv, strTen_Cbnv, strEmail, strMa_Kv, strMa_Loai2, strSubject;
                    EpointProcessBox.AddMessage("Lấy dữ liệu tin nhắn");

                    DataTable dtMsg = SQLExec.ExecuteReturnDt(" EXEC TUANVIET_OFFICIAL.dbo.Z_GetMessage_ToZalo " + MsgIDCur.ToString());

                    if (dtMsg == null || dtMsg.Rows.Count == 0)
                    {
                        EpointProcessBox.AddMessage("không lấy được dữ liệu tin nhắn");
                        return;
                    }
                    EpointProcessBox.AddMessage("Bắt đầu gửi tin nhắn");
                    //foreach (DataRow drmsg in dtMsg.Rows)
                    //{

                    DataRow drmsg = dtMsg.Rows[0];
                    //int MsgID = Convert.ToInt32(drmsg["Ident00"]);
                    ZaloLink    = drmsg["ZaloLink"].ToString();
                    objImage    = drmsg["File_Content"];
                    File_Name   = drmsg["File_Name"].ToString();
                    Description = drmsg["Description"].ToString();

                    FileImg = FilePathZalo + @"\" + (drmsg["File_Tag"].ToString() == string.Empty ? String.Empty : drmsg["File_ID"].ToString() + "." + drmsg["File_Tag"].ToString());

                    //Common.WriteToFileZaloLog("Start Send Message ToZalo : " + FileImg);
                    if (SaveZaloResource.LoadResourceImage(FileImg, objImage))
                    {
                        ZaloFile Zfile = new ZaloFile(FileImg);
                        Zfile.setMediaTypeHeader("Image/PNG");
                        JObject updatefile = client.uploadImageForOfficialAccountAPI(Zfile);
                        dynamic dynObjFile = JsonConvert.DeserializeObject(updatefile.ToString());
                        AttachmentId = dynObjFile.data.attachment_id;
                    }

                    //Get list employee in branch
                    //string strSQLEm = "Z_GetEmployee_ByTag " + drmsg["Ident00"] + "";

                    strMsg = File_Name + "\n" + Description + "\n" + ZaloLink;
                    if (true)
                    {
                        DataTable dtEmployee_Br = SQLExec.ExecuteReturnDt("EXEC Z_GetEmployee_ByTag " + MsgIDCur.ToString());
                        if (dtEmployee_Br == null || dtEmployee_Br.Rows.Count == 0)
                        {
                            return;
                        }

                        foreach (DataRow drR in dtEmployee_Br.Rows)
                        {
                            JObject jSendbr = client.sendImageMessageToUserIdByAttachmentId(drR["Zalo_ID"].ToString(), strMsg, AttachmentId);
                        }
                    }
                    else
                    {
                        JObject jSend_hungnv = client.sendImageMessageToUserIdByAttachmentId("5643947530772678208", strMsg, AttachmentId);
                    }
                    SQLExec.Execute("EXEC TUANVIET_OFFICIAL.dbo.Z_UpdateMessageZaloAfterSend " + MsgIDCur.ToString());
                    EpointProcessBox.AddMessage("Kết thúc");
                }
                catch (Exception ex)
                {
                    EpointProcessBox.AddMessage("Fail Send Message to Zalo : " + strMsgLog + "-------------\n" + ex.ToString());
                }
            }
            else if (ReleaseType == "G")
            {
                EpointProcessBox.AddMessage("Đang cập nhật thông tin người theo dõi!...................");
                UpdateFollower();
                ReleaseType = string.Empty;
                EpointProcessBox.AddMessage("....................Kết thúc...................");
            }
        }
Пример #12
0
        private bool Save()
        {
            //frmPmTb frmPmTb = new frmPmTb();
            //frmPmTb

            string    strSQLExec = string.Empty;
            Hashtable htPara;

            //drCurrent = ((DataRowView)bdsPmTb.Current).Row;

            //Lưu phần Checked
            if (chkDuyet.Enabled)
            {
                if (strColumnName == "DUYET" && strTableName == "HRKHCV")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET", chkDuyet.Checked);
                    htPara.Add("DUYET_LOG", txtDuyet_Log.Text);
                    htPara.Add("IDENT00", drEdit["Ident00"]);

                    strSQLExec = @"UPDATE HRKHCV SET Duyet = @Duyet, Duyet_Log = @Duyet_Log WHERE Ident00 = @Ident00";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet"]     = chkDuyet.Checked;
                        drEdit["Duyet_Log"] = txtDuyet_Log.Text;
                    }
                }
                else if (strColumnName == "DUYET" && strTableName == "L14TDCV")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET", chkDuyet.Checked);
                    htPara.Add("DUYET_LOG", txtDuyet_Log.Text);
                    htPara.Add("IDENT00", drEdit["Ident00"]);

                    strSQLExec = @"UPDATE L14TDCV SET Duyet = @Duyet, Duyet_Log = @Duyet_Log WHERE Ident00 = @Ident00";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet"]     = chkDuyet.Checked;
                        drEdit["Duyet_Log"] = txtDuyet_Log.Text;
                    }
                }
                else if (strColumnName == "DUYET_GD" && strTableName == "L14PMTB")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET_GD", chkDuyet.Checked);
                    htPara.Add("DUYET_GD_LOG", txtDuyet_Log.Text);
                    htPara.Add("IDENT00", drEdit["Ident00"]);

                    strSQLExec = @"UPDATE L14PMTB SET Duyet_GD = @Duyet_GD, Duyet_GD_Log = @Duyet_GD_Log WHERE Ident00 = @Ident00";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet_GD"]     = chkDuyet.Checked;
                        drEdit["Duyet_GD_Log"] = txtDuyet_Log.Text;
                    }
                }
                else if (strColumnName == "DUYET_HCNS" && strTableName == "L14PMTB")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET_HCNS", chkDuyet.Checked);
                    htPara.Add("DUYET_HCNS_LOG", txtDuyet_Log.Text);
                    htPara.Add("IDENT00", drEdit["Ident00"]);

                    strSQLExec = @"UPDATE L14PMTB SET Duyet_HCNS = @Duyet_HCNS, Duyet_HCNS_Log = @Duyet_HCNS_Log WHERE Ident00 = @Ident00";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet_HCNS"]     = chkDuyet.Checked;
                        drEdit["Duyet_HCNS_Log"] = txtDuyet_Log.Text;
                    }
                }
                else if (strColumnName == "DUYET_NHAN" && strTableName == "L14PMTB")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET_NHAN", chkDuyet.Checked);
                    htPara.Add("DUYET_NHAN_LOG", txtDuyet_Log.Text);
                    htPara.Add("IDENT00", drEdit["Ident00"]);

                    strSQLExec = @"UPDATE L14PMTB SET Duyet_Nhan = @Duyet_Nhan, Duyet_Nhan_Log = @Duyet_Nhan_Log WHERE Ident00 = @Ident00";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet_Nhan"]     = chkDuyet.Checked;
                        drEdit["Duyet_Nhan_Log"] = txtDuyet_Log.Text;
                    }
                }
                else if (strColumnName == "DUYET_TRA" && strTableName == "L14PMTB")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET_TRA", chkDuyet.Checked);
                    htPara.Add("DUYET_TRA_LOG", txtDuyet_Log.Text);
                    htPara.Add("IDENT00", drEdit["Ident00"]);

                    strSQLExec = @"UPDATE L14PMTB SET Duyet_Tra = @Duyet_Tra, Duyet_Tra_Log = @Duyet_Tra_Log WHERE Ident00 = @Ident00";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet_Tra"]     = chkDuyet.Checked;
                        drEdit["Duyet_Tra_Log"] = txtDuyet_Log.Text;
                    }
                }
                else if (strColumnName == "DUYET_GD" && strTableName == "L14NGHIPHEP")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET_GD", chkDuyet.Checked);
                    htPara.Add("DUYET_GD_LOG", txtDuyet_Log.Text);
                    htPara.Add("IDENT00", drEdit["Ident00"]);

                    strSQLExec = @"UPDATE L14NGHIPHEP SET Duyet_GD = @Duyet_GD, Duyet_GD_Log = @Duyet_GD_Log WHERE Ident00 = @Ident00";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet_GD"]     = chkDuyet.Checked;
                        drEdit["Duyet_GD_Log"] = txtDuyet_Log.Text;
                    }
                }
                else if (strColumnName == "DUYET_NQL" && strTableName == "L14NGHIPHEP")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET_NQL", chkDuyet.Checked);
                    htPara.Add("DUYET_NQL_LOG", txtDuyet_Log.Text);
                    htPara.Add("IDENT00", drEdit["Ident00"]);

                    strSQLExec = @"UPDATE L14NGHIPHEP SET Duyet_NQL = @Duyet_NQL, Duyet_NQL_Log = @Duyet_NQL_Log WHERE Ident00 = @Ident00";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet_NQL"]     = chkDuyet.Checked;
                        drEdit["Duyet_NQL_Log"] = txtDuyet_Log.Text;
                    }
                }
                else if (strColumnName == "DUYET_GD" && strTableName == "L14PMVPP")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET_GD", chkDuyet.Checked);
                    htPara.Add("DUYET_GD_LOG", txtDuyet_Log.Text);
                    htPara.Add("STT", drEdit["Stt"]);

                    strSQLExec = @"UPDATE L14PMVPP SET Duyet_GD = @Duyet_GD, Duyet_GD_Log = @Duyet_GD_Log WHERE Stt = @Stt";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet_GD"]     = chkDuyet.Checked;
                        drEdit["Duyet_GD_Log"] = txtDuyet_Log.Text;
                    }
                }
                else if (strColumnName == "DUYET_HCNS" && strTableName == "L14PMVPP")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET_HCNS", chkDuyet.Checked);
                    htPara.Add("DUYET_HCNS_LOG", txtDuyet_Log.Text);
                    htPara.Add("STT", drEdit["Stt"]);

                    strSQLExec = @"UPDATE L14PMVPP SET Duyet_HCNS = @Duyet_HCNS, Duyet_HCNS_Log = @Duyet_HCNS_Log WHERE Stt = @Stt";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet_HCNS"]     = chkDuyet.Checked;
                        drEdit["Duyet_HCNS_Log"] = txtDuyet_Log.Text;
                    }
                }
                else if (strColumnName == "DUYET" && strTableName == "L14LTDX")
                {
                    htPara = new Hashtable();
                    htPara.Add("DUYET", chkDuyet.Checked);
                    htPara.Add("DUYET_LOG", txtDuyet_Log.Text);
                    htPara.Add("IDENT00", drEdit["Ident00"]);

                    strSQLExec = @"UPDATE L14LTDX SET Duyet = @Duyet, Duyet_Log = @Duyet_Log WHERE Ident00 = @Ident00";

                    if (SQLExec.Execute(strSQLExec, htPara, CommandType.Text))
                    {
                        drEdit["Duyet"]     = chkDuyet.Checked;
                        drEdit["Duyet_Log"] = txtDuyet_Log.Text;
                    }
                }
            }
            return(true);
        }
Пример #13
0
        private string Tao_Pt()
        {
            int    Stt0          = 0;
            string strSo_Ct      = string.Empty;
            string strSo_Ct_New  = string.Empty;
            string strCreate_Log = string.Empty;
            string strQueryCthd  = string.Empty;
            string iStt          = string.Empty;

            try
            {
                #region GetNew_SoCt


                DataRow  drDmct        = DataTool.SQLGetDataRowByID("SYSDMCT", "Ma_Ct", "PT");
                DataRow  dr            = SQLExec.ExecuteReturnDt("SELECT Ma_DvCs FROM SYSDMDVCS WHERE Ma_DvCs = '" + Element.sysMa_DvCs + "' ").Rows[0];
                DateTime dteNgay_Ct_tt = Library.StrToDate(dteNgay_Ct_TT.Text);
                string   strSQLExec    = "SELECT So_Ct FROM GLVOUCHER WHERE Ma_DvCs = '" + Element.sysMa_DvCs
                                         + "' AND Ma_Ct = 'PT' AND MONTH(Ngay_Ct) =" + dteNgay_Ct_tt.Month.ToString()
                                         + " AND YEAR(Ngay_Ct) =" + dteNgay_Ct_tt.Year.ToString() + " AND So_Ct <> '' ";
                //+ " AND DAY(Ngay_Ct) =" + dteNgay_Ct1.Day.ToString()

                DataTable dt = SQLExec.ExecuteReturnDt(strSQLExec);
                if (dt.Rows.Count > 0)
                {
                    string strSQL = "SELECT ISNULL(MAX(So_Ct),'') FROM GLVOUCHER WHERE Ma_DvCs = '" + Element.sysMa_DvCs + "' AND Ma_Ct = 'PT' AND MONTH(Ngay_Ct) =" + dteNgay_Ct_tt.Month.ToString() + " AND YEAR(Ngay_Ct) =" + dteNgay_Ct_tt.Year.ToString() + "";
                    strSo_Ct = SQLExec.ExecuteReturnValue(strSQL).ToString();
                    Hashtable htPara = new Hashtable();
                    htPara.Add("TABLENAME", "GLVOUCHER");
                    htPara.Add("COLUMNNAME", "So_Ct");
                    htPara.Add("CURRENTID", strSo_Ct);
                    htPara.Add("KEY", "Ma_DvCs = '" + Element.sysMa_DvCs + "' AND Ma_Ct = 'PT' AND MONTH(Ngay_Ct) = " + dteNgay_Ct_tt.Month + " AND YEAR(Ngay_Ct) = " + dteNgay_Ct_tt.Year + "");
                    htPara.Add("PREFIXLEN", Convert.ToInt32(drDmct["PrefixLen"]));
                    htPara.Add("SUFFIXLEN", Convert.ToInt32(drDmct["SubfixLen"]));

                    strSo_Ct_New = (string)SQLExec.ExecuteReturnValue("sp_GetNewID", htPara, CommandType.StoredProcedure);
                    //strSo_Ct_New = drDmct["Prefix"].ToString() + dteNgay_Ct_tt.Month.ToString("00") + dteNgay_Ct_tt.Day.ToString("00") + strSo_Ct_New.Substring(strSo_Ct_New.Length - 4, 4);
                }
                else
                {
                    strSo_Ct_New = drDmct["Prefix"].ToString() + dteNgay_Ct_tt.Month.ToString("00") + dteNgay_Ct_tt.Day.ToString("00") + "0001";
                }


                #endregion

                strCreate_Log = Common.GetCurrent_Log();



                bool bSttValid = false;

                while (!bSttValid)
                {
                    iStt = Common.GetNewStt("01", true);
                    string    strPH  = @"SELECT * FROM GLVOUCHER WHERE Stt= '" + iStt + "'";
                    DataTable dtCtph = SQLExec.ExecuteReturnDt(strPH);
                    if (dtCtph.Rows.Count > 0)
                    {
                        bSttValid = false;
                    }
                    else
                    {
                        bSttValid = true;
                    }
                }

                double dbTien0 = Convert.ToDouble(numTTien_Tt.Value);
                double dbTien3 = 0;
                //double dbTTien = dbTien0 + dbTien3;
                double dbThue     = 0;
                string strQueryPh = @"
                                    INSERT INTO	GLVOUCHER (Stt, Ma_Ct, Ngay_Ct, So_Ct, Ma_Dt, Dien_giai, TTien0, TTien_Nt0, TTien3, TTien_Nt3, Create_Log, Ct_Di_Kem,Is_ThanhToan, Ma_Dvcs)
                                        VALUES('"                         + iStt + "', 'PT', '" + Library.DateToStr(dteNgay_Ct_tt) + "', '" + strSo_Ct_New + "', '"
                                    + txtMa_Dt.Text + "', N'" + txtDien_Giai.Text + "', " + dbTien0 + ", " + dbTien0 + ", " + dbTien3 + ", " + dbTien3 + ", '"
                                    + strCreate_Log + "', '',1, '" + Element.sysMa_DvCs + "')";



                foreach (DataRow drhd in dtCtHanTt.Rows)
                {
                    if ((bool)drhd["Thanh_Toan"])
                    {
                        Stt0 += 1;
                        DataRow drDt = DataTool.SQLGetDataRowByID("LIDOITUONG", "Ma_Dt", drhd["Ma_Dt"].ToString());

                        strQueryCthd += @"INSERT INTO	CATIEN (Stt, Stt0, Ma_Ct, Ngay_Ct, So_Ct, Dien_Giai, Ong_Ba, Ma_Dt,Dia_Chi,
                                                                    Tk_No, Tk_Co, Tien_Nt9, Tien, Tien_Nt, 
                                                                    Ma_Thue, Thue_GtGt, Tien3, Tien_Nt3, Tk_No3, Tk_Co3, Ngay_Ct0, So_Ct0, So_Seri0, Ma_So_Thue, Ten_DtGtGt,
                                                                    Ma_Dvcs, Ma_Tte, Ty_Gia)
                                                    VALUES('"                             + iStt + "', '" + Stt0 + "', 'PT', '" + dteNgay_Ct_TT.Text + "','" + strSo_Ct_New + "', N'"
                                        + txtDien_Giai.Text + "',  N'" + drDt["Ong_Ba"] + "', '" + drhd["Ma_Dt"] + "',N'" + drDt["Dia_Chi"] + "','"
                                        + txtTk_Tt.Text + "','" + drhd["Tk"] + "', " + drhd["Tien_Tt1"] + ",  " + drhd["Tien_Tt1"] + ",  " + drhd["Tien_Tt1"]
                                        + ", '', 0, 0, 0, '', '', '', '', '', '', N'', '" + Element.sysMa_DvCs + "','VND', 1)\n";
                    }
                }
                if (numTTien_Tt.Value > 0)
                {
                    SQLExec.Execute(strQueryPh);
                    SQLExec.Execute(strQueryCthd);

                    Common.MsgOk("Chứng từ đã tạo xong Số chứng từ : " + strSo_Ct_New);
                    this.strStt_Pt    = iStt;
                    this.strSo_Ct_New = strSo_Ct_New;
                    return(iStt);
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                Common.MsgOk(ex.ToString());
                return(string.Empty);
                // throw;
            }
        }